Skip to content

Commit

Permalink
Fixed Codacy issues in the lib #34
Browse files Browse the repository at this point in the history
  • Loading branch information
LukasRychtecky committed Jan 19, 2017
1 parent 34feab3 commit 38da836
Show file tree
Hide file tree
Showing 7 changed files with 33 additions and 21 deletions.
8 changes: 6 additions & 2 deletions chamber/commands/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,10 @@ def handle(self, *args, **kwargs):

class BulkImportCSVCommand(ImportCSVCommandMixin, BulkCSVImporter, BaseCommand):

def __init__(self, *args, **kwargs):
super(BulkImportCSVCommand, self).__init__(*args, **kwargs)
self.bar = None

def _pre_import_rows(self, row_count):
self.bar = pyprind.ProgBar(row_count, stream=ProgressBarStream(self.stdout))

Expand All @@ -46,7 +50,7 @@ def _post_batch_create(self, created_count, row_count):
def _post_import_rows(self, created_count, updated_count=0):
self.stdout.write('\nCreated {created} {model_name}.'.format(
created=created_count,
model_name=self.model_class._meta.verbose_name_plural
model_name=self.model_class._meta.verbose_name_plural # pylint: disable=W0212
))


Expand All @@ -55,6 +59,6 @@ class ImportCSVCommand(ImportCSVCommandMixin, CSVImporter, BaseCommand):
def _post_import_rows(self, created_count, updated_count=0):
self.stdout.write('Created {created} {model_name} and {updated} updated.'.format(
created=created_count,
model_name=self.model_class._meta.verbose_name_plural,
model_name=self.model_class._meta.verbose_name_plural, # pylint: disable=W0212
updated=updated_count)
)
1 change: 1 addition & 0 deletions chamber/exceptions/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
class PersistenceException(Exception):

def __init__(self, message=None):
super(PersistenceException, self).__init__()
self.message = message

def __str__(self):
Expand Down
4 changes: 2 additions & 2 deletions chamber/migrations/fixtures.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,10 @@ def _get_model(model_identifier):
except (LookupError, TypeError):
raise base.DeserializationError("Invalid model identifier: '%s'" % model_identifier)

get_model_tmp = python._get_model
get_model_tmp = python._get_model # pylint: disable=W0212
python._get_model = _get_model
file = os.path.join(self.fixture_dir, self.fixture_filename)
if not os.path.isfile(file):
raise IOError('File "%s" does not exists' % file)
call_command('loaddata', file, stdout=cStringIO())
python._get_model = get_model_tmp
python._get_model = get_model_tmp # pylint: disable=W0212
8 changes: 4 additions & 4 deletions chamber/multidomains/auth/backends.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ def authenticate(self, username=None, password=None, **kwargs):
if username is None:
username = kwargs.get(UserModel.USERNAME_FIELD)
try:
user = UserModel._default_manager.get_by_natural_key(username)
user = UserModel._default_manager.get_by_natural_key(username) # pylint: disable=W0212
if user.check_password(password):
return user
except UserModel.DoesNotExist:
Expand All @@ -35,12 +35,12 @@ def get_group_permissions(self, user_obj, obj=None):
if user_obj.is_superuser:
perms = Permission.objects.all()
else:
user_groups_field = get_user_class()._meta.get_field('groups')
user_groups_field = get_user_class()._meta.get_field('groups') # pylint: disable=W0212
user_groups_query = 'group__%s' % user_groups_field.related_query_name()
perms = Permission.objects.filter(**{user_groups_query: user_obj})
perms = perms.values_list('content_type__app_label', 'codename').order_by()
user_obj._group_perm_cache = set(["%s.%s" % (ct, name) for ct, name in perms])
return user_obj._group_perm_cache
user_obj._group_perm_cache = set(["%s.%s" % (ct, name) for ct, name in perms]) # pylint: disable=W0212
return user_obj._group_perm_cache # pylint: disable=W0212

def get_user(self, user_id):
UserModel = get_user_class()
Expand Down
14 changes: 8 additions & 6 deletions chamber/multidomains/auth/middleware.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,23 +2,24 @@

from django.utils.functional import SimpleLazyObject

from is_core.auth_token.middleware import TokenAuthenticationMiddlewares, get_user
from is_core import config as is_core_config
from is_core.auth_token import utils
from is_core.auth_token.utils import dont_enforce_csrf_checks
from is_core.auth_token.middleware import TokenAuthenticationMiddlewares, get_user
from is_core.auth_token.models import Token
from is_core.auth_token.utils import dont_enforce_csrf_checks
from is_core.utils import header_name_to_django
from is_core import config as is_core_config

from chamber.shortcuts import get_object_or_none
from chamber import config
from chamber.shortcuts import get_object_or_none


def get_token(request):
"""
Returns the token model instance associated with the given request token key.
If no user is retrieved AnonymousToken is returned.
"""
if not request.META.get(header_name_to_django(is_core_config.IS_CORE_AUTH_HEADER_NAME)) and config.CHAMBER_MULTIDOMAINS_OVERTAKER_AUTH_COOKIE_NAME:
if (not request.META.get(header_name_to_django(is_core_config.IS_CORE_AUTH_HEADER_NAME)) and
config.CHAMBER_MULTIDOMAINS_OVERTAKER_AUTH_COOKIE_NAME):
ovetaker_auth_token = request.COOKIES.get(config.CHAMBER_MULTIDOMAINS_OVERTAKER_AUTH_COOKIE_NAME)
token = get_object_or_none(Token, key=ovetaker_auth_token, is_active=True)
if utils.get_user_from_token(token).is_authenticated():
Expand All @@ -28,10 +29,11 @@ def get_token(request):


class MultiDomainsTokenAuthenticationMiddleware(TokenAuthenticationMiddlewares):

def process_request(self, request):
"""
Lazy set user and token
"""
request.token = get_token(request)
request.user = SimpleLazyObject(lambda: get_user(request))
request._dont_enforce_csrf_checks = dont_enforce_csrf_checks(request)
request._dont_enforce_csrf_checks = dont_enforce_csrf_checks(request) # pylint: disable=W0212
10 changes: 5 additions & 5 deletions chamber/utils/datastructures.py
Original file line number Diff line number Diff line change
Expand Up @@ -194,8 +194,8 @@ class OrderedSet(MutableSet):

def __init__(self, *iterable):
self.end = end = []
end += [None, end, end] # sentinel node for doubly linked list
self.map = {} # key --> [key, prev, next]
end += [None, end, end] # sentinel node for doubly linked list
self.map = {} # key --> [key, prev, next]
if iterable is not None:
self |= iterable

Expand All @@ -213,9 +213,9 @@ def add(self, key):

def discard(self, key):
if key in self.map:
key, prev, next = self.map.pop(key)
prev[2] = next
next[1] = prev
key, prev_item, next_item = self.map.pop(key)
prev_item[2] = next_item
next_item[1] = prev_item

def __iter__(self):
end = self.end
Expand Down
9 changes: 7 additions & 2 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,13 @@
"Framework :: Django",
],
install_requires=[
'Django >= 1.6',
'Django>=1.6',
'Unidecode>=0.04.17',
'pyprind==2.9.9',
'django-is-core>=1.3.145',
'six>=1.10.0',
],
)
dependency_links=[
'https://github.com/matllubos/django-is-core/tarball/1.3.145#egg=django-is-core-1.3.145',
],
)

0 comments on commit 38da836

Please sign in to comment.