Skip to content

Commit

Permalink
Merge branch 'master' of git://github.com/django/django
Browse files Browse the repository at this point in the history
  • Loading branch information
zedr committed Feb 22, 2014
2 parents 9473565 + ede99f0 commit 3d26680
Show file tree
Hide file tree
Showing 55 changed files with 725 additions and 311 deletions.
Empty file.
52 changes: 52 additions & 0 deletions django/conf/locale/eo/formats.py
@@ -0,0 +1,52 @@
# -*- encoding: utf-8 -*-
# This file is distributed under the same license as the Django package.
#
from __future__ import unicode_literals

# The *_FORMAT strings use the Django date format syntax,
# see http://docs.djangoproject.com/en/dev/ref/templates/builtins/#date
DATE_FORMAT = r'j\-\a \d\e F Y' # '26-a de julio 1887'
TIME_FORMAT = 'H:i:s' # '18:59:00'
DATETIME_FORMAT = r'j\-\a \d\e F Y\, \j\e H:i:s' # '26-a de julio 1887, je 18:59:00'
YEAR_MONTH_FORMAT = r'F \d\e Y' # 'julio de 1887'
MONTH_DAY_FORMAT = r'j\-\a \d\e F' # '26-a de julio'
SHORT_DATE_FORMAT = 'Y-m-d' # '1887-07-26'
SHORT_DATETIME_FORMAT = 'Y-m-d H:i:s' # '1887-07-26 18:59:00'
FIRST_DAY_OF_WEEK = 1 # Monday (lundo)

# The *_INPUT_FORMATS strings use the Python strftime format syntax,
# see http://docs.python.org/library/datetime.html#strftime-strptime-behavior
DATE_INPUT_FORMATS = (
'%Y-%m-%d', # '1887-07-26'
'%y-%m-%d', # '87-07-26'
'%Y %m %d', # '1887 07 26'
'%d-a de %b %Y', # '26-a de jul 1887'
'%d %b %Y', # '26 jul 1887'
'%d-a de %B %Y', # '26-a de julio 1887'
'%d %B %Y', # '26 julio 1887'
'%d %m %Y', # '26 07 1887'
)
TIME_INPUT_FORMATS = (
'%H:%M:%S', # '18:59:00'
'%H:%M', # '18:59'
)
DATETIME_INPUT_FORMATS = (
'%Y-%m-%d %H:%M:%S', # '1887-07-26 18:59:00'
'%Y-%m-%d %H:%M', # '1887-07-26 18:59'
'%Y-%m-%d', # '1887-07-26'

'%Y.%m.%d %H:%M:%S', # '1887.07.26 18:59:00'
'%Y.%m.%d %H:%M', # '1887.07.26 18:59'
'%Y.%m.%d', # '1887.07.26'

'%d/%m/%Y %H:%M:%S', # '26/07/1887 18:59:00'
'%d/%m/%Y %H:%M', # '26/07/1887 18:59'
'%d/%m/%Y', # '26/07/1887'

'%y-%m-%d %H:%M:%S', # '87-07-26 18:59:00'
'%y-%m-%d %H:%M', # '87-07-26 18:59'
'%y-%m-%d', # '87-07-26'
)
DECIMAL_SEPARATOR = ','
THOUSAND_SEPARATOR = '\xa0' # non-breaking space
NUMBER_GROUPING = 3
2 changes: 2 additions & 0 deletions django/contrib/admin/static/admin/js/actions.js
Expand Up @@ -16,6 +16,8 @@
},
updateCounter = function() {
var sel = $(actionCheckboxes).filter(":checked").length;
// _actions_icnt is defined in the generated HTML
// and contains the total amount of objects in the queryset
$(options.counterContainer).html(interpolate(
ngettext('%(sel)s of %(cnt)s selected', '%(sel)s of %(cnt)s selected', sel), {
sel: sel,
Expand Down
2 changes: 1 addition & 1 deletion django/contrib/admin/static/admin/js/actions.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

19 changes: 11 additions & 8 deletions django/contrib/auth/__init__.py
Expand Up @@ -5,6 +5,7 @@
from django.conf import settings
from django.core.exceptions import ImproperlyConfigured, PermissionDenied
from django.utils.module_loading import import_string
from django.utils.translation import LANGUAGE_SESSION_KEY
from django.middleware.csrf import rotate_token

from .signals import user_logged_in, user_logged_out, user_login_failed
Expand Down Expand Up @@ -108,12 +109,12 @@ def logout(request):

# remember language choice saved to session
# for backwards compatibility django_language is also checked (remove in 1.8)
language = request.session.get('_language', request.session.get('django_language'))
language = request.session.get(LANGUAGE_SESSION_KEY, request.session.get('django_language'))

request.session.flush()

if language is not None:
request.session['_language'] = language
request.session[LANGUAGE_SESSION_KEY] = language

if hasattr(request, 'user'):
from django.contrib.auth.models import AnonymousUser
Expand All @@ -138,15 +139,17 @@ def get_user(request):
If no user is retrieved an instance of `AnonymousUser` is returned.
"""
from .models import AnonymousUser
user = None
try:
user_id = request.session[SESSION_KEY]
backend_path = request.session[BACKEND_SESSION_KEY]
assert backend_path in settings.AUTHENTICATION_BACKENDS
backend = load_backend(backend_path)
user = backend.get_user(user_id) or AnonymousUser()
except (KeyError, AssertionError):
user = AnonymousUser()
return user
except KeyError:
pass
else:
if backend_path in settings.AUTHENTICATION_BACKENDS:
backend = load_backend(backend_path)
user = backend.get_user(user_id)
return user or AnonymousUser()


def get_permission_codename(action, opts):
Expand Down
6 changes: 5 additions & 1 deletion django/contrib/auth/management/commands/createsuperuser.py
Expand Up @@ -50,6 +50,10 @@ def __init__(self, *args, **kwargs):
option_list = BaseCommand.option_list
help = 'Used to create a superuser.'

def execute(self, *args, **options):
self.stdin = options.get('stdin', sys.stdin) # Used for testing
return super(Command, self).execute(*args, **options)

def handle(self, *args, **options):
username = options.get(self.UserModel.USERNAME_FIELD, None)
interactive = options.get('interactive')
Expand Down Expand Up @@ -84,7 +88,7 @@ def handle(self, *args, **options):
default_username = get_default_username()
try:

if not self.stdin.isatty():
if hasattr(self.stdin, 'isatty') and not self.stdin.isatty():
raise NotRunningInTTYException("Not running in a TTY")

# Get a username
Expand Down
148 changes: 0 additions & 148 deletions django/contrib/auth/tests/test_basic.py
@@ -1,22 +1,15 @@
# -*- encoding: utf-8 -*-
from __future__ import unicode_literals

import locale

from django.apps import apps
from django.contrib.auth import get_user_model
from django.contrib.auth.management.commands import createsuperuser
from django.contrib.auth.models import User, AnonymousUser
from django.contrib.auth.tests.custom_user import CustomUser
from django.contrib.auth.tests.utils import skipIfCustomUser
from django.core.exceptions import ImproperlyConfigured
from django.core.management import call_command
from django.dispatch import receiver
from django.test import TestCase, override_settings
from django.test.signals import setting_changed
from django.utils import translation
from django.utils.encoding import force_str
from django.utils.six import binary_type, PY2, StringIO


@receiver(setting_changed)
Expand All @@ -29,46 +22,6 @@ def user_model_swapped(**kwargs):
apps.clear_cache()


def mock_inputs(inputs):
"""
Decorator to temporarily replace input/getpass to allow interactive
createsuperuser.
"""
def inner(test_func):
def wrapped(*args):
class mock_getpass:
@staticmethod
def getpass(prompt=b'Password: ', stream=None):
if PY2:
# getpass on Windows only supports prompt as bytestring (#19807)
assert isinstance(prompt, binary_type)
return inputs['password']

def mock_input(prompt):
# prompt should be encoded in Python 2. This line will raise an
# Exception if prompt contains unencoded non-ascii on Python 2.
prompt = str(prompt)
assert str('__proxy__') not in prompt
response = ''
for key, val in inputs.items():
if force_str(key) in prompt.lower():
response = val
break
return response

old_getpass = createsuperuser.getpass
old_input = createsuperuser.input
createsuperuser.getpass = mock_getpass
createsuperuser.input = mock_input
try:
test_func(*args)
finally:
createsuperuser.getpass = old_getpass
createsuperuser.input = old_input
return wrapped
return inner


@skipIfCustomUser
class BasicTestCase(TestCase):
def test_user(self):
Expand Down Expand Up @@ -127,107 +80,6 @@ def test_superuser(self):
self.assertTrue(super.is_active)
self.assertTrue(super.is_staff)

def test_createsuperuser_management_command(self):
"Check the operation of the createsuperuser management command"
# We can use the management command to create a superuser
new_io = StringIO()
call_command(
"createsuperuser",
interactive=False,
username="joe",
email="joe@somewhere.org",
stdout=new_io
)
command_output = new_io.getvalue().strip()
self.assertEqual(command_output, 'Superuser created successfully.')
u = User.objects.get(username="joe")
self.assertEqual(u.email, 'joe@somewhere.org')

# created password should be unusable
self.assertFalse(u.has_usable_password())

# We can supress output on the management command
new_io = StringIO()
call_command(
"createsuperuser",
interactive=False,
username="joe2",
email="joe2@somewhere.org",
verbosity=0,
stdout=new_io
)
command_output = new_io.getvalue().strip()
self.assertEqual(command_output, '')
u = User.objects.get(username="joe2")
self.assertEqual(u.email, 'joe2@somewhere.org')
self.assertFalse(u.has_usable_password())

call_command(
"createsuperuser",
interactive=False,
username="joe+admin@somewhere.org",
email="joe@somewhere.org",
verbosity=0
)
u = User.objects.get(username="joe+admin@somewhere.org")
self.assertEqual(u.email, 'joe@somewhere.org')
self.assertFalse(u.has_usable_password())

@mock_inputs({'password': "nopasswd"})
def test_createsuperuser_nolocale(self):
"""
Check that createsuperuser does not break when no locale is set. See
ticket #16017.
"""

old_getdefaultlocale = locale.getdefaultlocale
try:
# Temporarily remove locale information
locale.getdefaultlocale = lambda: (None, None)

# Call the command in this new environment
call_command(
"createsuperuser",
interactive=True,
username="nolocale@somewhere.org",
email="nolocale@somewhere.org",
verbosity=0
)

except TypeError:
self.fail("createsuperuser fails if the OS provides no information about the current locale")

finally:
# Re-apply locale information
locale.getdefaultlocale = old_getdefaultlocale

# If we were successful, a user should have been created
u = User.objects.get(username="nolocale@somewhere.org")
self.assertEqual(u.email, 'nolocale@somewhere.org')

@mock_inputs({
'password': "nopasswd",
'uživatel': 'foo', # username (cz)
'email': 'nolocale@somewhere.org'})
def test_createsuperuser_non_ascii_verbose_name(self):
# Aliased so the string doesn't get extracted
from django.utils.translation import ugettext_lazy as ulazy
username_field = User._meta.get_field('username')
old_verbose_name = username_field.verbose_name
username_field.verbose_name = ulazy('uživatel')
new_io = StringIO()
try:
call_command(
"createsuperuser",
interactive=True,
stdout=new_io
)
finally:
username_field.verbose_name = old_verbose_name

command_output = new_io.getvalue().strip()
self.assertEqual(command_output, 'Superuser created successfully.')

def test_get_user_model(self):
"The current user model can be retrieved"
self.assertEqual(get_user_model(), User)
Expand Down

0 comments on commit 3d26680

Please sign in to comment.