8000 Fixed #20034 - Ability to retrieve variables in multipart even before parsing files by tadeck · Pull Request #1148 · django/django · GitHub
[go: up one dir, main page]

Skip to content

Fixed #20034 - Ability to retrieve variables in multipart even before parsing files #1148

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 33 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
c278e56
Corrected documentation on the constructor arguments of MultiPartParser
hydrogen18 May 17, 2013
ee11d32
Reorganize committers list chronologically.
aaugustin May 18, 2013
1d3d040
Merge pull request #1082 from hydrogen18/master
mjtamlyn May 18, 2013
9012a9e
Fixed #20422 -- Applied makemessage's --ignore patterns to full path
bmispelon May 16, 2013
051cb1f
Fixed #20411 -- Don't let invalid referers blow up CSRF same origin c…
apollo13 May 18, 2013
8fd44b2
Fixed #20356 -- Prevented crash when HTTP_REFERER contains non-ascii
claudep May 18, 2013
0b07416
Fixed #20294 -- Documented context processors in TemplateResponseMixin.
zsiciarz May 18, 2013
7b85ef9
Fixed #20408 -- Clarified that values_list() doesn't return a list.
aaugustin May 18, 2013
566e284
Added test for multipart, non form-data POST.
senko May 18, 2013
029c690
#20432: Fix for GroupAdmin test
jacobb May 18, 2013
3401152
Fixed #20432 -- Test failure in admin_views.
jacobb May 18, 2013
215647c
Fixed #20386 - Introspection problem on Oracle
May 16, 2013
5e208d5
Fixed #20433: Extract catalog compilation code from javascript_catalo…
May 18, 2013
06603d1
Merge pull request #1090 from zyegfryed/ticket_20433
aaugustin May 18, 2013
4bed64c
Made test introduced in 566e284c pass on Python 3.
aaugustin May 18, 2013
be826aa
Fixed #20402: removed as-limit from uWSGI example.
aaugustin May 18, 2013
1c921cf
Fixed #20235 -- Use self.object_list if object_list not present in ge…
dracos Apr 10, 2013
756b81d
Fixed #13546 -- Easier handling of localize field options in ModelForm
mxsasha May 18, 2013
ef73a8e
Merge pull request #1083 from Markush2010/ticket20235
mjtamlyn May 18, 2013 8000
16683f2
Merge pull request #1084 from erikr/master
apollo13 May 18, 2013
90f1170
Fixed #20269 -- Adapted PostGIS template create script for CentOS/RHEL
claudep May 18, 2013
92ebb29
Fixes #19919: get_language_from_request() disregards "en-us" and "en"…
ambv May 18, 2013
1c16956
Fixed argument order for localized_fields to ensure backwards compati…
mxsasha May 18, 2013
cac7b44
Merge pull request #1100 from ambv/issue19919
aaugustin May 18, 2013
e0df647
Merge pull request #1101 from erikr/master
apollo13 May 18, 2013
89955cc
Fixed #9595 -- Allow non-expiring cache timeouts.
jacobb May 18, 2013
a0c0cc9
Merge pull request #1088 from jacobb/upstream
dstufft May 18, 2013
dc43fbc
Fixed #18998 - Prevented session crash when auth backend removed
jorgebastida May 18, 2013
710c59b
Slightly reworked imports in contrib.auth.__init__
claudep May 18, 2013
7d050e8
Merge pull request #1113 from denibertovic/master
aaugustin May 18, 2013
63a9555
Fixed #19436 -- Don't log warnings in ensure_csrf_cookie.
oliviersels May 18, 2013
5c68d02
Modified upload handler API to be able to invoke callbacks when new f…
naftulikay Mar 13, 2013
d9866da
Refactored new feature #20034, added tests, documented.
tadeck May 18, 2013
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Fixes #19919: get_language_from_request() disregards "en-us" and "en"…
… languages

when matching Accept-Language
  • Loading branch information
ambv committed May 18, 2013
commit 92ebb29c5376c1811e8607e96bddc90d24e44e2a
27 changes: 15 additions & 12 deletions django/utils/translation/trans_real.py
Original file line number Diff line number Diff line change
Expand Up @@ -364,10 +364,14 @@ def get_supported_language_variant(lang_code, supported=None):
if supported is None:
from django.conf import settings
supported = dict(settings.LANGUAGES)
if lang_code and lang_code not in supported:
lang_code = lang_code.split('-')[0] # e.g. if fr-ca is not supported fallback to fr
if lang_code and lang_code in supported and check_for_language(lang_code):
return lang_code
if lang_code:
# e.g. if fr-CA is not supported, try fr-ca;
# if that fails, fallback to fr.
variants = (lang_code, lang_code.lower(), lang_code.split('-')[0],
lang_code.lower().split('-')[0])
for code in variants:
if code in supported and check_for_language(code):
return code
raise LookupError(lang_code)

def get_language_from_path(path, supported=None):
Expand Down Expand Up @@ -438,14 +442,13 @@ def get_language_from_request(request, check_path=False):
# need to check again.
return _accepted[normalized]

for lang, dirname in ((accept_lang, normalized),
(accept_lang.split('-')[0], normalized.split('_')[0])):
if lang.lower() not in supported:
continue
for path in all_locale_paths():
if os.path.exists(os.path.join(path, dirname, 'LC_MESSAGES', 'django.mo')):
_accepted[normalized] = lang
return lang
try:
accept_lang = get_supported_language_variant(accept_lang, supported)
except LookupError:
continue
else:
_accepted[normalized] = accept_lang
return accept_lang

try:
return get_supported_language_variant(settings.LANGUAGE_CODE, supported)
Expand Down
40 changes: 39 additions & 1 deletion tests/i18n/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@
ngettext, ngettext_lazy,
ungettext, ungettext_lazy,
pgettext, pgettext_lazy,
npgettext, npgettext_lazy)
npgettext, npgettext_lazy,
check_for_language)

from .commands.tests import can_run_extraction_tests, can_run_compilation_tests
if can_run_extraction_tests:
Expand Down Expand Up @@ -1114,3 +1115,40 @@ def test_streaming_response(self):
self.assertContains(response, "Oui/Non")
response = self.client.get('/en/streaming/')
self.assertContains(response, "Yes/No")

@override_settings(
USE_I18N=True,
LANGUAGES=(
('bg', 'Bulgarian'),
('en-us', 'English'),
),
MIDDLEWARE_CLASSES=(
'django.middleware.locale.LocaleMiddleware',
'django.middleware.common.CommonMiddleware',
),
)
class CountrySpecificLanguageTests(TestCase):

urls = 'i18n.urls'

def setUp(self):
trans_real._accepted = {}
self.rf = RequestFactory()

def test_check_for_language(self):
self.assertTrue(check_for_language('en'))
self.assertTrue(check_for_language('en-us'))
self.assertTrue(check_for_language('en-US'))


def test_get_language_from_request(self):
r = self.rf.get('/')
r.COOKIES = {}
r.META = {'HTTP_ACCEPT_LANGUAGE': 'en-US,en;q=0.8,bg;q=0.6,ru;q=0.4'}
lang = get_language_from_request(r)
self.assertEqual('en-us', lang)
r = self.rf.get('/')
r.COOKIES = {}
r.META = {'HTTP_ACCEPT_LANGUAGE': 'bg-bg,en-US;q=0.8,en;q=0.6,ru;q=0.4'}
lang = get_language_from_request(r)
self.assertEqual('bg', lang)
0