Thanks, It worked. On Mon, Feb 18, 2013 at 1:00 PM, Tom Evans <tevans...@googlemail.com> wrote:
> On Mon, Feb 18, 2013 at 2:41 PM, Serge G. Spaolonzi <se...@cobalys.com> > wrote: > > Thanks Pankaj, In this case I could not use an HttpResponse because the > > helper method I am developing doesn't return a respose it returns a dict > or > > raises an exception if the user is not authenticated. > > For example: > > > > def get_server_time(request): > > time_dictionary = helper_method() > > #Rest of the view here > > > > def helper_method(): > > if user.is_authenticated(): > > return {'server_time': server_time()} > > else: > > raise HttpCustomException(redirect='this_login_for_this_method') > > > > The goal is to return the dictionary or redirect the user to a specific > > login screen (there would be several login screens). > > The idea is to encapsulate all this functionality in the helper method so > > the views dont have to implement the authentication part or write a > > try/catch/redirect in all the views. > > > > Hi Serge > > If an unhandled exception is raised from view code, then before > generating a default error response, Django will first call any > middleware that has a process_exception method, and if a response is > returned from any of them, will use that response rather than proceed > with it's standard error reporting. > > Therefore, you can simply define some middleware to handle project > specific exceptions in a similar manner to Http404. > > Cheers > > Tom > > -- > You received this message because you are subscribed to the Google Groups > "Django users" group. > To unsubscribe from this group and stop receiving emails from it, send an > email to django-users+unsubscr...@googlegroups.com. > To post to this group, send email to django-users@googlegroups.com. > Visit this group at http://groups.google.com/group/django-users?hl=en. > For more options, visit https://groups.google.com/groups/opt_out. > > > -- Serge G. Spaolonzi Cobalys Systems http://www.cobalys.com -- You received this message because you are subscribed to the Google Groups "Django users" group. To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscr...@googlegroups.com. To post to this group, send email to django-users@googlegroups.com. Visit this group at http://groups.google.com/group/django-users?hl=en. For more options, visit https://groups.google.com/groups/opt_out.