Add from __future__ import unicode_literals, issue #37
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
from __future__ import absolute_import
|
||||
from __future__ import absolute_import, unicode_literals
|
||||
|
||||
import logging
|
||||
import tempfile
|
||||
@@ -6,16 +6,15 @@ import tempfile
|
||||
from django.conf import settings
|
||||
from django.contrib.auth import models as auth_models
|
||||
from django.contrib.auth.models import User
|
||||
from django.contrib.auth.signals import user_logged_in
|
||||
from django.db.models.signals import post_save
|
||||
from django.dispatch import receiver
|
||||
|
||||
from django.contrib.auth.signals import user_logged_in
|
||||
|
||||
from south.signals import post_migrate
|
||||
|
||||
from common import settings as common_settings
|
||||
from navigation.api import register_links, register_top_menu
|
||||
|
||||
from common import settings as common_settings
|
||||
from .links import (link_about, link_current_user_details,
|
||||
link_current_user_edit,
|
||||
link_current_user_locale_profile_details,
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
from __future__ import absolute_import
|
||||
from __future__ import unicode_literals
|
||||
|
||||
from django.contrib import admin
|
||||
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
from __future__ import unicode_literals
|
||||
|
||||
from django.db import models
|
||||
from django.utils.translation import ugettext
|
||||
|
||||
@@ -39,7 +41,7 @@ class ModelAttribute(object):
|
||||
|
||||
def get_display(self, show_name=False):
|
||||
if self.description:
|
||||
return u'{} - {}'.format(self.name if show_name else self.label, self.description)
|
||||
return '{} - {}'.format(self.name if show_name else self.label, self.description)
|
||||
else:
|
||||
return unicode(self.name if show_name else self.label)
|
||||
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
from __future__ import unicode_literals
|
||||
|
||||
import zipfile
|
||||
|
||||
try:
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
from __future__ import absolute_import
|
||||
from __future__ import unicode_literals
|
||||
|
||||
import warnings
|
||||
import os
|
||||
@@ -95,7 +95,7 @@ class ChoiceForm(forms.Form):
|
||||
"""
|
||||
def __init__(self, *args, **kwargs):
|
||||
choices = kwargs.pop('choices', [])
|
||||
label = kwargs.pop('label', _(u'Selection'))
|
||||
label = kwargs.pop('label', _('Selection'))
|
||||
super(ChoiceForm, self).__init__(*args, **kwargs)
|
||||
self.fields['selection'].choices = choices
|
||||
self.fields['selection'].label = label
|
||||
@@ -140,15 +140,15 @@ class EmailAuthenticationForm(forms.Form):
|
||||
"""
|
||||
A form to use email address authentication
|
||||
"""
|
||||
email = forms.CharField(label=_(u'Email'), max_length=254,
|
||||
email = forms.CharField(label=_('Email'), max_length=254,
|
||||
widget=EmailInput()
|
||||
)
|
||||
password = forms.CharField(label=_(u'Password'), widget=forms.PasswordInput)
|
||||
password = forms.CharField(label=_('Password'), widget=forms.PasswordInput)
|
||||
|
||||
error_messages = {
|
||||
'invalid_login': _(u'Please enter a correct email and password. '
|
||||
u'Note that the password field is case-sensitive.'),
|
||||
'inactive': _(u'This account is inactive.'),
|
||||
'invalid_login': _('Please enter a correct email and password. '
|
||||
'Note that the password field is case-sensitive.'),
|
||||
'inactive': _('This account is inactive.'),
|
||||
}
|
||||
|
||||
def __init__(self, request=None, *args, **kwargs):
|
||||
@@ -193,7 +193,7 @@ class EmailAuthenticationForm(forms.Form):
|
||||
|
||||
class FileDisplayForm(forms.Form):
|
||||
text = forms.CharField(
|
||||
label='', # _(u'Text'),
|
||||
label='', # _('Text'),
|
||||
widget=forms.widgets.Textarea(
|
||||
attrs={'cols': 40, 'rows': 20, 'readonly': 'readonly'}
|
||||
)
|
||||
@@ -208,5 +208,5 @@ class FileDisplayForm(forms.Form):
|
||||
|
||||
|
||||
class LicenseForm(FileDisplayForm):
|
||||
FILENAME = u'LICENSE'
|
||||
FILENAME = 'LICENSE'
|
||||
DIRECTORY = []
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
from __future__ import absolute_import
|
||||
from __future__ import unicode_literals
|
||||
|
||||
from django.utils.translation import ugettext_lazy as _
|
||||
|
||||
@@ -7,14 +7,14 @@ def has_usable_password(context):
|
||||
return context['request'].user.has_usable_password
|
||||
|
||||
|
||||
link_password_change = {'text': _(u'Change password'), 'view': 'common:password_change_view', 'famfam': 'computer_key', 'condition': has_usable_password}
|
||||
link_current_user_details = {'text': _(u'User details'), 'view': 'common:current_user_details', 'famfam': 'vcard'}
|
||||
link_current_user_edit = {'text': _(u'Edit details'), 'view': 'common:current_user_edit', 'famfam': 'vcard_edit'}
|
||||
link_password_change = {'text': _('Change password'), 'view': 'common:password_change_view', 'famfam': 'computer_key', 'condition': has_usable_password}
|
||||
link_current_user_details = {'text': _('User details'), 'view': 'common:current_user_details', 'famfam': 'vcard'}
|
||||
link_current_user_edit = {'text': _('Edit details'), 'view': 'common:current_user_edit', 'famfam': 'vcard_edit'}
|
||||
|
||||
link_about = {'text': _(u'About'), 'view': 'common:about_view', 'famfam': 'information'}
|
||||
link_license = {'text': _(u'License'), 'view': 'common:license_view', 'famfam': 'script'}
|
||||
link_about = {'text': _('About'), 'view': 'common:about_view', 'famfam': 'information'}
|
||||
link_license = {'text': _('License'), 'view': 'common:license_view', 'famfam': 'script'}
|
||||
|
||||
link_current_user_locale_profile_details = {'text': _(u'Locale profile'), 'view': 'common:current_user_locale_profile_details', 'famfam': 'world'}
|
||||
link_current_user_locale_profile_edit = {'text': _(u'Edit locale profile'), 'view': 'common:current_user_locale_profile_edit', 'famfam': 'world_edit'}
|
||||
link_current_user_locale_profile_details = {'text': _('Locale profile'), 'view': 'common:current_user_locale_profile_details', 'famfam': 'world'}
|
||||
link_current_user_locale_profile_edit = {'text': _('Edit locale profile'), 'view': 'common:current_user_locale_profile_edit', 'famfam': 'world_edit'}
|
||||
|
||||
link_logout = {'text': _(u'Logout'), 'view': 'common:logout_view', 'famfam': 'door_out'}
|
||||
link_logout = {'text': _('Logout'), 'view': 'common:logout_view', 'famfam': 'door_out'}
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
from __future__ import unicode_literals
|
||||
|
||||
from django.db import models
|
||||
from django.contrib.auth.models import AnonymousUser
|
||||
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
from __future__ import absolute_import
|
||||
from __future__ import unicode_literals
|
||||
|
||||
import re
|
||||
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
from __future__ import unicode_literals
|
||||
|
||||
from django.utils.html import strip_spaces_between_tags
|
||||
|
||||
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
from __future__ import unicode_literals
|
||||
|
||||
import pytz
|
||||
|
||||
from django.utils import timezone
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
from __future__ import absolute_import
|
||||
from __future__ import unicode_literals
|
||||
|
||||
from pytz import common_timezones
|
||||
|
||||
@@ -18,7 +18,7 @@ SHARED_UPLOADED_FILE_PATH = 'shared_uploads'
|
||||
|
||||
def upload_to(instance, filename):
|
||||
instance.filename = filename
|
||||
return u'/'.join([SHARED_UPLOADED_FILE_PATH, filename])
|
||||
return '/'.join([SHARED_UPLOADED_FILE_PATH, filename])
|
||||
|
||||
|
||||
class AnonymousUserSingleton(SingletonModel):
|
||||
@@ -28,26 +28,26 @@ class AnonymousUserSingleton(SingletonModel):
|
||||
return ugettext('Anonymous user')
|
||||
|
||||
class Meta:
|
||||
verbose_name = verbose_name_plural = _(u'Anonymous user')
|
||||
verbose_name = verbose_name_plural = _('Anonymous user')
|
||||
|
||||
|
||||
class AutoAdminSingleton(SingletonModel):
|
||||
account = models.ForeignKey(User, null=True, blank=True, related_name='auto_admin_account', verbose_name=_(u'Account'))
|
||||
password = models.CharField(null=True, blank=True, verbose_name=_(u'Password'), max_length=128)
|
||||
password_hash = models.CharField(null=True, blank=True, verbose_name=_(u'Password hash'), max_length=128)
|
||||
account = models.ForeignKey(User, null=True, blank=True, related_name='auto_admin_account', verbose_name=_('Account'))
|
||||
password = models.CharField(null=True, blank=True, verbose_name=_('Password'), max_length=128)
|
||||
password_hash = models.CharField(null=True, blank=True, verbose_name=_('Password hash'), max_length=128)
|
||||
|
||||
class Meta:
|
||||
verbose_name = verbose_name_plural = _(u'Auto admin properties')
|
||||
verbose_name = verbose_name_plural = _('Auto admin properties')
|
||||
|
||||
|
||||
class SharedUploadedFile(models.Model):
|
||||
file = models.FileField(upload_to=upload_to, storage=shared_storage_backend, verbose_name=_(u'File'))
|
||||
file = models.FileField(upload_to=upload_to, storage=shared_storage_backend, verbose_name=_('File'))
|
||||
filename = models.CharField(max_length=255, verbose_name=_('Filename'))
|
||||
datatime = models.DateTimeField(auto_now_add=True, verbose_name=_('Date time'))
|
||||
|
||||
class Meta:
|
||||
verbose_name = _(u'Shared uploaded file')
|
||||
verbose_name_plural = _(u'Shared uploaded files')
|
||||
verbose_name = _('Shared uploaded file')
|
||||
verbose_name_plural = _('Shared uploaded files')
|
||||
|
||||
def __unicode__(self):
|
||||
return self.filename
|
||||
@@ -67,5 +67,5 @@ class UserLocaleProfile(models.Model):
|
||||
return unicode(self.user)
|
||||
|
||||
class Meta:
|
||||
verbose_name = _(u'User locale profile')
|
||||
verbose_name_plural = _(u'User locale profiles')
|
||||
verbose_name = _('User locale profile')
|
||||
verbose_name_plural = _('User locale profiles')
|
||||
|
||||
@@ -1,5 +1,3 @@
|
||||
from __future__ import absolute_import
|
||||
|
||||
from common.utils import load_backend
|
||||
|
||||
from .settings import SHARED_STORAGE
|
||||
|
||||
@@ -1,67 +1,67 @@
|
||||
"""Configuration options for the common app"""
|
||||
from __future__ import unicode_literals
|
||||
|
||||
from django.utils.translation import ugettext_lazy as _
|
||||
from django.contrib.auth.models import User
|
||||
from django.utils.translation import ugettext_lazy as _
|
||||
|
||||
from smart_settings.api import register_setting
|
||||
|
||||
TEMPORARY_DIRECTORY = register_setting(
|
||||
namespace=u'common',
|
||||
module=u'common.settings',
|
||||
name=u'TEMPORARY_DIRECTORY',
|
||||
global_name=u'COMMON_TEMPORARY_DIRECTORY',
|
||||
default=u'/tmp',
|
||||
description=_(u'Temporary directory used site wide to store thumbnails, previews and temporary files. If none is specified, one will be created using tempfile.mkdtemp()'),
|
||||
namespace='common',
|
||||
module='common.settings',
|
||||
name='TEMPORARY_DIRECTORY',
|
||||
global_name='COMMON_TEMPORARY_DIRECTORY',
|
||||
default='/tmp',
|
||||
description=_('Temporary directory used site wide to store thumbnails, previews and temporary files. If none is specified, one will be created using tempfile.mkdtemp()'),
|
||||
exists=True
|
||||
)
|
||||
|
||||
register_setting(
|
||||
namespace=u'common',
|
||||
module=u'common.settings',
|
||||
name=u'AUTO_CREATE_ADMIN',
|
||||
global_name=u'COMMON_AUTO_CREATE_ADMIN',
|
||||
namespace='common',
|
||||
module='common.settings',
|
||||
name='AUTO_CREATE_ADMIN',
|
||||
global_name='COMMON_AUTO_CREATE_ADMIN',
|
||||
default=True,
|
||||
)
|
||||
|
||||
register_setting(
|
||||
namespace=u'common',
|
||||
module=u'common.settings',
|
||||
name=u'AUTO_ADMIN_USERNAME',
|
||||
global_name=u'COMMON_AUTO_ADMIN_USERNAME',
|
||||
default=u'admin',
|
||||
namespace='common',
|
||||
module='common.settings',
|
||||
name='AUTO_ADMIN_USERNAME',
|
||||
global_name='COMMON_AUTO_ADMIN_USERNAME',
|
||||
default='admin',
|
||||
)
|
||||
|
||||
register_setting(
|
||||
namespace=u'common',
|
||||
module=u'common.settings',
|
||||
name=u'AUTO_ADMIN_PASSWORD',
|
||||
global_name=u'COMMON_AUTO_ADMIN_PASSWORD',
|
||||
namespace='common',
|
||||
module='common.settings',
|
||||
name='AUTO_ADMIN_PASSWORD',
|
||||
global_name='COMMON_AUTO_ADMIN_PASSWORD',
|
||||
default=User.objects.make_random_password(),
|
||||
)
|
||||
|
||||
register_setting(
|
||||
namespace=u'common',
|
||||
module=u'common.settings',
|
||||
name=u'LOGIN_METHOD',
|
||||
global_name=u'COMMON_LOGIN_METHOD',
|
||||
default=u'username',
|
||||
description=_(u'Controls the mechanism used to authenticated user. Options are: username, email'),
|
||||
namespace='common',
|
||||
module='common.settings',
|
||||
name='LOGIN_METHOD',
|
||||
global_name='COMMON_LOGIN_METHOD',
|
||||
default='username',
|
||||
description=_('Controls the mechanism used to authenticated user. Options are: username, email'),
|
||||
)
|
||||
|
||||
register_setting(
|
||||
namespace=u'common',
|
||||
module=u'common.settings',
|
||||
name=u'ALLOW_ANONYMOUS_ACCESS',
|
||||
global_name=u'COMMON_ALLOW_ANONYMOUS_ACCESS',
|
||||
namespace='common',
|
||||
module='common.settings',
|
||||
name='ALLOW_ANONYMOUS_ACCESS',
|
||||
global_name='COMMON_ALLOW_ANONYMOUS_ACCESS',
|
||||
default=False,
|
||||
description=_(u'Allow non authenticated users, access to all views'),
|
||||
description=_('Allow non authenticated users, access to all views'),
|
||||
)
|
||||
|
||||
register_setting(
|
||||
namespace=u'common',
|
||||
module=u'common.settings',
|
||||
name=u'SHARED_STORAGE',
|
||||
global_name=u'COMMON_SHARED_STORAGE',
|
||||
namespace='common',
|
||||
module='common.settings',
|
||||
name='SHARED_STORAGE',
|
||||
global_name='COMMON_SHARED_STORAGE',
|
||||
default='storage.backends.filebasedstorage.FileBasedStorage',
|
||||
description=_(u'A storage backend that all workers can use to share files.'),
|
||||
description=_('A storage backend that all workers can use to share files.'),
|
||||
)
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
from __future__ import unicode_literals
|
||||
|
||||
from django.template import Library
|
||||
|
||||
from common.models import AutoAdminSingleton
|
||||
@@ -8,4 +10,4 @@ register = Library()
|
||||
@register.simple_tag(takes_context=True)
|
||||
def auto_admin_properties(context):
|
||||
context['auto_admin_properties'] = AutoAdminSingleton.objects.get()
|
||||
return u''
|
||||
return ''
|
||||
|
||||
@@ -1,5 +1,3 @@
|
||||
from __future__ import absolute_import
|
||||
|
||||
from json import dumps
|
||||
from django.template import Library
|
||||
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
from __future__ import unicode_literals
|
||||
|
||||
from django.template import Library
|
||||
|
||||
register = Library()
|
||||
@@ -5,4 +7,4 @@ register = Library()
|
||||
|
||||
@register.filter
|
||||
def make_non_breakable(value):
|
||||
return value.replace(u'-', u'\u2011')
|
||||
return value.replace('-', '\u2011')
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
from django.template import Library
|
||||
from django.conf import settings
|
||||
from django.template import Library
|
||||
|
||||
register = Library()
|
||||
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
from __future__ import unicode_literals
|
||||
|
||||
from django import template
|
||||
|
||||
register = template.Library()
|
||||
@@ -16,7 +18,7 @@ class SetVarNode(template.Node):
|
||||
# Make it global across all blocks
|
||||
context.dicts[0][self.var_name] = value
|
||||
|
||||
return u""
|
||||
return ''
|
||||
|
||||
|
||||
def set_var(parser, token):
|
||||
|
||||
@@ -1,8 +1,9 @@
|
||||
from __future__ import unicode_literals
|
||||
|
||||
import re
|
||||
|
||||
from django.template import Node
|
||||
from django.template import TemplateSyntaxError, Library
|
||||
from django.conf import settings
|
||||
from django.template import Library, Node, TemplateSyntaxError
|
||||
|
||||
register = Library()
|
||||
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
from __future__ import unicode_literals
|
||||
|
||||
import re
|
||||
|
||||
from django.template import (Context, Library, Node, TemplateSyntaxError,
|
||||
|
||||
@@ -14,7 +14,7 @@ class CopyNode(Node):
|
||||
def render(self, context):
|
||||
context[Variable(self.var_name).resolve(context)] = Variable(self.source_variable).resolve(context)
|
||||
if self.delete_old:
|
||||
context[Variable(self.source_variable).resolve(context)] = u''
|
||||
context[Variable(self.source_variable).resolve(context)] = ''
|
||||
return ''
|
||||
|
||||
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
from __future__ import unicode_literals
|
||||
|
||||
from django.template import Library
|
||||
from django.utils.importlib import import_module
|
||||
|
||||
@@ -10,4 +12,4 @@ def app_version(app_name):
|
||||
app = import_module(app_name)
|
||||
return app.__version__
|
||||
except ImportError:
|
||||
return u''
|
||||
return ''
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
from __future__ import unicode_literals
|
||||
|
||||
from django.conf import settings
|
||||
from django.conf.urls import patterns, url
|
||||
from django.views.generic import RedirectView, TemplateView
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
from __future__ import absolute_import
|
||||
from __future__ import unicode_literals
|
||||
|
||||
import logging
|
||||
import os
|
||||
@@ -19,7 +19,7 @@ logger = logging.getLogger(__name__)
|
||||
|
||||
|
||||
def urlquote(link=None, get=None):
|
||||
u"""
|
||||
"""
|
||||
This method does both: urlquote() and urlencode()
|
||||
|
||||
urlqoute(): Quote special characters in 'link'
|
||||
@@ -44,7 +44,7 @@ def urlquote(link=None, get=None):
|
||||
assert not get, get
|
||||
get = link
|
||||
link = ''
|
||||
assert isinstance(get, dict), u'wrong type "%s", dict required' % type(get)
|
||||
assert isinstance(get, dict), 'wrong type "%s", dict required' % type(get)
|
||||
# assert not (link.startswith('http://') or link.startswith('https://')), \
|
||||
# 'This method should only quote the url path.
|
||||
# It should not start with http(s):// (%s)' % (
|
||||
@@ -54,8 +54,8 @@ def urlquote(link=None, get=None):
|
||||
if isinstance(get, MultiValueDict):
|
||||
get = get.lists()
|
||||
if link:
|
||||
link = u'%s?' % django_urlquote(link)
|
||||
return u'%s%s' % (link, django_urlencode(get, doseq=True))
|
||||
link = '%s?' % django_urlquote(link)
|
||||
return '%s%s' % (link, django_urlencode(get, doseq=True))
|
||||
else:
|
||||
return django_urlquote(link)
|
||||
|
||||
@@ -67,7 +67,7 @@ def return_attrib(obj, attrib, arguments=None):
|
||||
elif isinstance(obj, types.DictType) or isinstance(obj, types.DictionaryType):
|
||||
return obj[attrib]
|
||||
else:
|
||||
result = reduce(getattr, attrib.split(u'.'), obj)
|
||||
result = reduce(getattr, attrib.split('.'), obj)
|
||||
if isinstance(result, types.MethodType):
|
||||
if arguments:
|
||||
return result(**arguments)
|
||||
@@ -86,8 +86,8 @@ def return_attrib(obj, attrib, arguments=None):
|
||||
# http://snippets.dzone.com/user/jakob
|
||||
def pretty_size(size, suffixes=None):
|
||||
suffixes = suffixes or [
|
||||
(u'B', 1024L), (u'K', 1048576L), (u'M', 1073741824L),
|
||||
(u'G', 1099511627776L), (u'T', 1125899906842624L)
|
||||
('B', 1024L), ('K', 1048576L), ('M', 1073741824L),
|
||||
('G', 1099511627776L), ('T', 1125899906842624L)
|
||||
]
|
||||
|
||||
for suf, lim in suffixes:
|
||||
@@ -104,20 +104,20 @@ def pretty_size_10(size):
|
||||
return pretty_size(
|
||||
size,
|
||||
suffixes=[
|
||||
(u'B', 1000L), (u'K', 1000000L), (u'M', 1000000000L),
|
||||
(u'G', 1000000000000L), (u'T', 1000000000000000L)
|
||||
('B', 1000L), ('K', 1000000L), ('M', 1000000000L),
|
||||
('G', 1000000000000L), ('T', 1000000000000000L)
|
||||
])
|
||||
|
||||
|
||||
def return_type(value):
|
||||
if isinstance(value, types.FunctionType):
|
||||
return value.__doc__ if value.__doc__ else _(u'Function found')
|
||||
return value.__doc__ if value.__doc__ else _('Function found')
|
||||
elif isinstance(value, types.ClassType):
|
||||
return u'%s.%s' % (value.__class__.__module__, value.__class__.__name__)
|
||||
return '%s.%s' % (value.__class__.__module__, value.__class__.__name__)
|
||||
elif isinstance(value, types.TypeType):
|
||||
return u'%s.%s' % (value.__module__, value.__name__)
|
||||
return '%s.%s' % (value.__module__, value.__name__)
|
||||
elif isinstance(value, types.DictType) or isinstance(value, types.DictionaryType):
|
||||
return u', '.join(list(value))
|
||||
return ', '.join(list(value))
|
||||
else:
|
||||
return value
|
||||
|
||||
@@ -125,8 +125,8 @@ def return_type(value):
|
||||
# http://stackoverflow.com/questions/4248399/page-range-for-printing-algorithm
|
||||
def parse_range(astr):
|
||||
result = set()
|
||||
for part in astr.split(u','):
|
||||
x = part.split(u'-')
|
||||
for part in astr.split(','):
|
||||
x = part.split('-')
|
||||
result.update(range(int(x[0]), int(x[-1]) + 1))
|
||||
return sorted(result)
|
||||
|
||||
@@ -140,10 +140,10 @@ def generate_choices_w_labels(choices, display_object_type=True):
|
||||
label = choice.get_full_name() if choice.get_full_name() else choice
|
||||
|
||||
if display_object_type:
|
||||
verbose_name = unicode(getattr(choice._meta, u'verbose_name', ct.name))
|
||||
results.append((u'%s,%s' % (ct.model, choice.pk), u'%s: %s' % (verbose_name, label)))
|
||||
verbose_name = unicode(getattr(choice._meta, 'verbose_name', ct.name))
|
||||
results.append(('%s,%s' % (ct.model, choice.pk), '%s: %s' % (verbose_name, label)))
|
||||
else:
|
||||
results.append((u'%s,%s' % (ct.model, choice.pk), u'%s' % (label)))
|
||||
results.append(('%s,%s' % (ct.model, choice.pk), '%s' % (label)))
|
||||
|
||||
# Sort results by the label not the key value
|
||||
return sorted(results, key=lambda x: x[1])
|
||||
@@ -162,9 +162,9 @@ def get_object_name(obj, display_object_type=True):
|
||||
except AttributeError:
|
||||
verbose_name = ct_label
|
||||
|
||||
return u'%s: %s' % (verbose_name, label)
|
||||
return '%s: %s' % (verbose_name, label)
|
||||
else:
|
||||
return u'%s' % (label)
|
||||
return '%s' % (label)
|
||||
|
||||
|
||||
def validate_path(path):
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
from __future__ import absolute_import
|
||||
from __future__ import absolute_import, unicode_literals
|
||||
|
||||
from json import dumps, loads
|
||||
|
||||
@@ -39,15 +39,15 @@ def multi_object_action_view(request):
|
||||
next = request.POST.get('next', request.GET.get('next', request.META.get('HTTP_REFERER', reverse('main:home'))))
|
||||
|
||||
action = request.GET.get('action', None)
|
||||
id_list = u','.join([key[3:] for key in request.GET.keys() if key.startswith('pk_')])
|
||||
id_list = ','.join([key[3:] for key in request.GET.keys() if key.startswith('pk_')])
|
||||
items_property_list = [loads(key[11:]) for key in request.GET.keys() if key.startswith('properties_')]
|
||||
|
||||
if not action:
|
||||
messages.error(request, _(u'No action selected.'))
|
||||
messages.error(request, _('No action selected.'))
|
||||
return HttpResponseRedirect(request.META.get('HTTP_REFERER', reverse('main:home')))
|
||||
|
||||
if not id_list and not items_property_list:
|
||||
messages.error(request, _(u'Must select at least one item.'))
|
||||
messages.error(request, _('Must select at least one item.'))
|
||||
return HttpResponseRedirect(request.META.get('HTTP_REFERER', reverse('main:home')))
|
||||
|
||||
# Separate redirects to keep backwards compatibility with older
|
||||
@@ -65,17 +65,17 @@ def multi_object_action_view(request):
|
||||
|
||||
|
||||
def get_obj_from_content_type_string(string):
|
||||
model, pk = string.split(u',')
|
||||
model, pk = string.split(',')
|
||||
ct = ContentType.objects.get(model=model)
|
||||
return ct.get_object_for_this_type(pk=pk)
|
||||
|
||||
|
||||
def assign_remove(request, left_list, right_list, add_method, remove_method, left_list_title=None, right_list_title=None, decode_content_type=False, extra_context=None, grouped=False):
|
||||
left_list_name = u'left_list'
|
||||
right_list_name = u'right_list'
|
||||
left_list_name = 'left_list'
|
||||
right_list_name = 'right_list'
|
||||
|
||||
if request.method == 'POST':
|
||||
if u'%s-submit' % left_list_name in request.POST.keys():
|
||||
if '%s-submit' % left_list_name in request.POST.keys():
|
||||
unselected_list = ChoiceForm(request.POST,
|
||||
prefix=left_list_name,
|
||||
choices=left_list())
|
||||
@@ -99,10 +99,10 @@ def assign_remove(request, left_list, right_list, add_method, remove_method, lef
|
||||
if settings.DEBUG:
|
||||
raise
|
||||
else:
|
||||
messages.error(request, _(u'Unable to remove %(selection)s.') % {
|
||||
messages.error(request, _('Unable to remove %(selection)s.') % {
|
||||
'selection': label, 'right_list_title': right_list_title})
|
||||
|
||||
elif u'%s-submit' % right_list_name in request.POST.keys():
|
||||
elif '%s-submit' % right_list_name in request.POST.keys():
|
||||
selected_list = ChoiceForm(request.POST,
|
||||
prefix=right_list_name,
|
||||
choices=right_list())
|
||||
@@ -124,7 +124,7 @@ def assign_remove(request, left_list, right_list, add_method, remove_method, lef
|
||||
if settings.DEBUG:
|
||||
raise
|
||||
else:
|
||||
messages.error(request, _(u'Unable to add %(selection)s.') % {
|
||||
messages.error(request, _('Unable to add %(selection)s.') % {
|
||||
'selection': label, 'right_list_title': right_list_title})
|
||||
unselected_list = ChoiceForm(prefix=left_list_name, choices=left_list())
|
||||
selected_list = ChoiceForm(prefix=right_list_name, choices=right_list())
|
||||
@@ -137,7 +137,7 @@ def assign_remove(request, left_list, right_list, add_method, remove_method, lef
|
||||
'context': {
|
||||
'form': unselected_list,
|
||||
'title': left_list_title or ' ',
|
||||
'submit_label': _(u'Add'),
|
||||
'submit_label': _('Add'),
|
||||
'submit_icon_famfam': 'add'
|
||||
}
|
||||
},
|
||||
@@ -148,7 +148,7 @@ def assign_remove(request, left_list, right_list, add_method, remove_method, lef
|
||||
'context': {
|
||||
'form': selected_list,
|
||||
'title': right_list_title or ' ',
|
||||
'submit_label': _(u'Remove'),
|
||||
'submit_label': _('Remove'),
|
||||
'submit_icon_famfam': 'delete'
|
||||
}
|
||||
},
|
||||
@@ -171,7 +171,7 @@ def current_user_details(request):
|
||||
return render_to_response(
|
||||
'main/generic_form.html', {
|
||||
'form': form,
|
||||
'title': _(u'Current user details'),
|
||||
'title': _('Current user details'),
|
||||
'read_only': True,
|
||||
},
|
||||
context_instance=RequestContext(request))
|
||||
@@ -186,7 +186,7 @@ def current_user_locale_profile_details(request):
|
||||
return render_to_response(
|
||||
'main/generic_form.html', {
|
||||
'form': form,
|
||||
'title': _(u'Current user locale profile details'),
|
||||
'title': _('Current user locale profile details'),
|
||||
'read_only': True,
|
||||
},
|
||||
context_instance=RequestContext(request))
|
||||
@@ -203,10 +203,10 @@ def current_user_edit(request):
|
||||
form = UserForm(instance=request.user, data=request.POST)
|
||||
if form.is_valid():
|
||||
if User.objects.filter(email=form.cleaned_data['email']).exclude(pk=request.user.pk).count():
|
||||
messages.error(request, _(u'E-mail conflict, another user has that same email.'))
|
||||
messages.error(request, _('E-mail conflict, another user has that same email.'))
|
||||
else:
|
||||
form.save()
|
||||
messages.success(request, _(u'Current user\'s details updated.'))
|
||||
messages.success(request, _('Current user\'s details updated.'))
|
||||
return HttpResponseRedirect(next)
|
||||
else:
|
||||
form = UserForm(instance=request.user)
|
||||
@@ -215,7 +215,7 @@ def current_user_edit(request):
|
||||
'main/generic_form.html', {
|
||||
'form': form,
|
||||
'next': next,
|
||||
'title': _(u'Edit current user details'),
|
||||
'title': _('Edit current user details'),
|
||||
},
|
||||
context_instance=RequestContext(request))
|
||||
|
||||
@@ -238,7 +238,7 @@ def current_user_locale_profile_edit(request):
|
||||
else:
|
||||
request.set_cookie(settings.LANGUAGE_COOKIE_NAME, form.cleaned_data['language'])
|
||||
|
||||
messages.success(request, _(u'Current user\'s locale profile details updated.'))
|
||||
messages.success(request, _('Current user\'s locale profile details updated.'))
|
||||
return HttpResponseRedirect(next)
|
||||
else:
|
||||
form = LocaleProfileForm(instance=request.user.locale_profile)
|
||||
@@ -247,7 +247,7 @@ def current_user_locale_profile_edit(request):
|
||||
'main/generic_form.html', {
|
||||
'form': form,
|
||||
'next': next,
|
||||
'title': _(u'Edit current user locale profile details'),
|
||||
'title': _('Edit current user locale profile details'),
|
||||
},
|
||||
context_instance=RequestContext(request))
|
||||
|
||||
@@ -278,7 +278,7 @@ def license_view(request):
|
||||
return render_to_response(
|
||||
'main/generic_detail.html', {
|
||||
'form': form,
|
||||
'title': _(u'License'),
|
||||
'title': _('License'),
|
||||
},
|
||||
context_instance=RequestContext(request))
|
||||
|
||||
@@ -287,7 +287,7 @@ def password_change_view(request):
|
||||
"""
|
||||
Password change wrapper for better control
|
||||
"""
|
||||
context = {'title': _(u'Current user password change')}
|
||||
context = {'title': _('Current user password change')}
|
||||
|
||||
return password_change(
|
||||
request,
|
||||
@@ -302,7 +302,7 @@ 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.'))
|
||||
messages.success(request, _('Your password has been successfully changed.'))
|
||||
return redirect('common:current_user_details')
|
||||
|
||||
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
from __future__ import unicode_literals
|
||||
|
||||
from itertools import chain
|
||||
import os
|
||||
|
||||
@@ -15,7 +17,7 @@ class PlainWidget(forms.widgets.Widget):
|
||||
widget and reduces the output to only it's value
|
||||
"""
|
||||
def render(self, name, value, attrs=None):
|
||||
return mark_safe(u'%s' % value)
|
||||
return mark_safe('%s' % value)
|
||||
|
||||
|
||||
class DetailSelectMultiple(forms.widgets.SelectMultiple):
|
||||
@@ -28,7 +30,7 @@ class DetailSelectMultiple(forms.widgets.SelectMultiple):
|
||||
value = ''
|
||||
final_attrs = self.build_attrs(attrs, name=name)
|
||||
css_class = final_attrs.get('class', 'list')
|
||||
output = u'<ul class="%s">' % css_class
|
||||
output = '<ul class="%s">' % css_class
|
||||
options = None
|
||||
if value:
|
||||
if getattr(value, '__iter__', None):
|
||||
@@ -39,7 +41,7 @@ class DetailSelectMultiple(forms.widgets.SelectMultiple):
|
||||
self.choices if index == value]
|
||||
else:
|
||||
if self.choices:
|
||||
if self.choices[0] != (u'', u'---------') and value != []:
|
||||
if self.choices[0] != ('', '---------') and value != []:
|
||||
options = [(index, string) for index, string in
|
||||
self.choices]
|
||||
|
||||
@@ -47,16 +49,16 @@ class DetailSelectMultiple(forms.widgets.SelectMultiple):
|
||||
for index, string in options:
|
||||
if self.queryset:
|
||||
try:
|
||||
output += u'<li><a href="%s">%s</a></li>' % (
|
||||
output += '<li><a href="%s">%s</a></li>' % (
|
||||
self.queryset.get(pk=index).get_absolute_url(),
|
||||
string)
|
||||
except AttributeError:
|
||||
output += u'<li>%s</li>' % (string)
|
||||
output += '<li>%s</li>' % (string)
|
||||
else:
|
||||
output += u'<li>%s</li>' % string
|
||||
output += '<li>%s</li>' % string
|
||||
else:
|
||||
output += u'<li>%s</li>' % _(u'None')
|
||||
return mark_safe(output + u'</ul>\n')
|
||||
output += '<li>%s</li>' % _('None')
|
||||
return mark_safe(output + '</ul>\n')
|
||||
|
||||
|
||||
def exists_with_famfam(path):
|
||||
@@ -66,11 +68,11 @@ def exists_with_famfam(path):
|
||||
return exception
|
||||
|
||||
|
||||
def two_state_template(state, famfam_ok_icon=u'tick', famfam_fail_icon=u'cross'):
|
||||
def two_state_template(state, famfam_ok_icon='tick', famfam_fail_icon='cross'):
|
||||
if state:
|
||||
return mark_safe(u'<span class="famfam active famfam-%s"></span>' % famfam_ok_icon)
|
||||
return mark_safe('<span class="famfam active famfam-%s"></span>' % famfam_ok_icon)
|
||||
else:
|
||||
return mark_safe(u'<span class="famfam active famfam-%s"></span>' % famfam_fail_icon)
|
||||
return mark_safe('<span class="famfam active famfam-%s"></span>' % famfam_fail_icon)
|
||||
|
||||
|
||||
class TextAreaDiv(forms.widgets.Widget):
|
||||
@@ -88,11 +90,11 @@ class TextAreaDiv(forms.widgets.Widget):
|
||||
|
||||
def render(self, name, value, attrs=None):
|
||||
if value is None:
|
||||
value = u''
|
||||
value = ''
|
||||
|
||||
flat_attrs = flatatt(self.build_attrs(attrs, name=name))
|
||||
content = conditional_escape(force_unicode(value))
|
||||
result = u'<pre%s>%s</pre>' % (flat_attrs, content)
|
||||
result = '<pre%s>%s</pre>' % (flat_attrs, content)
|
||||
return mark_safe(result)
|
||||
|
||||
|
||||
@@ -124,7 +126,7 @@ class ScrollableCheckboxSelectMultiple(forms.widgets.CheckboxSelectMultiple):
|
||||
value = []
|
||||
has_id = attrs and 'id' in attrs
|
||||
final_attrs = self.build_attrs(attrs, name=name)
|
||||
output = [u'<ul class="undecorated_list" style="margin-left: 5px; margin-top: 3px; margin-bottom: 3px;">']
|
||||
output = ['<ul class="undecorated_list" style="margin-left: 5px; margin-top: 3px; margin-bottom: 3px;">']
|
||||
# Normalize to strings
|
||||
str_values = set([force_unicode(v) for v in value])
|
||||
for i, (option_value, option_label) in enumerate(chain(self.choices, choices)):
|
||||
@@ -132,7 +134,7 @@ class ScrollableCheckboxSelectMultiple(forms.widgets.CheckboxSelectMultiple):
|
||||
# so that the checkboxes don't all have the same ID attribute.
|
||||
if has_id:
|
||||
final_attrs = dict(final_attrs, id='%s_%s' % (attrs['id'], i))
|
||||
label_for = u' for="%s"' % final_attrs['id']
|
||||
label_for = ' for="%s"' % final_attrs['id']
|
||||
else:
|
||||
label_for = ''
|
||||
|
||||
@@ -140,7 +142,7 @@ class ScrollableCheckboxSelectMultiple(forms.widgets.CheckboxSelectMultiple):
|
||||
option_value = force_unicode(option_value)
|
||||
rendered_cb = cb.render(name, option_value)
|
||||
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>')
|
||||
output.append('<li><label%s>%s %s</label></li>' % (label_for, rendered_cb, option_label))
|
||||
output.append('</ul>')
|
||||
|
||||
return mark_safe(u'<div class="text_area_div">%s</div>' % u'\n'.join(output))
|
||||
return mark_safe('<div class="text_area_div">%s</div>' % '\n'.join(output))
|
||||
|
||||
Reference in New Issue
Block a user