pep8ness & style & py3
This commit is contained in:
parent
7ab9a10a6c
commit
8c032bd55b
|
@ -16,7 +16,6 @@
|
||||||
|
|
||||||
from django.contrib import admin
|
from django.contrib import admin
|
||||||
from django.contrib.auth import get_user_model
|
from django.contrib.auth import get_user_model
|
||||||
from django.utils.html import format_html
|
|
||||||
from django.utils.translation import ugettext_lazy as _
|
from django.utils.translation import ugettext_lazy as _
|
||||||
|
|
||||||
from . import models
|
from . import models
|
||||||
|
@ -43,7 +42,7 @@ class DocumentAdmin(admin.ModelAdmin):
|
||||||
def users(self, instance):
|
def users(self, instance):
|
||||||
User = get_user_model()
|
User = get_user_model()
|
||||||
qs = User.objects.filter(user_documents__document=instance)
|
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):
|
def thumbnail(self, instance):
|
||||||
return instance.thumbnail_img_tag
|
return instance.thumbnail_img_tag
|
||||||
|
|
|
@ -79,7 +79,7 @@ class CommonAPIMixin(object):
|
||||||
return super(CommonAPIMixin, self).handle_exception(exc)
|
return super(CommonAPIMixin, self).handle_exception(exc)
|
||||||
|
|
||||||
def finalize_response(self, request, response, *args, **kwargs):
|
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}
|
response.data = {'result': 1, 'data': response.data}
|
||||||
return super(CommonAPIMixin, self).finalize_response(request, response, *args, **kwargs)
|
return super(CommonAPIMixin, self).finalize_response(request, response, *args, **kwargs)
|
||||||
|
|
||||||
|
|
|
@ -121,8 +121,8 @@ class UserDocument(models.Model):
|
||||||
if not self.document.mime_type:
|
if not self.document.mime_type:
|
||||||
return ''
|
return ''
|
||||||
return 'mime-%s mime-%s' % (
|
return 'mime-%s mime-%s' % (
|
||||||
self.document.mime_type.split('/')[0],
|
self.document.mime_type.split('/')[0],
|
||||||
re.sub('[/\.+-]', '-', self.document.mime_type))
|
re.sub(r'[/\.+-]', '-', self.document.mime_type))
|
||||||
|
|
||||||
|
|
||||||
@python_2_unicode_compatible
|
@python_2_unicode_compatible
|
||||||
|
@ -164,14 +164,14 @@ class Validation(models.Model):
|
||||||
return force_text(template.format(**self.data))
|
return force_text(template.format(**self.data))
|
||||||
except KeyError:
|
except KeyError:
|
||||||
pass
|
pass
|
||||||
l = []
|
parts = []
|
||||||
for meta_field in self.metadata:
|
for meta_field in self.metadata:
|
||||||
l.append(_(u'%(label)s: %(value)s')
|
parts.append(
|
||||||
% {
|
_(u'%(label)s: %(value)s') % {
|
||||||
'label': meta_field['label'],
|
'label': meta_field['label'],
|
||||||
'value': self.data.get(meta_field['varname'], ''),
|
'value': self.data.get(meta_field['varname'], ''),
|
||||||
})
|
})
|
||||||
return force_text(u'; '.join(l))
|
return force_text(u'; '.join(parts))
|
||||||
display.short_description = _('description')
|
display.short_description = _('description')
|
||||||
|
|
||||||
@property
|
@property
|
||||||
|
@ -217,7 +217,7 @@ class Document(models.Model):
|
||||||
return None
|
return None
|
||||||
try:
|
try:
|
||||||
thumbnail = get_thumbnail(self.content, '200x200')
|
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
|
return None
|
||||||
try:
|
try:
|
||||||
# check file exists and is readable
|
# check file exists and is readable
|
||||||
|
@ -256,7 +256,8 @@ class Document(models.Model):
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def occupancy_for_user(cls, user):
|
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):
|
def __unicode__(self):
|
||||||
return u'%s %s' % (os.path.basename(self.content.name), self.content_hash[:6])
|
return u'%s %s' % (os.path.basename(self.content.name), self.content_hash[:6])
|
||||||
|
|
|
@ -44,7 +44,8 @@ from . import models, forms, tables
|
||||||
try:
|
try:
|
||||||
from mellon.utils import get_idps
|
from mellon.utils import get_idps
|
||||||
except ImportError:
|
except ImportError:
|
||||||
get_idps = lambda: []
|
def get_idps():
|
||||||
|
return []
|
||||||
|
|
||||||
|
|
||||||
class Logger(object):
|
class Logger(object):
|
||||||
|
@ -273,7 +274,7 @@ class ChooseDocumentKind(TemplateView):
|
||||||
|
|
||||||
def login(request, *args, **kwargs):
|
def login(request, *args, **kwargs):
|
||||||
if any(get_idps()):
|
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'))
|
||||||
return HttpResponseRedirect(resolve_url('mellon_login') + '?next='
|
return HttpResponseRedirect(resolve_url('mellon_login') + '?next='
|
||||||
+ quote(request.GET.get('next')))
|
+ quote(request.GET.get('next')))
|
||||||
|
|
|
@ -24,6 +24,7 @@ class OAuth2ClientAdmin(admin.ModelAdmin):
|
||||||
fields = ('client_name', 'client_id', 'client_secret', 'redirect_uris')
|
fields = ('client_name', 'client_id', 'client_secret', 'redirect_uris')
|
||||||
list_display = ['client_name', 'client_id', 'client_secret', 'redirect_uris']
|
list_display = ['client_name', 'client_id', 'client_secret', 'redirect_uris']
|
||||||
|
|
||||||
|
|
||||||
class OAuth2AuthorizeAdmin(admin.ModelAdmin):
|
class OAuth2AuthorizeAdmin(admin.ModelAdmin):
|
||||||
list_display = ['id', 'client_name', 'user_document', 'thumbnail',
|
list_display = ['id', 'client_name', 'user_document', 'thumbnail',
|
||||||
'access_token', 'code', 'creation_date']
|
'access_token', 'code', 'creation_date']
|
||||||
|
|
|
@ -37,4 +37,4 @@ class Command(BaseCommand):
|
||||||
kwargs['client_id'] = client_id
|
kwargs['client_id'] = client_id
|
||||||
if client_secret:
|
if client_secret:
|
||||||
kwargs['client_secret'] = client_secret
|
kwargs['client_secret'] = client_secret
|
||||||
client = OAuth2Client.objects.create(**kwargs)
|
OAuth2Client.objects.create(**kwargs)
|
||||||
|
|
|
@ -109,7 +109,7 @@ class OAuth2AuthorizeView(FormView):
|
||||||
|
|
||||||
def get_context_data(self, **kwargs):
|
def get_context_data(self, **kwargs):
|
||||||
kwargs['oauth2_client'] = self.client
|
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())
|
authorize_get_document = login_required(OAuth2AuthorizeView.as_view())
|
||||||
|
@ -159,6 +159,7 @@ def document_response(user_document):
|
||||||
percent_encoded_filename)
|
percent_encoded_filename)
|
||||||
return response
|
return response
|
||||||
|
|
||||||
|
|
||||||
def get_document(request):
|
def get_document(request):
|
||||||
oauth_authorize = authenticate_bearer(request)
|
oauth_authorize = authenticate_bearer(request)
|
||||||
if not oauth_authorize:
|
if not oauth_authorize:
|
||||||
|
|
|
@ -23,8 +23,9 @@ For more information on this file, see
|
||||||
https://docs.djangoproject.com/en/1.7/howto/deployment/wsgi/
|
https://docs.djangoproject.com/en/1.7/howto/deployment/wsgi/
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
from django.core.wsgi import get_wsgi_application
|
||||||
import os
|
import os
|
||||||
|
|
||||||
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "fargo.settings")
|
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "fargo.settings")
|
||||||
|
|
||||||
from django.core.wsgi import get_wsgi_application
|
|
||||||
application = get_wsgi_application()
|
application = get_wsgi_application()
|
||||||
|
|
Loading…
Reference in New Issue