I was afraid of middleware too, but it's really not bad at all. Just remember that the URL patterns are only processed once.
On Jun 27, 7:41 am, Kenneth Gonsalves <law...@thenilgiris.com> wrote: > On Friday 26 June 2009 21:19:30 Rajesh D wrote: > > > > > > I have a conference management application. It has a list of menu items > > > on the lefthand side. These menus are created by a templatetag from a > > > list of menus in views.py. At various stages of the conference, menu > > > items have to be enabled or disabled. For example, 'submit talk' has to > > > be hidden after the last date for talk submission is over. At present I > > > am doing this by commenting out the menu item in views.py and commenting > > > out the corresponding url inurls.py. But this involves the admins > > > delving into code, which is not a good thing as there is no guarantee > > > that the admins will be programmers. The menu items can be put in a > > > model, and have a boolean field 'activate'. That is not a problem. But if > > > the url is not commented out inurls.py, there is nothing to prevent the > > >userfrom directly typing in the url. So is there some way where these > > >urlscan also be stored in a model so that the admin just has to set > > > 'activate' to false and the menu will not appear and the url will not be > > > available for theuserto directly type it in? > > > You could use custom middleware code to set request.urlconf[1] from a > > function that dynamically puts together the menuURLsbasedon your > > model's activate flag. > > > For an example of dynamically constructing URL patterns at run time, > > see Django Admin's sites.AdminSite.get_urls method[2]. Note that this > > admin method isn't called per request but the examply is still useful > > to understand how simple it is to return a custom URL pattern list. > > The key is to wire that function into the custom middleware mentioned > > above. > > thanks for the detailed reply, but I am terrified of going any where near > middleware. I compromised by making a decorator that checks whether the menu > item is enabled when ever a view function is called from that menu. Works for > me (am fighting a deadline). > -- > regards > kghttp://lawgon.livejournal.com --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~----------~----~----~----~------~----~------~--~---