Changeset 756 in main


Ignore:
Timestamp:
02/15/12 14:59:26 (10 years ago)
Author:
pcosquer
Message:

changes how the language is determined:
when the user select a language, its choice is saved into its profile
and the language stored in the profile is the prefered language
To enable this, the 'openPLM.plmapp.middleware.locale.ProfileLocaleMiddleware?' middleware
must be enabled (after the authentication middleware) in the settings file
(the locale middleware can be removed)
this commit changes the database schema, so a ./manage.py migrate plmapp is required

Location:
trunk/openPLM
Files:
4 added
5 edited

Legend:

Unmodified
Added
Removed
  • trunk/openPLM/plmapp/models.py

    r750 r756  
    110110    #: True if user is a contributor 
    111111    is_contributor = models.BooleanField(default=False, blank=True) 
     112    #: language 
     113    language = models.CharField(max_length=5, default="en", 
     114            choices=settings.LANGUAGES) 
    112115     
    113116    @property 
  • trunk/openPLM/plmapp/views/main.py

    r744 r756  
    6464from django.utils.decorators import method_decorator 
    6565from django.forms import HiddenInput 
     66from django.views.i18n import set_language as dj_set_language 
    6667 
    6768from haystack.views import SearchView 
     
    8990    return render_to_response(template, dictionary, 
    9091                              context_instance=RequestContext(request)) 
     92 
     93 
     94def set_language(request): 
     95    """ 
     96    A wrapper arround :func:`django.views.i18n.set_language` that 
     97    stores the language in the user profile. 
     98    """ 
     99    response = dj_set_language(request) 
     100    if request.method == "POST" and request.user.is_authenticated(): 
     101        language = request.session.get('django_language') 
     102        if language: 
     103            request.user.get_profile().language = language 
     104            request.user.get_profile().save() 
     105    return response 
    91106 
    92107########################################################################################## 
  • trunk/openPLM/settings.py

    r713 r756  
    6767    'django.contrib.csrf.middleware.CsrfMiddleware', 
    6868    'django.contrib.sessions.middleware.SessionMiddleware', 
    69     'django.middleware.locale.LocaleMiddleware', 
    7069    'django.contrib.auth.middleware.AuthenticationMiddleware', 
     70    'openPLM.plmapp.middleware.locale.ProfileLocaleMiddleware', 
    7171) 
    7272 
  • trunk/openPLM/settings_tests.py

    r713 r756  
    7070    'django.middleware.common.CommonMiddleware', 
    7171    'django.contrib.sessions.middleware.SessionMiddleware', 
    72     'django.middleware.locale.LocaleMiddleware', 
    7372    'django.contrib.auth.middleware.AuthenticationMiddleware', 
     73    'openPLM.plmapp.middleware.locale.ProfileLocaleMiddleware', 
    7474) 
    7575 
  • trunk/openPLM/urls.py

    r744 r756  
    7676urlpatterns += patterns('', 
    7777    (r'^admin/', include(admin.site.urls)), 
    78     (r'^i18n/', include('django.conf.urls.i18n')), 
     78    (r'^i18n/setlang/', 'openPLM.plmapp.views.main.set_language'), 
    7979 
    8080    (r'^(?:home/)?$', display_home_page), 
Note: See TracChangeset for help on using the changeset viewer.