Fixed REST to get language from Accept-Language header instead of "messed-up" stuff i had done... Much easier, and works fine

This commit is contained in:
Adolfo Gómez 2014-06-03 05:16:04 +00:00
parent 376ed1f231
commit c1d26fb35e

View File

@ -54,6 +54,7 @@ class Dispatcher(View):
@method_decorator(csrf_exempt) @method_decorator(csrf_exempt)
def dispatch(self, request, **kwargs): def dispatch(self, request, **kwargs):
logger.debug('Language in dispatcher: {0}'.format(request.LANGUAGE_CODE))
import processors import processors
# Remove session, so response middelwares do nothing with this # Remove session, so response middelwares do nothing with this
@ -99,24 +100,28 @@ class Dispatcher(View):
args = path args = path
# Inspect # try:
lang = None # lang = request.LANGUAGE_CODE
if len(args) > 0: # except:
for l in settings.LANGUAGES: # lang = None
if args[-1] == l[0]:
lang = l[0] # Inspect url to see if it contains a language
activate(lang) # if len(args) > 0:
logger.error('Found lang {0}'.format(l)) # for l in settings.LANGUAGES:
args = args[:-1] # if args[-1] == l[0]:
break # lang = l[0]
# activate(lang)
# logger.error('Found lang {0}'.format(l))
# args = args[:-1]
# break
# Instantiate method handler and locate http_method dispatcher # Instantiate method handler and locate http_method dispatcher
try: try:
handler = cls(request, full_path, http_method, processor.processParameters(), *args, **kwargs) handler = cls(request, full_path, http_method, processor.processParameters(), *args, **kwargs)
# If no lang on request, try to get the one from # If no lang on request, try to get the one from
if lang is None: # if lang is None:
activate(handler.getValue('locale')) # activate(handler.getValue('locale'))
else: # else:
handler.setValue('locale', lang) # Update Locale if request had one # handler.setValue('locale', lang) # Update Locale if request had one
operation = getattr(handler, http_method) operation = getattr(handler, http_method)
except processors.ParametersException as e: except processors.ParametersException as e: