def __call__(self, request, url): ''' DEPRECATED!! More recent versions of Django use the get_urls method instead. Overriden to route extra URLs. ''' if url: if url.endswith('items/add'): return self.add_menu_item(request, unquote(url[:-10])) if url.endswith('items'): return HttpResponseRedirect('../') match = re.match('^(?P<menu_pk>[-\w]+)/items/(?P<menu_item_pk>[-\w]+)$', url) if match: return self.edit_menu_item(request, match.group('menu_pk'), match.group('menu_item_pk')) match = re.match('^(?P<menu_pk>[-\w]+)/items/(?P<menu_item_pk>[-\w]+)/delete$', url) if match: return self.delete_menu_item(request, match.group('menu_pk'), match.group('menu_item_pk')) match = re.match('^(?P<menu_pk>[-\w]+)/items/(?P<menu_item_pk>[-\w]+)/history$', url) if match: return self.history_menu_item(request, match.group('menu_pk'), match.group('menu_item_pk')) match = re.match('^(?P<menu_pk>[-\w]+)/items/(?P<menu_item_pk>[-\w]+)/move_up$', url) if match: return self.move_up_item(request, match.group('menu_pk'), match.group('menu_item_pk')) match = re.match('^(?P<menu_pk>[-\w]+)/items/(?P<menu_item_pk>[-\w]+)/move_down$', url) if match: return self.move_down_item(request, match.group('menu_pk'), match.group('menu_item_pk')) return super(MenuAdmin, self).__call__(request, url)
def button_view_dispatcher(self, request, url): # Dispatch the url to a function call if url is not None: res = re.match("(.*/)?(?P<id>\d+)/(?P<view>.*)/(?P<command>.*)$", url) if res: button_list = {"view": self.view_buttons, "change": self.change_buttons} if res.group("command") in [b.func_name for b in button_list[res.group("view")]]: obj = self.model._default_manager.get(pk=res.group("id")) response = getattr(self, res.group("command"))(request, obj) if response is None: return HttpResponseRedirect(request.META["HTTP_REFERER"]) return response res = re.match("(.*/)?(?P<id>\d+)/(?P<command>.*)$", url) if res: if res.group("command") in [b.func_name for b in self.change_buttons]: obj = self.model._default_manager.get(pk=res.group("id")) response = getattr(self, res.group("command"))(request, obj) if response is None: return HttpResponseRedirect(request.META["HTTP_REFERER"]) return response res = re.match("(.*/)?(?P<command>.*)$", url) if res: if res.group("command") in [b.func_name for b in self.list_buttons]: response = getattr(self, res.group("command"))(request) if response is None: return HttpResponseRedirect(request.META["HTTP_REFERER"]) return response # Delegate to the appropriate method, based on the URL. from django.contrib.admin.util import unquote if url is None: return self.changelist_view(request) elif url == "add": return self.add_view(request) elif url.endswith("/history"): return self.history_view(request, unquote(url[:-8])) elif url.endswith("/delete"): return self.delete_view(request, unquote(url[:-7])) elif url.endswith("/change"): return self.change_view(request, unquote(url[:-7])) elif url.endswith("/view"): return self.display_view(request, unquote(url[:-5])) else: return self.display_view(request, unquote(url))
def __call__(self, request, url): """ DEPRECATED: this is the old way of URL resolution, replaced by ``get_urls()``. This only called by AdminSite.root(), which is also deprecated. Again, remember that the following code only exists for backwards-compatibility. Any new URLs, changes to existing URLs, or whatever need to be done up in get_urls(), above! This function still exists for backwards-compatibility; it will be removed in Django 1.3. """ # Delegate to the appropriate method, based on the URL. if url is None: return self.changelist_view(request) elif url == "add": return self.add_view(request) elif url.endswith('/history'): return self.history_view(request, unquote(url[:-8])) elif url.endswith('/delete'): return self.delete_view(request, unquote(url[:-7])) else: return self.change_view(request, unquote(url))
def button_view_dispatcher(self, request, url): # Dispatch the url to a function call if url is not None: res = re.match('(.*/)?(?P<id>\d+)/(?P<view>.*)/(?P<command>.*)$', url) if res: button_list = { 'view': self.view_buttons, 'change': self.change_buttons } if res.group('command') in [ b.func_name for b in button_list[res.group('view')] ]: obj = self.model._default_manager.get(pk=res.group('id')) response = getattr(self, res.group('command'))(request, obj) if response is None: return HttpResponseRedirect( request.META['HTTP_REFERER']) return response res = re.match('(.*/)?(?P<id>\d+)/(?P<command>.*)$', url) if res: if res.group('command') in [ b.func_name for b in self.change_buttons ]: obj = self.model._default_manager.get(pk=res.group('id')) response = getattr(self, res.group('command'))(request, obj) if response is None: return HttpResponseRedirect( request.META['HTTP_REFERER']) return response res = re.match('(.*/)?(?P<command>.*)$', url) if res: if res.group('command') in [ b.func_name for b in self.list_buttons ]: response = getattr(self, res.group('command'))(request) if response is None: return HttpResponseRedirect( request.META['HTTP_REFERER']) return response # Delegate to the appropriate method, based on the URL. from django.contrib.admin.util import unquote if url is None: return self.changelist_view(request) elif url == 'add': return self.add_view(request) elif url.endswith('/history'): return self.history_view(request, unquote(url[:-8])) elif url.endswith('/delete'): return self.delete_view(request, unquote(url[:-7])) elif url.endswith('/change'): return self.change_view(request, unquote(url[:-7])) elif url.endswith('/view'): return self.display_view(request, unquote(url[:-5])) else: return self.display_view(request, unquote(url))