Re: Django needs for normal sequence of handlers for request processing
it's last: I don't know how to provide order of processing outside middlewares... i stopped on this: settings.py: MIDDLEWARE_CLASSES = ( 'django.middleware.common.CommonMiddleware', 'django.contrib.sessions.middleware.SessionMiddleware', 'django.contrib.auth.middleware.AuthenticationMiddleware', 'middleware.handlers.Handler', ) middleware handlers: import re from django.http import HttpResponseRedirect class Handler(object): def process_request(self, request, *args, **kwargs): self.__class__.handlers = [] def process_view(self, request, view_func, view_args, view_kwargs): if 'h_LoginRequired' in view_kwargs: res = self.LoginRequired(request, view_kwargs ['h_LoginRequired']) if res is not None: return res del view_kwargs['h_LoginRequired'] if 'h_PermissionRequired' in view_kwargs: res = self.PermissionRequired(request, view_kwargs ['h_PermissionRequired']) if res is not None: return res del view_kwargs['h_PermissionRequired'] ''' add your handlers here: def myHandler(self, request, *args, **kwargs): if all_is_okay(): return None return HttpResponseRedirect('/a_bad_result_page.html') # for example ''' def LoginRequired(self, request, *args, **kwargs): if request is not None: if request.user is not None and request.user.is_authenticated(): return None return HttpResponseRedirect('/login.html') def PermissionRequired(self, request, *args, **kwargs): # check permissions for access to '^members/account/' area return None urls.py: (r'^members/', include('members.urls'), {'h_LoginRequired':{}}), members.urls: (r'^private/', include('members.private.urls'), { 'h_PermissionRequired':{ 'handler_arg_name1':'handler_value1', 'handler_arg_name2':'handler_value2', }, 'view_arg_name1':'view_value1', 'view_arg_name2':'view_value2', } ), development process: 1. make new handler in middleware.Handler 2. add handler processing to Handler. process_view(..) 3. in urls.py create "h_HandlerName" view_param i've no idea normal handler conveyer about -- You received this message because you are subscribed to the Google Groups "Django developers" group. To post to this group, send email to django-develop...@googlegroups.com. To unsubscribe from this group, send email to django-developers+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-developers?hl=en.
Re: Django needs for normal sequence of handlers for request processing
here's my crutch (just for the idea illustrating): pre-pre-pre-alpha :) settins.py MIDDLEWARE_CLASSES = ( 'middleware.handlers.Handler', # only first. it's posthandler processor builder 'django.middleware.common.CommonMiddleware', 'django.contrib.sessions.middleware.SessionMiddleware', 'django.contrib.auth.middleware.AuthenticationMiddleware', 'middleware.handlers.HandlerProcessor', # posthandlers processor ) middleware.handlers: class HandlerProcessor(object): def process_request(self, request, *args, **kwargs): pass def process_view(self, request, view_func, view_args, view_kwargs): # pops handlers list while len(Handler.handlers) > 0: name = Handler.handlers.pop() if name in dir(Handler) and callable(getattr(Handler, name)): call = 'Handler.'+name+'(request)' try: result = eval(call) if not result == None: return result except Exception, ex: return HttpResponseRedirect('/500.html') else: return HttpResponseRedirect('/500.html') class Handler(object): def process_request(self, request, *args, **kwargs): self.__class__.handlers = [] def add_handler(self, handler): self.__class__.handlers.append(handler) def process_view(self, request, view_func, view_args, view_kwargs): # this method check ch = re.compile(r'^hnd_(.*)$') for hname in view_kwargs: hl = ch.findall(hname) if len(hl) > 0: # if you need, save view_kwargs[hname] values (it's params for this handler) self.add_handler(hl[0]) # dont forget del view_kwargs[hname] ''' add your handlers here: def myHandler(self, request, *args, **kwargs): if smth_wrong(): return HttpResponseRedirect('/a_bad_result_page.html') # for example ''' def LoginRequired(self, request, *args, **kwargs): if user is not logged in: return HttpResponseRedirect('/login.html') def PermissionRequired(self, request, *args, **kwargs): # check permissions for access to '^members/account/' area pass in urls.py (r'^members/', include('members.urls'), {'hnd_LoginRequired':{}}), in members/urls.py (r'^account/', include('members.account.urls'), { 'hnd_PermissionRequired':{ 'handler_arg_name1':'handler_value1', 'handler_arg_name2':'handler_value2', }, 'view_arg_name1':'view_value1', 'view_arg_name2':'view_value2', } ), something like this.. :) -- You received this message because you are subscribed to the Google Groups "Django developers" group. To post to this group, send email to django-develop...@googlegroups.com. To unsubscribe from this group, send email to django-developers+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-developers?hl=en.
Re: Django needs for normal sequence of handlers for request processing
megathanks to all I will try to use something like: (r'^members/', include('members.urls'), {'auth':True}) but {'auth':True} will consist of name of handler (handlers) I'll try to create 1 middleware to process this filters. All handlers will be called according by its names. Yes, this is a crutch. But maybe it will be work... -- You received this message because you are subscribed to the Google Groups "Django developers" group. To post to this group, send email to django-develop...@googlegroups.com. To unsubscribe from this group, send email to django-developers+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-developers?hl=en.
Django needs for normal sequence of handlers for request processing
The request processing can be easy if developers of sites can define prehandlers and posthandlers for each urls.py (or views.py?). prehandler: the connection middleware. It calls before request object was created. Only connection detailes needed for prehandler processing (no session, no user, no any request-specified objects). Prehandlers are used for connection detailed checking. posthandler: the process middleware. It's usually middleware, but it can be defined for specific urls.py and was processed only for this urls.py and no other. When the server started, it create map of handlers for urls and calls prehandlers and posthandlers according the map. The view (defined in view.py) is used only if no handlers returned response object. -- i.e. the request processing sequence interrupted and server returns the response if the handler returned response object. For example: The site have a members area '^memers/.*$'. The members area have a private zone '^members/private/.*$' (additional authentication demands for access into). Other urls is a public, but some external ip was banned. In urls.py I create prehandler to reject banned ip. In members.urls I create posthandler for user authentication. In members.private.urls I create posthandler for additional authentication. -- A: 1. The server get http request: "GET /members/list.xml" (user is authenticated) 2. django try process prehandlers: prehandler members.prehandlers # not exists 3. django create request object 4. django try process posthandlers: posthandler # it is a settings.middlewares now. (it was a bad idea to put middlewares call map into global settings) members.posthandler (checking for user authentication) 5. process the view: (r'^list.xml$', called members.views.list), -- B: 1. The server get http request: "GET /members/private/ detailes.xml" (user is authenticated and has permissions for access into private area): 2. django try process prehandlers: prehandler members.prehandlers # not exists members.private.prehandler #not exists 3. django create request object 4. django try process posthandlers: posthandler members.posthandler (checking for user authentication) members.private.posthandler (checking for additional authentication) 5. process the view: (r'^detailes.xml$', called members.private.views.detailes), -- C: 1. The server get http request: "GET /members/list.xml" from banned ip: 2. django try process prehandlers: prehandler # ip banned, prehandler returns response and server sending response -- D: 1. The server get http request: "GET /members/list.xml" and user is not authenticated: 2. django try process prehandlers: prehandler members.prehandlers # not exists 3. django create request object 4. django try process posthandlers: posthandler members.posthandler # user is not authenticated, The members.posthandler returns HttpResponseRedirect('/login.xml') and the server send response to user When I created members.posthandler I forgot authentication about. All urls '^members/.*$' was automatically verified for user authentication and all urls '^members/private/.*$' was automatically checked for additional authorization since I defined members.private.posthandler. No decorators. Just define any views into members/views.py or into members/private/views.py and enjoy by result now. P.S. I used this sceme in perl + mason constructions and it was nice. P. P.S. Sorr for my english. :) I can read but can't speack or write. -- You received this message because you are subscribed to the Google Groups "Django developers" group. To post to this group, send email to django-develop...@googlegroups.com. To unsubscribe from this group, send email to django-developers+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-developers?hl=en.
Re: Fwd: how are you handling i18n and m10l content?
On Nov 9, 3:21 pm, Ivan Sagalaev <[EMAIL PROTECTED]> wrote: > +1. Keeping all translations in one table instead of creating separate > tables for each user table is what I was going to propose but you beat > me :-) This has one potential benefit - ease global search implementation. -- serg. --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django developers" group. To post to this group, send email to django-developers@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-developers?hl=en -~--~~~~--~~--~--~---
contrib.admin: why short_description?
Forgive me for silly question, but why 'short_description' used in contrib.admin, instead of '__doc__' attribute? -- serg. --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django developers" group. To post to this group, send email to django-developers@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-developers?hl=en -~--~~~~--~~--~--~---