Cleanups, permissions separation into explicit module, absolute import update

This commit is contained in:
Roberto Rosario
2012-01-02 03:48:26 -04:00
parent 2781a211ec
commit 34311fb17e
107 changed files with 693 additions and 468 deletions

View File

@@ -1,3 +1,5 @@
from __future__ import absolute_import
import tempfile
from django.utils.translation import ugettext_lazy as _
@@ -7,8 +9,8 @@ from django.db.models import signals
from navigation.api import register_links, register_top_menu
from common.conf import settings as common_settings
from common.utils import validate_path
from .conf import settings as common_settings
from .utils import validate_path
def has_usable_password(context):

View File

@@ -1,3 +1,5 @@
from __future__ import absolute_import
import os
from django import forms
@@ -8,9 +10,9 @@ from django.contrib.auth.forms import AuthenticationForm
from django.contrib.auth import authenticate
from django.conf import settings
from common.utils import return_attrib
from common.widgets import DetailSelectMultiple, PlainWidget, \
TextAreaDiv, EmailInput
from .utils import return_attrib
from .widgets import (DetailSelectMultiple, PlainWidget, TextAreaDiv,
EmailInput)
class DetailForm(forms.ModelForm):
@@ -90,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'))
@@ -106,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()
)

View File

@@ -110,7 +110,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)."""
'''
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 = [

View File

@@ -1,3 +1,5 @@
from __future__ import absolute_import
from django.shortcuts import redirect
from django.utils.translation import ugettext_lazy as _
from django.http import HttpResponseRedirect
@@ -10,26 +12,25 @@ from django.utils.http import urlencode
from django.contrib.auth.views import login
from django.utils.simplejson import dumps, loads
from common.forms import ChoiceForm, UserForm, UserForm_view, \
ChangelogForm, LicenseForm
from common.forms import EmailAuthenticationForm
from common.conf.settings import LOGIN_METHOD
from .forms import (ChoiceForm, UserForm, UserForm_view, ChangelogForm,
LicenseForm, EmailAuthenticationForm)
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', '/')))
@@ -144,9 +145,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(
@@ -159,9 +160,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'))))
@@ -184,10 +185,10 @@ def current_user_edit(request):
def login_view(request):
"""
'''
Control how the use is to be authenticated, options are 'email' and
'username'
"""
'''
kwargs = {'template_name': 'login.html'}
if LOGIN_METHOD == 'email':
@@ -197,9 +198,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', {
@@ -210,9 +211,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', {

View File

@@ -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,10 +74,10 @@ 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.
@@ -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
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 = []
has_id = attrs and 'id' in attrs

View File

@@ -1,4 +1,4 @@
"""Common abstract classes for forms."""
'''Common abstract classes for forms.'''
try:
import cPickle as pickle
except ImportError:
@@ -15,12 +15,13 @@ __all__ = ('security_hash', 'BoundFormWizard')
def security_hash_new(form, exclude=None, *args):
"""Calculates a security hash for the given Form/FormSet instance.
'''
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:
@@ -51,19 +52,24 @@ 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."""
'''
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
'''
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):
"Renders the given Form object, returning an HttpResponse."
'Renders the given Form object, returning an HttpResponse.'
old_data = request.POST
prev_fields = []
if old_data: