diff --git a/fargo/fargo/admin.py b/fargo/fargo/admin.py index 8e76170..e1a72d7 100644 --- a/fargo/fargo/admin.py +++ b/fargo/fargo/admin.py @@ -16,7 +16,6 @@ from django.contrib import admin from django.contrib.auth import get_user_model -from django.utils.html import format_html from django.utils.translation import ugettext_lazy as _ from . import models @@ -43,7 +42,7 @@ class DocumentAdmin(admin.ModelAdmin): def users(self, instance): User = get_user_model() qs = User.objects.filter(user_documents__document=instance) - return u', '.join(unicode(u) for u in qs) + return u', '.join(u'%s' % u for u in qs) def thumbnail(self, instance): return instance.thumbnail_img_tag diff --git a/fargo/fargo/api_views.py b/fargo/fargo/api_views.py index e8bf990..b514cea 100644 --- a/fargo/fargo/api_views.py +++ b/fargo/fargo/api_views.py @@ -79,7 +79,7 @@ class CommonAPIMixin(object): return super(CommonAPIMixin, self).handle_exception(exc) def finalize_response(self, request, response, *args, **kwargs): - if not isinstance(response.data, dict) or not 'result' in response.data: + if not isinstance(response.data, dict) or 'result' not in response.data: response.data = {'result': 1, 'data': response.data} return super(CommonAPIMixin, self).finalize_response(request, response, *args, **kwargs) diff --git a/fargo/fargo/models.py b/fargo/fargo/models.py index 0807c56..6b08c34 100644 --- a/fargo/fargo/models.py +++ b/fargo/fargo/models.py @@ -121,8 +121,8 @@ class UserDocument(models.Model): if not self.document.mime_type: return '' return 'mime-%s mime-%s' % ( - self.document.mime_type.split('/')[0], - re.sub('[/\.+-]', '-', self.document.mime_type)) + self.document.mime_type.split('/')[0], + re.sub(r'[/\.+-]', '-', self.document.mime_type)) @python_2_unicode_compatible @@ -164,14 +164,14 @@ class Validation(models.Model): return force_text(template.format(**self.data)) except KeyError: pass - l = [] + parts = [] for meta_field in self.metadata: - l.append(_(u'%(label)s: %(value)s') - % { - 'label': meta_field['label'], - 'value': self.data.get(meta_field['varname'], ''), - }) - return force_text(u'; '.join(l)) + parts.append( + _(u'%(label)s: %(value)s') % { + 'label': meta_field['label'], + 'value': self.data.get(meta_field['varname'], ''), + }) + return force_text(u'; '.join(parts)) display.short_description = _('description') @property @@ -217,7 +217,7 @@ class Document(models.Model): return None try: thumbnail = get_thumbnail(self.content, '200x200') - except: # sorl-thumbnail can crash in unexpected ways + except Exception: # sorl-thumbnail can crash in unexpected ways return None try: # check file exists and is readable @@ -256,7 +256,8 @@ class Document(models.Model): @classmethod def occupancy_for_user(cls, user): - return float(sum(document.content.size for document in cls.objects.filter(user_documents__user=user).distinct())) + documents = cls.objects.filter(user_documents__user=user).distinct() + return float(sum(document.content.size for document in documents)) def __unicode__(self): return u'%s %s' % (os.path.basename(self.content.name), self.content_hash[:6]) diff --git a/fargo/fargo/views.py b/fargo/fargo/views.py index 9d8f688..c284d0e 100644 --- a/fargo/fargo/views.py +++ b/fargo/fargo/views.py @@ -44,7 +44,8 @@ from . import models, forms, tables try: from mellon.utils import get_idps except ImportError: - get_idps = lambda: [] + def get_idps(): + return [] class Logger(object): @@ -273,7 +274,7 @@ class ChooseDocumentKind(TemplateView): def login(request, *args, **kwargs): if any(get_idps()): - if not 'next' in request.GET: + if 'next' not in request.GET: return HttpResponseRedirect(resolve_url('mellon_login')) return HttpResponseRedirect(resolve_url('mellon_login') + '?next=' + quote(request.GET.get('next'))) diff --git a/fargo/oauth2/admin.py b/fargo/oauth2/admin.py index b8acef1..083957b 100644 --- a/fargo/oauth2/admin.py +++ b/fargo/oauth2/admin.py @@ -24,6 +24,7 @@ class OAuth2ClientAdmin(admin.ModelAdmin): fields = ('client_name', 'client_id', 'client_secret', 'redirect_uris') list_display = ['client_name', 'client_id', 'client_secret', 'redirect_uris'] + class OAuth2AuthorizeAdmin(admin.ModelAdmin): list_display = ['id', 'client_name', 'user_document', 'thumbnail', 'access_token', 'code', 'creation_date'] diff --git a/fargo/oauth2/management/commands/oauth2-create-client.py b/fargo/oauth2/management/commands/oauth2-create-client.py index 370e1a3..5fd3de7 100644 --- a/fargo/oauth2/management/commands/oauth2-create-client.py +++ b/fargo/oauth2/management/commands/oauth2-create-client.py @@ -37,4 +37,4 @@ class Command(BaseCommand): kwargs['client_id'] = client_id if client_secret: kwargs['client_secret'] = client_secret - client = OAuth2Client.objects.create(**kwargs) + OAuth2Client.objects.create(**kwargs) diff --git a/fargo/oauth2/views.py b/fargo/oauth2/views.py index b5401d5..1f99172 100644 --- a/fargo/oauth2/views.py +++ b/fargo/oauth2/views.py @@ -109,7 +109,7 @@ class OAuth2AuthorizeView(FormView): def get_context_data(self, **kwargs): kwargs['oauth2_client'] = self.client - return super(OAuth2AuthorizeView , self).get_context_data(**kwargs) + return super(OAuth2AuthorizeView, self).get_context_data(**kwargs) authorize_get_document = login_required(OAuth2AuthorizeView.as_view()) @@ -159,6 +159,7 @@ def document_response(user_document): percent_encoded_filename) return response + def get_document(request): oauth_authorize = authenticate_bearer(request) if not oauth_authorize: diff --git a/fargo/wsgi.py b/fargo/wsgi.py index 255adf2..cb85623 100644 --- a/fargo/wsgi.py +++ b/fargo/wsgi.py @@ -23,8 +23,9 @@ For more information on this file, see https://docs.djangoproject.com/en/1.7/howto/deployment/wsgi/ """ +from django.core.wsgi import get_wsgi_application import os + os.environ.setdefault("DJANGO_SETTINGS_MODULE", "fargo.settings") -from django.core.wsgi import get_wsgi_application application = get_wsgi_application()