PEP8 cleanups, style cleanups, unused imports
This commit is contained in:
@@ -24,11 +24,11 @@ class CompressedFile(object):
|
||||
self._open(file_input)
|
||||
else:
|
||||
self._create()
|
||||
|
||||
|
||||
def _create(self):
|
||||
self.descriptor = StringIO()
|
||||
self.zf = zipfile.ZipFile(self.descriptor, mode='w')
|
||||
|
||||
|
||||
def _open(self, file_input):
|
||||
try:
|
||||
# Is it a file like object?
|
||||
@@ -37,7 +37,7 @@ class CompressedFile(object):
|
||||
# If not, try open it.
|
||||
self.descriptor = open(file_input, 'r+b')
|
||||
else:
|
||||
self.descriptor = file_input
|
||||
self.descriptor = file_input
|
||||
|
||||
try:
|
||||
test = zipfile.ZipFile(self.descriptor, mode='r')
|
||||
@@ -54,23 +54,23 @@ class CompressedFile(object):
|
||||
file_input.seek(0)
|
||||
except AttributeError:
|
||||
# If not, keep it
|
||||
self.zf.write(file_input, arcname=arcname, compress_type=COMPRESSION)
|
||||
self.zf.write(file_input, arcname=arcname, compress_type=COMPRESSION)
|
||||
else:
|
||||
self.zf.writestr(arcname, file_input.read())
|
||||
|
||||
def contents(self):
|
||||
return [filename for filename in self.zf.namelist() if not filename.endswith('/')]
|
||||
|
||||
|
||||
def get_content(self, filename):
|
||||
return self.zf.read(filename)
|
||||
|
||||
|
||||
def write(self, filename=None):
|
||||
# fix for Linux zip files read in Windows
|
||||
for file in self.zf.filelist:
|
||||
# fix for Linux zip files read in Windows
|
||||
for file in self.zf.filelist:
|
||||
file.create_system = 0
|
||||
|
||||
self.descriptor.seek(0)
|
||||
|
||||
|
||||
if filename:
|
||||
descriptor = open(filename, 'w')
|
||||
descriptor.write(self.descriptor.read())
|
||||
|
||||
@@ -92,10 +92,10 @@ class FilterForm(forms.Form):
|
||||
|
||||
|
||||
class ChoiceForm(forms.Form):
|
||||
'''
|
||||
"""
|
||||
Form to be used in side by side templates used to add or remove
|
||||
items from a many to many field
|
||||
'''
|
||||
"""
|
||||
def __init__(self, *args, **kwargs):
|
||||
choices = kwargs.pop('choices', [])
|
||||
label = kwargs.pop('label', _(u'Selection'))
|
||||
@@ -108,28 +108,28 @@ class ChoiceForm(forms.Form):
|
||||
|
||||
|
||||
class UserForm_view(DetailForm):
|
||||
'''
|
||||
"""
|
||||
Form used to display an user's public details
|
||||
'''
|
||||
"""
|
||||
class Meta:
|
||||
model = User
|
||||
fields = ('username', 'first_name', 'last_name', 'email', 'is_staff', 'is_superuser', 'last_login', 'date_joined', 'groups')
|
||||
|
||||
|
||||
class UserForm(forms.ModelForm):
|
||||
'''
|
||||
"""
|
||||
Form used to edit an user's mininal fields by the user himself
|
||||
'''
|
||||
"""
|
||||
class Meta:
|
||||
model = User
|
||||
fields = ('first_name', 'last_name')
|
||||
|
||||
|
||||
class EmailAuthenticationForm(AuthenticationForm):
|
||||
'''
|
||||
"""
|
||||
Override the default authentication form to use email address
|
||||
authentication
|
||||
'''
|
||||
"""
|
||||
email = forms.CharField(label=_(u'Email'), max_length=75,
|
||||
widget=EmailInput()
|
||||
)
|
||||
@@ -153,7 +153,7 @@ EmailAuthenticationForm.base_fields.keyOrder = ['email', 'password']
|
||||
|
||||
class FileDisplayForm(forms.Form):
|
||||
text = forms.CharField(
|
||||
label='',#_(u'Text'),
|
||||
label='', # _(u'Text'),
|
||||
widget=forms.widgets.Textarea(
|
||||
attrs={'cols': 40, 'rows': 20, 'readonly': 'readonly'}
|
||||
)
|
||||
|
||||
@@ -34,14 +34,14 @@ class AnonymousUserSingletonManager(SingletonManager):
|
||||
return self.model.objects.get()
|
||||
else:
|
||||
return user
|
||||
|
||||
|
||||
|
||||
class AnonymousUserSingleton(Singleton):
|
||||
objects = AnonymousUserSingletonManager()
|
||||
|
||||
def __unicode__(self):
|
||||
return ugettext('Anonymous user')
|
||||
|
||||
|
||||
class Meta:
|
||||
verbose_name = _(u'anonymous user')
|
||||
verbose_name_plural = _(u'anonymous user')
|
||||
|
||||
@@ -1,12 +1,13 @@
|
||||
from django import template
|
||||
|
||||
|
||||
register = template.Library()
|
||||
|
||||
|
||||
|
||||
class SetVarNode(template.Node):
|
||||
def __init__(self, var_name, var_value):
|
||||
self.var_name = var_name
|
||||
self.var_value = var_value
|
||||
|
||||
|
||||
def render(self, context):
|
||||
try:
|
||||
value = template.Variable(self.var_value).resolve(context)
|
||||
@@ -17,7 +18,8 @@ class SetVarNode(template.Node):
|
||||
context.dicts[0][self.var_name] = value
|
||||
|
||||
return u""
|
||||
|
||||
|
||||
|
||||
def set_var(parser, token):
|
||||
"""
|
||||
{% set <var_name> = <var_value> %}
|
||||
@@ -26,5 +28,5 @@ def set_var(parser, token):
|
||||
if len(parts) < 4:
|
||||
raise template.TemplateSyntaxError("'set' tag must be of the form: {% set <var_name> = <var_value> %}")
|
||||
return SetVarNode(parts[1], parts[3])
|
||||
|
||||
|
||||
register.tag('set', set_var)
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
# -*- coding: utf-8 -*-
|
||||
from __future__ import absolute_import
|
||||
|
||||
import os
|
||||
@@ -18,7 +18,7 @@ from django.contrib.auth.models import User
|
||||
|
||||
|
||||
def urlquote(link=None, get=None):
|
||||
u'''
|
||||
u"""
|
||||
This method does both: urlquote() and urlencode()
|
||||
|
||||
urlqoute(): Quote special characters in 'link'
|
||||
@@ -33,7 +33,7 @@ def urlquote(link=None, get=None):
|
||||
urlquote('/mypath/', {'key': 'value'}) --> '/mypath/?key=value'
|
||||
urlquote('/mypath/', {'key': ['value1', 'value2']}) --> '/mypath/?key=value1&key=value2'
|
||||
urlquote({'key': ['value1', 'value2']}) --> 'key=value1&key=value2'
|
||||
'''
|
||||
"""
|
||||
if get is None:
|
||||
get = []
|
||||
|
||||
@@ -112,9 +112,9 @@ def pretty_size_10(size):
|
||||
# http://www.johncardinal.com/tmgutil/capitalizenames.htm
|
||||
|
||||
def proper_name(name):
|
||||
'''
|
||||
"""
|
||||
Does the work of capitalizing a name (can be a full name).
|
||||
'''
|
||||
"""
|
||||
mc = re.compile(r'^Mc(\w)(?=\w)', re.I)
|
||||
mac = re.compile(r'^Mac(\w)(?=\w)', re.I)
|
||||
suffixes = [
|
||||
@@ -330,7 +330,7 @@ def generate_choices_w_labels(choices, display_object_type=True):
|
||||
return sorted(results, key=lambda x: x[1])
|
||||
|
||||
|
||||
def get_object_name(obj, display_object_type=True):
|
||||
def get_object_name(obj, display_object_type=True):
|
||||
ct_label = ContentType.objects.get_for_model(obj).name
|
||||
if isinstance(obj, User):
|
||||
label = obj.get_full_name() if obj.get_full_name() else obj
|
||||
@@ -342,7 +342,7 @@ def get_object_name(obj, display_object_type=True):
|
||||
verbose_name = unicode(obj._meta.verbose_name)
|
||||
except AttributeError:
|
||||
verbose_name = ct_label
|
||||
|
||||
|
||||
return u'%s: %s' % (verbose_name, label)
|
||||
else:
|
||||
return u'%s' % (label)
|
||||
|
||||
+19
-19
@@ -18,19 +18,19 @@ from .conf.settings import LOGIN_METHOD
|
||||
|
||||
|
||||
def password_change_done(request):
|
||||
'''
|
||||
"""
|
||||
View called when the new user password has been accepted
|
||||
'''
|
||||
"""
|
||||
|
||||
messages.success(request, _(u'Your password has been successfully changed.'))
|
||||
return redirect('home')
|
||||
|
||||
|
||||
def multi_object_action_view(request):
|
||||
'''
|
||||
"""
|
||||
Proxy view called first when using a multi object action, which
|
||||
then redirects to the appropiate specialized view
|
||||
'''
|
||||
"""
|
||||
|
||||
next = request.POST.get('next', request.GET.get('next', request.META.get('HTTP_REFERER', '/')))
|
||||
|
||||
@@ -83,7 +83,7 @@ def assign_remove(request, left_list, right_list, add_method, remove_method, lef
|
||||
flat_list.extend(group[1])
|
||||
else:
|
||||
flat_list = left_list()
|
||||
|
||||
|
||||
label = dict(flat_list)[selection]
|
||||
if decode_content_type:
|
||||
selection_obj = get_obj_from_content_type_string(selection)
|
||||
@@ -109,7 +109,7 @@ def assign_remove(request, left_list, right_list, add_method, remove_method, lef
|
||||
flat_list.extend(group[1])
|
||||
else:
|
||||
flat_list = right_list()
|
||||
|
||||
|
||||
label = dict(flat_list)[selection]
|
||||
if decode_content_type:
|
||||
selection = get_obj_from_content_type_string(selection)
|
||||
@@ -159,9 +159,9 @@ def assign_remove(request, left_list, right_list, add_method, remove_method, lef
|
||||
|
||||
|
||||
def current_user_details(request):
|
||||
'''
|
||||
"""
|
||||
Display the current user's details
|
||||
'''
|
||||
"""
|
||||
form = UserForm_view(instance=request.user)
|
||||
|
||||
return render_to_response(
|
||||
@@ -174,9 +174,9 @@ def current_user_details(request):
|
||||
|
||||
|
||||
def current_user_edit(request):
|
||||
'''
|
||||
"""
|
||||
Allow an user to edit his own details
|
||||
'''
|
||||
"""
|
||||
|
||||
next = request.POST.get('next', request.GET.get('next', request.META.get('HTTP_REFERER', reverse('current_user_details'))))
|
||||
|
||||
@@ -199,15 +199,15 @@ def current_user_edit(request):
|
||||
|
||||
|
||||
def login_view(request):
|
||||
'''
|
||||
Control how the use is to be authenticated, options are 'email' and
|
||||
"""
|
||||
Control how the use is to be authenticated, options are 'email' and
|
||||
'username'
|
||||
'''
|
||||
"""
|
||||
kwargs = {'template_name': 'login.html'}
|
||||
|
||||
|
||||
if LOGIN_METHOD == 'email':
|
||||
kwargs['authentication_form'] = EmailAuthenticationForm
|
||||
|
||||
|
||||
if not request.user.is_authenticated():
|
||||
context = {'web_theme_view_type': 'plain'}
|
||||
else:
|
||||
@@ -217,9 +217,9 @@ def login_view(request):
|
||||
|
||||
|
||||
def changelog_view(request):
|
||||
'''
|
||||
"""
|
||||
Display the included Changelog.txt file from the about menu
|
||||
'''
|
||||
"""
|
||||
form = ChangelogForm()
|
||||
return render_to_response(
|
||||
'generic_detail.html', {
|
||||
@@ -230,9 +230,9 @@ def changelog_view(request):
|
||||
|
||||
|
||||
def license_view(request):
|
||||
'''
|
||||
"""
|
||||
Display the included LICENSE file from the about menu
|
||||
'''
|
||||
"""
|
||||
form = LicenseForm()
|
||||
return render_to_response(
|
||||
'generic_detail.html', {
|
||||
|
||||
+11
-11
@@ -10,10 +10,10 @@ from django.utils.encoding import force_unicode
|
||||
|
||||
|
||||
class PlainWidget(forms.widgets.Widget):
|
||||
'''
|
||||
"""
|
||||
Class to define a form widget that effectively nulls the htmls of a
|
||||
widget and reduces the output to only it's value
|
||||
'''
|
||||
"""
|
||||
def render(self, name, value, attrs=None):
|
||||
return mark_safe(u'%s' % value)
|
||||
|
||||
@@ -74,11 +74,11 @@ def two_state_template(state, famfam_ok_icon=u'tick', famfam_fail_icon=u'cross')
|
||||
|
||||
|
||||
class TextAreaDiv(forms.widgets.Widget):
|
||||
'''
|
||||
"""
|
||||
Class to define a form widget that simulates the behavior of a
|
||||
Textarea widget but using a div tag instead
|
||||
'''
|
||||
|
||||
"""
|
||||
|
||||
def __init__(self, attrs=None):
|
||||
# The 'rows' and 'cols' attributes are required for HTML correctness.
|
||||
default_attrs = {'class': 'text_area_div'}
|
||||
@@ -98,10 +98,10 @@ class TextAreaDiv(forms.widgets.Widget):
|
||||
|
||||
# From: http://www.peterbe.com/plog/emailinput-html5-django
|
||||
class EmailInput(forms.widgets.Input):
|
||||
'''
|
||||
Class for a login form widget that accepts only well formated
|
||||
"""
|
||||
Class for a login form widget that accepts only well formated
|
||||
email address
|
||||
'''
|
||||
"""
|
||||
input_type = 'email'
|
||||
|
||||
def render(self, name, value, attrs=None):
|
||||
@@ -114,11 +114,11 @@ class EmailInput(forms.widgets.Input):
|
||||
|
||||
|
||||
class ScrollableCheckboxSelectMultiple(forms.widgets.CheckboxSelectMultiple):
|
||||
'''
|
||||
"""
|
||||
Class for a form widget composed of a selection of checkboxes wrapped
|
||||
in a div tag with automatic overflow to add scrollbars when the list
|
||||
exceds the height of the div
|
||||
'''
|
||||
"""
|
||||
def render(self, name, value, attrs=None, choices=()):
|
||||
if value is None:
|
||||
value = []
|
||||
@@ -142,5 +142,5 @@ class ScrollableCheckboxSelectMultiple(forms.widgets.CheckboxSelectMultiple):
|
||||
option_label = conditional_escape(force_unicode(option_label))
|
||||
output.append(u'<li><label%s>%s %s</label></li>' % (label_for, rendered_cb, option_label))
|
||||
output.append(u'</ul>')
|
||||
|
||||
|
||||
return mark_safe(u'<div class="text_area_div">%s</div>' % u'\n'.join(output))
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
'''Common abstract classes for forms.'''
|
||||
"""Common abstract classes for forms."""
|
||||
try:
|
||||
import cPickle as pickle
|
||||
except ImportError:
|
||||
@@ -15,13 +15,13 @@ __all__ = ('security_hash', 'BoundFormWizard')
|
||||
|
||||
|
||||
def security_hash_new(form, exclude=None, *args):
|
||||
'''
|
||||
"""
|
||||
Calculates a security hash for the given Form/FormSet instance.
|
||||
|
||||
This creates a list of the form field names/values in a deterministic
|
||||
order, pickles the result with the SECRET_KEY setting, then takes an md5
|
||||
hash of that.
|
||||
'''
|
||||
"""
|
||||
|
||||
data = []
|
||||
if exclude is None:
|
||||
@@ -52,20 +52,20 @@ def security_hash_new(form, exclude=None, *args):
|
||||
|
||||
|
||||
class BoundFormWizard(FormWizard):
|
||||
'''
|
||||
"""
|
||||
Render prev_fields as a list of bound form fields in the template
|
||||
context rather than raw html.
|
||||
'''
|
||||
|
||||
"""
|
||||
|
||||
def security_hash(self, request, form):
|
||||
'''
|
||||
"""
|
||||
Calculates the security hash for the given HttpRequest and
|
||||
Form/FormSet instances.
|
||||
|
||||
Subclasses may want to take into account request-specific information,
|
||||
such as the IP address.
|
||||
'''
|
||||
|
||||
"""
|
||||
|
||||
return security_hash_new(form)
|
||||
|
||||
def render(self, form, request, step, context=None):
|
||||
|
||||
Reference in New Issue
Block a user