Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
*.egg-info
*.pyc
*.bak
.*.sw?
build
docs/build
Expand Down
1 change: 1 addition & 0 deletions baph/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from __future__ import absolute_import
def setup():
from baph.apps import apps
from baph.conf import settings
Expand Down
1 change: 1 addition & 0 deletions baph/apps/config.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from __future__ import absolute_import
import os
from importlib import import_module

Expand Down
10 changes: 8 additions & 2 deletions baph/apps/registry.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,13 @@
from __future__ import absolute_import
import threading
from collections import Counter, OrderedDict, defaultdict

from functools32 import lru_cache
from six import PY2

if PY2:
from functools32 import lru_cache
else:
from functools import lru_cache

from .config import AppConfig

Expand Down Expand Up @@ -80,7 +86,7 @@ def get_app_configs(self):
Imports applications and returns an iterable of app configs.
"""
self.check_apps_ready()
return self.app_configs.values()
return list(self.app_configs.values())

@lru_cache(maxsize=None)
def get_models(self, include_auto_created=False,
Expand Down
1 change: 1 addition & 0 deletions baph/auth/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from __future__ import absolute_import
from datetime import datetime

from django.conf import settings
Expand Down
1 change: 1 addition & 0 deletions baph/auth/apps.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from __future__ import absolute_import
from baph.apps import AppConfig


Expand Down
1 change: 1 addition & 0 deletions baph/auth/backends.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from __future__ import absolute_import
import django.core.validators

from baph.auth.models import User, Organization
Expand Down
8 changes: 5 additions & 3 deletions baph/auth/decorators.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
# -*- coding: utf-8 -*-
from __future__ import absolute_import
import decorator
import logging
import time

from django.contrib.auth import REDIRECT_FIELD_NAME
from django.contrib.auth.decorators import user_passes_test
from django.http import HttpResponseRedirect
from six.moves import zip


def check_perm(resource, action, simple=True, extra_keys={}, filters={}):
Expand All @@ -23,8 +25,8 @@ def check_perm(resource, action, simple=True, extra_keys={}, filters={}):
def check_perm_closure(f, request, *args, **kwargs):

if not kwargs:
keys = f.func_code.co_varnames[1:] #item 0 is 'request'
kwargs = dict(zip(keys,args))
keys = f.__code__.co_varnames[1:] #item 0 is 'request'
kwargs = dict(list(zip(keys,args)))
args = []

for url_key, db_key in extra_keys.items():
Expand Down Expand Up @@ -68,6 +70,6 @@ def wrapper(*arg):
t1 = time.time()
res = func(*arg)
t2 = time.time()
logging.debug('%s took %0.3f ms' % (func.func_name, (t2-t1)*1000.0))
logging.debug('%s took %0.3f ms' % (func.__name__, (t2-t1)*1000.0))
return res
return wrapper
1 change: 1 addition & 0 deletions baph/auth/forms.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# -*- coding: utf-8 -*-

#from baph.sites.models import get_current_site
from __future__ import absolute_import
from coffin.shortcuts import render_to_string
from django import forms
from django.contrib.auth.forms import SetPasswordForm as BaseSetPasswordForm
Expand Down
13 changes: 9 additions & 4 deletions baph/auth/management/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
from __future__ import unicode_literals
from __future__ import absolute_import
from __future__ import print_function
import getpass
import locale
import unicodedata
Expand Down Expand Up @@ -84,14 +86,17 @@ def _get_all_permissions(opts):

def create_permissions(app, created_models, verbosity, db=DEFAULT_DB_ALIAS,
**kwargs):
pkg, _ = app.__name__.rsplit('.', 1)
app_models = []
for k, v in vars(app).items():
if k not in orm.Base._decl_class_registry:
continue
if v not in orm.Base._decl_class_registry.values():
if v not in list(orm.Base._decl_class_registry.values()):
continue
if hasattr(app, '__package__') and app.__package__ + '.models' != v.__module__:
if pkg + '.models' != v.__module__:
continue
#if hasattr(app, '__package__') and app.__package__ + '.models' != v.__module__:
# continue
app_models.append( (k,v) )
if not app_models:
return
Expand Down Expand Up @@ -143,8 +148,8 @@ def create_permissions(app, created_models, verbosity, db=DEFAULT_DB_ALIAS,

if verbosity >= 2:
for perm in perms:
print("Adding permission '%s:%s'" % (perm['resource'],
perm['codename']))
print(("Adding permission '%s:%s'" % (perm['resource'],
perm['codename'])))

'''
def create_superuser(app, created_models, verbosity, db, **kwargs):
Expand Down
1 change: 1 addition & 0 deletions baph/auth/management/commands/createpermissions.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from __future__ import absolute_import
import sys
import os
from optparse import make_option
Expand Down
1 change: 1 addition & 0 deletions baph/auth/middleware.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from __future__ import absolute_import
from django.utils.functional import SimpleLazyObject

from . import get_user as _get_user
Expand Down
7 changes: 5 additions & 2 deletions baph/auth/mixins.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from __future__ import absolute_import
import json
import logging

Expand All @@ -10,13 +11,15 @@
from baph.db import ORM
from baph.db.models.loading import cache
from baph.db.models.utils import class_resolver, column_to_attr, key_to_value
import six
from six.moves import zip


logger = logging.getLogger('authorization')

def convert_filter(k, cls=None):
"""Convert a string filter into a column-based filter"""
if not isinstance(k, basestring):
if not isinstance(k, six.string_types):
raise Exception('convert_filters keys must be strings')
frags = k.split('.')
attr = frags.pop()
Expand Down Expand Up @@ -402,7 +405,7 @@ def get_resource_filters(self, resource, action='view'):
# exact filter
values = p.value.split(',')

data = zip(keys, values)
data = list(zip(keys, values))

filters = []
for key, value in data:
Expand Down
9 changes: 5 additions & 4 deletions baph/auth/models/__init__.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
from __future__ import print_function
from .permission import Permission
print 'Permission imported'
print('Permission imported')
from .organization import Organization
print 'Organization imported'
print('Organization imported')
from .group import Group
print 'Group imported'
print('Group imported')
from .user import AnonymousUser, User
print 'User imported'
print('User imported')
from .usergroup import UserGroup
from .permissionassociation import PermissionAssociation
from .oauth_ import OAuthConsumer, OAuthNonce
1 change: 1 addition & 0 deletions baph/auth/models/group/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from __future__ import absolute_import
from sqlalchemy import Column, ForeignKey, Integer
from sqlalchemy.orm import RelationshipProperty

Expand Down
1 change: 1 addition & 0 deletions baph/auth/models/group/base.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from __future__ import absolute_import
from sqlalchemy import Column, Integer, Unicode
from sqlalchemy.ext.associationproxy import association_proxy

Expand Down
5 changes: 3 additions & 2 deletions baph/auth/models/oauth_/__init__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from __future__ import absolute_import
from django.conf import settings
from oauth import oauth
import oauth2 as oauth
from sqlalchemy import (Column, DateTime, ForeignKey, Integer, String,
UniqueConstraint)
from sqlalchemy.orm import relationship
Expand Down Expand Up @@ -30,7 +31,7 @@ def as_consumer(self):
'''Creates an oauth.OAuthConsumer object from the DB data.
:rtype: oauth.OAuthConsumer
'''
return oauth.OAuthConsumer(self.key, self.secret)
return oauth.Consumer(self.key, self.secret)


class OAuthNonce(Base):
Expand Down
1 change: 1 addition & 0 deletions baph/auth/models/organization/base.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from __future__ import absolute_import
from sqlalchemy import Column, Integer, Unicode

from baph.db import ORM
Expand Down
1 change: 1 addition & 0 deletions baph/auth/models/permission/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from __future__ import absolute_import
from django.conf import settings
from sqlalchemy import Column, Integer, String, Unicode

Expand Down
1 change: 1 addition & 0 deletions baph/auth/models/permission/utils.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from __future__ import absolute_import
import funcy as f

from baph.auth.models.permission import Permission
Expand Down
1 change: 1 addition & 0 deletions baph/auth/models/permissionassociation/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from __future__ import absolute_import
from django.conf import settings
from sqlalchemy import Column, ForeignKey, Integer
from sqlalchemy.ext.associationproxy import association_proxy
Expand Down
1 change: 1 addition & 0 deletions baph/auth/models/user/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from __future__ import absolute_import
from datetime import datetime

from django.contrib.auth.signals import user_logged_in
Expand Down
5 changes: 3 additions & 2 deletions baph/auth/models/user/base.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from __future__ import absolute_import
from datetime import datetime
import urllib
import six.moves.urllib.request, six.moves.urllib.parse, six.moves.urllib.error

from django.conf import settings
from django.contrib.auth.hashers import check_password, make_password
Expand Down Expand Up @@ -154,7 +155,7 @@ def get_absolute_url(self):

:rtype: :class:`str`
'''
return '/users/%s/' % urllib.quote(smart_str(self.username))
return '/users/%s/' % six.moves.urllib.parse.quote(smart_str(self.username))

def get_full_name(self):
'''Retrieves the first_name plus the last_name, with a space in
Expand Down
1 change: 1 addition & 0 deletions baph/auth/models/user/utils.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from __future__ import absolute_import
import uuid

from django.conf import settings
Expand Down
1 change: 1 addition & 0 deletions baph/auth/models/usergroup/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from __future__ import absolute_import
from sqlalchemy import (Boolean, Column, ForeignKey, Index, Integer,
PrimaryKeyConstraint, String)
from sqlalchemy.orm import backref, relationship
Expand Down
1 change: 1 addition & 0 deletions baph/auth/registration/decorators.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from __future__ import absolute_import
from django.conf import settings
from django.http import HttpResponsePermanentRedirect
from django.utils.decorators import available_attrs
Expand Down
6 changes: 4 additions & 2 deletions baph/auth/registration/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

Forms and validation code for user registration.
'''
from __future__ import absolute_import
from hashlib import sha1 as sha_constructor
import random

Expand All @@ -18,6 +19,7 @@
from baph.auth.registration.managers import SignupManager
from baph.auth.utils import generate_sha1
from baph.db.orm import ORM
import six


orm = ORM.get()
Expand Down Expand Up @@ -188,7 +190,7 @@ def save(self):
""" Generate a random username before falling back to parent signup form """
session = orm.sessionmaker()
while True:
username = unicode(sha_constructor(str(random.random())).hexdigest()[:5])
username = six.text_type(sha_constructor(six.ensure_binary(str(random.random()))).hexdigest()[:5])
user = session.query(User).filter(User.username==username).first()
if not user:
break
Expand All @@ -211,7 +213,7 @@ def __init__(self, user, *args, **kwargs):
"""
super(ChangeEmailForm, self).__init__(*args, **kwargs)
if not isinstance(user, User):
raise TypeError, "user must be an instance of %s" % User._meta.model_name
raise TypeError("user must be an instance of %s" % User._meta.model_name)
else: self.user = user

def clean_email(self):
Expand Down
4 changes: 3 additions & 1 deletion baph/auth/registration/managers.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from __future__ import absolute_import
from datetime import datetime
import re

Expand All @@ -8,6 +9,7 @@
from baph.auth.registration.models import UserRegistration
from baph.auth.utils import generate_sha1
from baph.db.orm import ORM
import six


orm = ORM.get()
Expand All @@ -19,7 +21,7 @@ class SignupManager(object):
@staticmethod
def create_user(username, email, password, active=False, send_email=True,
**kwargs):
uname = username.encode('utf-8') if isinstance(username, unicode) else username
uname = username.encode('utf-8') if isinstance(username, six.text_type) else username
salt, activation_key = generate_sha1(uname)

#org_key = Organization._meta.verbose_name
Expand Down
1 change: 1 addition & 0 deletions baph/auth/registration/models.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from __future__ import absolute_import
import datetime

from coffin.shortcuts import render_to_string
Expand Down
1 change: 1 addition & 0 deletions baph/auth/registration/settings.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from __future__ import absolute_import
from django.conf import settings


Expand Down
1 change: 1 addition & 0 deletions baph/auth/registration/signals.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# -*- coding: utf-8 -*-

from __future__ import absolute_import
from django.dispatch import Signal

# A new user has registered.
Expand Down
1 change: 1 addition & 0 deletions baph/auth/registration/tests/backends.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from __future__ import absolute_import
import unittest2 as unittest

from django.conf import settings
Expand Down
3 changes: 2 additions & 1 deletion baph/auth/registration/tests/decorators.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from __future__ import absolute_import
import re

from django.conf import settings
Expand Down Expand Up @@ -27,7 +28,7 @@ def test_secure_required(self):
# Test if the redirected url contains 'https'. Couldn't use
# ``assertRedirects`` here because the redirected to page is
# non-existant.
self.assertTrue('https' in str(response))
self.assertTrue('https' in response._headers['location'][1])

# Set back to the old settings
auth_settings.BAPH_USE_HTTPS = False
1 change: 1 addition & 0 deletions baph/auth/registration/tests/forms.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from __future__ import unicode_literals
from __future__ import absolute_import
from django.utils.translation import ugettext_lazy as _

from baph.auth.models import User
Expand Down
1 change: 1 addition & 0 deletions baph/auth/registration/tests/managers.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from __future__ import unicode_literals
from __future__ import absolute_import
import datetime
import re

Expand Down
1 change: 1 addition & 0 deletions baph/auth/registration/tests/models.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from __future__ import unicode_literals
from __future__ import absolute_import
import datetime
import hashlib
import re
Expand Down
Loading