|
5
|
1 |
# from django.db.models import signals |
|
|
2 |
# from django.utils.functional import curry |
|
|
3 |
|
|
|
4 |
#class TranslationMiddleware(object): |
|
|
5 |
#def process_request(self, request): |
|
|
6 |
#if hasattr(request, 'LANGUAGE_CODE'): |
|
|
7 |
#print "TranslationMiddleware: preferred lang=", request.LANGUAGE_CODE |
|
|
8 |
#update_lang = curry(self.update_lang, request.LANGUAGE_CODE) |
|
|
9 |
#signals.pre_save.connect(update_lang, dispatch_uid=request, weak=False) |
|
|
10 |
#else: |
|
|
11 |
#print "TranslationMiddleware: no lang" |
|
|
12 |
#pass |
|
|
13 |
|
|
|
14 |
|
|
|
15 |
#def update_lang(self, lang, sender, instance, **kwargs): |
|
|
16 |
#registry = registration.FieldRegistry() |
|
|
17 |
#if sender in registry: |
|
|
18 |
#for field in registry.get_fields(sender): |
|
|
19 |
#setattr(instance, field.name, lang) |
|
|
20 |
|
|
|
21 |
#def process_response(self, request, response): |
|
|
22 |
#print "response:", dir(response) |
|
|
23 |
#signals.pre_save.disconnect(dispatch_uid=request) |
|
|
24 |
#return response |