Python django.core.urlresolvers.NoReverseMatch() Examples
The following are 30
code examples of django.core.urlresolvers.NoReverseMatch().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
django.core.urlresolvers
, or try the search function
.
Example #1
Source File: topnav.py From ImitationTmall_Django with GNU General Public License v3.0 | 6 votes |
def block_top_navbar(self, context, nodes): search_models = [] site_name = self.admin_site.name if self.global_search_models == None: models = self.admin_site._registry.keys() else: models = self.global_search_models for model in models: app_label = model._meta.app_label if self.has_model_perm(model, "view"): info = (app_label, model._meta.model_name) if getattr(self.admin_site._registry[model], 'search_fields', None): try: search_models.append({ 'title': _('Search %s') % capfirst(model._meta.verbose_name_plural), 'url': reverse('xadmin:%s_%s_changelist' % info, current_app=site_name), 'model': model }) except NoReverseMatch: pass return nodes.append(loader.render_to_string('xadmin/blocks/comm.top.topnav.html', {'search_models': search_models, 'search_name': SEARCH_VAR}))
Example #2
Source File: actions.py From avos with Apache License 2.0 | 6 votes |
def get_link_url(self, datum=None): """Returns the final URL based on the value of ``url``. If ``url`` is callable it will call the function. If not, it will then try to call ``reverse`` on ``url``. Failing that, it will simply return the value of ``url`` as-is. When called for a row action, the current row data object will be passed as the first parameter. """ if not self.url: raise NotImplementedError('A LinkAction class must have a ' 'url attribute or define its own ' 'get_link_url method.') if callable(self.url): return self.url(datum, **self.kwargs) try: if datum: obj_id = self.table.get_object_id(datum) return urlresolvers.reverse(self.url, args=(obj_id,)) else: return urlresolvers.reverse(self.url) except urlresolvers.NoReverseMatch as ex: LOG.info('No reverse found for "%s": %s' % (self.url, ex)) return self.url
Example #3
Source File: base.py From avos with Apache License 2.0 | 6 votes |
def get_link_url(self, datum): """Returns the final value for the column's ``link`` property. If ``allowed_data_types`` of this column is not empty and the datum has an assigned type, check if the datum's type is in the ``allowed_data_types`` list. If not, the datum won't be displayed as a link. If ``link`` is a callable, it will be passed the current data object and should return a URL. Otherwise ``get_link_url`` will attempt to call ``reverse`` on ``link`` with the object's id as a parameter. Failing that, it will simply return the value of ``link``. """ if self.allowed_data_types: data_type_name = self.table._meta.data_type_name data_type = getattr(datum, data_type_name, None) if data_type and (data_type not in self.allowed_data_types): return None obj_id = self.table.get_object_id(datum) if callable(self.link): return self.link(datum) try: return urlresolvers.reverse(self.link, args=(obj_id,)) except urlresolvers.NoReverseMatch: return self.link
Example #4
Source File: base.py From GTDWeb with GNU General Public License v2.0 | 6 votes |
def get_redirect_url(self, *args, **kwargs): """ Return the URL redirect to. Keyword arguments from the URL pattern match generating the redirect request are provided as kwargs to this method. """ if self.url: url = self.url % kwargs elif self.pattern_name: try: url = reverse(self.pattern_name, args=args, kwargs=kwargs) except NoReverseMatch: return None else: return None args = self.request.META.get('QUERY_STRING', '') if args and self.query_string: url = "%s?%s" % (url, args) return url
Example #5
Source File: topnav.py From StormOnline with Apache License 2.0 | 6 votes |
def block_top_navmenu(self, context, nodes): add_models = [] site_name = self.admin_site.name if self.global_add_models == None: models = self.admin_site._registry.keys() else: models = self.global_add_models for model in models: app_label = model._meta.app_label if self.has_model_perm(model, "add"): info = (app_label, model._meta.model_name) try: add_models.append({ 'title': _('Add %s') % capfirst(model._meta.verbose_name), 'url': reverse('xadmin:%s_%s_add' % info, current_app=site_name), 'model': model }) except NoReverseMatch: pass nodes.append( loader.render_to_string('xadmin/blocks/comm.top.topnav.html', {'add_models': add_models}))
Example #6
Source File: menu.py From DCRM with GNU Affero General Public License v3.0 | 6 votes |
def handle_user_url(self, menu_item): """ Evaluate user defined URL :type menu_item: ChildItem or ParentItem """ if callable(menu_item.url): menu_item.url = menu_item.url(self.request, self.context) return menu_item if '/' in menu_item.url: return menu_item from django.core.urlresolvers import reverse, NoReverseMatch try: menu_item.url = reverse(menu_item.url, current_app=self.current_app) menu_item._url_name = menu_item.url except NoReverseMatch: menu_item.url = '#no-reverse-match' return menu_item
Example #7
Source File: topnav.py From StormOnline with Apache License 2.0 | 6 votes |
def block_top_navbar(self, context, nodes): search_models = [] site_name = self.admin_site.name if self.global_search_models == None: models = self.admin_site._registry.keys() else: models = self.global_search_models for model in models: app_label = model._meta.app_label if self.has_model_perm(model, "view"): info = (app_label, model._meta.model_name) if getattr(self.admin_site._registry[model], 'search_fields', None): try: search_models.append({ 'title': _('Search %s') % capfirst(model._meta.verbose_name_plural), 'url': reverse('xadmin:%s_%s_changelist' % info, current_app=site_name), 'model': model }) except NoReverseMatch: pass return nodes.append(loader.render_to_string('xadmin/blocks/comm.top.topnav.html', {'search_models': search_models, 'search_name': SEARCH_VAR}))
Example #8
Source File: topnav.py From ImitationTmall_Django with GNU General Public License v3.0 | 6 votes |
def block_top_navmenu(self, context, nodes): add_models = [] site_name = self.admin_site.name if self.global_add_models == None: models = self.admin_site._registry.keys() else: models = self.global_add_models for model in models: app_label = model._meta.app_label if self.has_model_perm(model, "add"): info = (app_label, model._meta.model_name) try: add_models.append({ 'title': _('Add %s') % capfirst(model._meta.verbose_name), 'url': reverse('xadmin:%s_%s_add' % info, current_app=site_name), 'model': model }) except NoReverseMatch: pass nodes.append( loader.render_to_string('xadmin/blocks/comm.top.topnav.html', {'add_models': add_models}))
Example #9
Source File: reverse.py From esdc-ce with Apache License 2.0 | 6 votes |
def reverse(viewname, args=None, kwargs=None, request=None, format=None, **extra): """ If versioning is being used then we pass any `reverse` calls through to the versioning scheme instance, so that the resulting URL can be modified if needed. """ scheme = getattr(request, 'versioning_scheme', None) if scheme is not None: try: return scheme.reverse(viewname, args, kwargs, request, format, **extra) except NoReverseMatch: # In case the versioning scheme reversal fails, fallback to the default implementation pass return _reverse(viewname, args, kwargs, request, format, **extra)
Example #10
Source File: tests.py From osler with GNU General Public License v3.0 | 6 votes |
def test_followup_view_rendering(self): from django.core.urlresolvers import NoReverseMatch for url in urls.urlpatterns: if url.name in ['new-followup', 'followup']: continue # all the URLs have either one parameter or none. Try one # parameter first; if that fails, try with none. try: self.verify_rendering(url.name, (1,)) except NoReverseMatch: self.verify_rendering(url.name) for fu_type in FU_TYPES: self.verify_rendering('new-followup', (1, fu_type)) # TODO: build in checks for 'followup' once the objects exist. # for model in ['General', 'Lab']: # self.verify_rendering('followup', # kwargs={"pk": 1, "model": model})
Example #11
Source File: dashboard.py From ImitationTmall_Django with GNU General Public License v3.0 | 6 votes |
def context(self, context): btns = [] for b in self.q_btns: btn = {} if 'model' in b: model = self.get_model(b['model']) if not self.user.has_perm("%s.view_%s" % (model._meta.app_label, model._meta.model_name)): continue btn['url'] = reverse("%s:%s_%s_%s" % (self.admin_site.app_name, model._meta.app_label, model._meta.model_name, b.get('view', 'changelist'))) btn['title'] = model._meta.verbose_name btn['icon'] = self.dashboard.get_model_icon(model) else: try: btn['url'] = reverse(b['url']) except NoReverseMatch: btn['url'] = b['url'] if 'title' in b: btn['title'] = b['title'] if 'icon' in b: btn['icon'] = b['icon'] btns.append(btn) context.update({'btns': btns})
Example #12
Source File: leonardo_tags.py From django-leonardo with BSD 3-Clause "New" or "Revised" License | 6 votes |
def render(self, context): args = [arg.resolve(context) for arg in self.args] kwargs = dict([ (smart_str(k, 'ascii'), v.resolve(context)) for k, v in self.kwargs.items()]) view_name = self.view_name.resolve(context) urlconf = self.urlconf.resolve(context) try: url = do_app_reverse( view_name, urlconf, args=args, kwargs=kwargs, current_app=context.current_app) except NoReverseMatch: if self.asvar is None: raise url = '' if self.asvar: context[self.asvar] = url return '' else: return url
Example #13
Source File: utils.py From devops with MIT License | 6 votes |
def handle_redirect_to_login(request, **kwargs): login_url = kwargs.get("login_url") redirect_field_name = kwargs.get("redirect_field_name") next_url = kwargs.get("next_url") if login_url is None: login_url = settings.ACCOUNT_LOGIN_URL if next_url is None: next_url = request.get_full_path() try: login_url = urlresolvers.reverse(login_url) except urlresolvers.NoReverseMatch: if callable(login_url): raise if "/" not in login_url and "." not in login_url: raise url_bits = list(urlparse(login_url)) if redirect_field_name: querystring = QueryDict(url_bits[4], mutable=True) querystring[redirect_field_name] = next_url url_bits[4] = querystring.urlencode(safe="/") return HttpResponseRedirect(urlunparse(url_bits))
Example #14
Source File: topnav.py From devops with MIT License | 6 votes |
def block_top_navmenu(self, context, nodes): add_models = [] site_name = self.admin_site.name if self.global_add_models == None: models = self.admin_site._registry.keys() else: models = self.global_add_models for model in models: app_label = model._meta.app_label if self.has_model_perm(model, "add"): info = (app_label, model._meta.model_name) try: add_models.append({ 'title': _('Add %s') % capfirst(model._meta.verbose_name), 'url': reverse('xadmin:%s_%s_add' % info, current_app=site_name), 'model': model }) except NoReverseMatch: pass nodes.append( loader.render_to_string('xadmin/blocks/comm.top.topnav.html', {'add_models': add_models}))
Example #15
Source File: topnav.py From devops with MIT License | 6 votes |
def block_top_navbar(self, context, nodes): search_models = [] site_name = self.admin_site.name if self.global_search_models == None: models = self.admin_site._registry.keys() else: models = self.global_search_models for model in models: app_label = model._meta.app_label if self.has_model_perm(model, "view"): info = (app_label, model._meta.model_name) if getattr(self.admin_site._registry[model], 'search_fields', None): try: search_models.append({ 'title': _('Search %s') % capfirst(model._meta.verbose_name_plural), 'url': reverse('xadmin:%s_%s_changelist' % info, current_app=site_name), 'model': model }) except NoReverseMatch: pass nodes.append(loader.render_to_string('xadmin/blocks/comm.top.topnav.html', {'search_models': search_models, 'search_name': SEARCH_VAR}))
Example #16
Source File: dashboard.py From devops with MIT License | 6 votes |
def context(self, context): btns = [] for b in self.q_btns: btn = {} if 'model' in b: model = self.get_model(b['model']) if not self.user.has_perm("%s.view_%s" % (model._meta.app_label, model._meta.model_name)): continue btn['url'] = reverse("%s:%s_%s_%s" % (self.admin_site.app_name, model._meta.app_label, model._meta.model_name, b.get('view', 'changelist'))) btn['title'] = model._meta.verbose_name btn['icon'] = self.dashboard.get_model_icon(model) else: try: btn['url'] = reverse(b['url']) except NoReverseMatch: btn['url'] = b['url'] if 'title' in b: btn['title'] = b['title'] if 'icon' in b: btn['icon'] = b['icon'] btns.append(btn) context.update({'btns': btns})
Example #17
Source File: topnav.py From imoocc with GNU General Public License v2.0 | 6 votes |
def block_top_navmenu(self, context, nodes): add_models = [] site_name = self.admin_site.name if self.global_add_models == None: models = self.admin_site._registry.keys() else: models = self.global_add_models for model in models: app_label = model._meta.app_label if self.has_model_perm(model, "add"): info = (app_label, model._meta.model_name) try: add_models.append({ 'title': _('Add %s') % capfirst(model._meta.verbose_name), 'url': reverse('xadmin:%s_%s_add' % info, current_app=site_name), 'model': model }) except NoReverseMatch: pass nodes.append( loader.render_to_string('xadmin/blocks/comm.top.topnav.html', {'add_models': add_models}))
Example #18
Source File: topnav.py From imoocc with GNU General Public License v2.0 | 6 votes |
def block_top_navbar(self, context, nodes): search_models = [] site_name = self.admin_site.name if self.global_search_models == None: models = self.admin_site._registry.keys() else: models = self.global_search_models for model in models: app_label = model._meta.app_label if self.has_model_perm(model, "view"): info = (app_label, model._meta.model_name) if getattr(self.admin_site._registry[model], 'search_fields', None): try: search_models.append({ 'title': _('Search %s') % capfirst(model._meta.verbose_name_plural), 'url': reverse('xadmin:%s_%s_changelist' % info, current_app=site_name), 'model': model }) except NoReverseMatch: pass return nodes.append(loader.render_to_string('xadmin/blocks/comm.top.topnav.html', {'search_models': search_models, 'search_name': SEARCH_VAR}))
Example #19
Source File: base.py From openhgsenti with Apache License 2.0 | 6 votes |
def get_redirect_url(self, *args, **kwargs): """ Return the URL redirect to. Keyword arguments from the URL pattern match generating the redirect request are provided as kwargs to this method. """ if self.url: url = self.url % kwargs elif self.pattern_name: try: url = reverse(self.pattern_name, args=args, kwargs=kwargs) except NoReverseMatch: return None else: return None args = self.request.META.get('QUERY_STRING', '') if args and self.query_string: url = "%s?%s" % (url, args) return url
Example #20
Source File: dashboard.py From imoocc with GNU General Public License v2.0 | 6 votes |
def context(self, context): btns = [] for b in self.q_btns: btn = {} if 'model' in b: model = self.get_model(b['model']) if not self.user.has_perm("%s.view_%s" % (model._meta.app_label, model._meta.model_name)): continue btn['url'] = reverse("%s:%s_%s_%s" % (self.admin_site.app_name, model._meta.app_label, model._meta.model_name, b.get('view', 'changelist'))) btn['title'] = model._meta.verbose_name btn['icon'] = self.dashboard.get_model_icon(model) else: try: btn['url'] = reverse(b['url']) except NoReverseMatch: btn['url'] = b['url'] if 'title' in b: btn['title'] = b['title'] if 'icon' in b: btn['icon'] = b['icon'] btns.append(btn) context.update({'btns': btns})
Example #21
Source File: dashboard.py From StormOnline with Apache License 2.0 | 6 votes |
def context(self, context): btns = [] for b in self.q_btns: btn = {} if 'model' in b: model = self.get_model(b['model']) if not self.user.has_perm("%s.view_%s" % (model._meta.app_label, model._meta.model_name)): continue btn['url'] = reverse("%s:%s_%s_%s" % (self.admin_site.app_name, model._meta.app_label, model._meta.model_name, b.get('view', 'changelist'))) btn['title'] = model._meta.verbose_name btn['icon'] = self.dashboard.get_model_icon(model) else: try: btn['url'] = reverse(b['url']) except NoReverseMatch: btn['url'] = b['url'] if 'title' in b: btn['title'] = b['title'] if 'icon' in b: btn['icon'] = b['icon'] btns.append(btn) context.update({'btns': btns})
Example #22
Source File: settings.py From django-sae with Apache License 2.0 | 5 votes |
def patch_root_urlconf(): from django.conf.urls import include, patterns, url from django.core.urlresolvers import clear_url_caches, reverse, NoReverseMatch from django.utils.importlib import import_module try: reverse('tasks:execute') except NoReverseMatch: root = import_module(settings.ROOT_URLCONF) root.urlpatterns = patterns('', url(r'^tasks/', include('django_sae.contrib.tasks.urls', 'tasks', 'tasks')), ) + root.urlpatterns clear_url_caches()
Example #23
Source File: relations.py From esdc-ce with Apache License 2.0 | 5 votes |
def get_url(self, obj, view_name, request, format): """ Given an object, return the URL that hyperlinks to the object. May raise a `NoReverseMatch` if the `view_name` and `lookup_field` attributes are not configured to correctly match the URL conf. """ lookup_field = getattr(obj, self.lookup_field, None) kwargs = {self.lookup_field: lookup_field} # Handle unsaved object case if lookup_field is None: return None try: return reverse(view_name, kwargs=kwargs, request=request, format=format) except NoReverseMatch: pass if self.pk_url_kwarg != 'pk': # Only try pk lookup if it has been explicitly set. # Otherwise, the default `lookup_field = 'pk'` has us covered. kwargs = {self.pk_url_kwarg: obj.pk} try: return reverse(view_name, kwargs=kwargs, request=request, format=format) except NoReverseMatch: pass slug = getattr(obj, self.slug_field, None) if slug: # Only use slug lookup if a slug field exists on the model kwargs = {self.slug_url_kwarg: slug} try: return reverse(view_name, kwargs=kwargs, request=request, format=format) except NoReverseMatch: pass raise NoReverseMatch()
Example #24
Source File: base.py From avos with Apache License 2.0 | 5 votes |
def get_success_url(self): """Returns a URL to redirect the user to upon completion. By default it will attempt to parse a ``success_url`` attribute on the workflow, which can take the form of a reversible URL pattern name, or a standard HTTP URL. """ try: return urlresolvers.reverse(self.success_url) except urlresolvers.NoReverseMatch: return self.success_url
Example #25
Source File: __init__.py From openhgsenti with Apache License 2.0 | 5 votes |
def ping_google(sitemap_url=None, ping_url=PING_URL): """ Alerts Google that the sitemap for the current site has been updated. If sitemap_url is provided, it should be an absolute path to the sitemap for this site -- e.g., '/sitemap.xml'. If sitemap_url is not provided, this function will attempt to deduce it by using urlresolvers.reverse(). """ if sitemap_url is None: try: # First, try to get the "index" sitemap URL. sitemap_url = urlresolvers.reverse('django.contrib.sitemaps.views.index') except urlresolvers.NoReverseMatch: try: # Next, try for the "global" sitemap URL. sitemap_url = urlresolvers.reverse('django.contrib.sitemaps.views.sitemap') except urlresolvers.NoReverseMatch: pass if sitemap_url is None: raise SitemapNotFound("You didn't provide a sitemap_url, and the sitemap URL couldn't be auto-detected.") if not django_apps.is_installed('django.contrib.sites'): raise ImproperlyConfigured("ping_google requires django.contrib.sites, which isn't installed.") Site = django_apps.get_model('sites.Site') current_site = Site.objects.get_current() url = "http://%s%s" % (current_site.domain, sitemap_url) params = urlencode({'sitemap': url}) urlopen("%s?%s" % (ping_url, params))
Example #26
Source File: base.py From avos with Apache License 2.0 | 5 votes |
def test_index_url_name(self): cats = horizon.get_dashboard("cats") tigers = cats.get_panel("tigers") tigers.index_url_name = "does_not_exist" with self.assertRaises(urlresolvers.NoReverseMatch): tigers.get_absolute_url() tigers.index_url_name = "index" self.assertEqual("/cats/tigers/", tigers.get_absolute_url())
Example #27
Source File: js_api.py From canvas with BSD 3-Clause "New" or "Revised" License | 5 votes |
def get_api_calls(api_functions=api_functions, ignore_unfound=False): """ Returns a list of APICall. """ functions = [(n,f) for (n,f) in api_functions if getattr(f, "is_api", False)] functions = sorted(functions, key=lambda (n,f): n) ret = [] for function in functions: try: ret.append(APICall(function)) except NoReverseMatch: if not ignore_unfound: raise return ret
Example #28
Source File: serializers.py From steemprojects.com with MIT License | 5 votes |
def get_url(self, obj, view_name): """ Given an object, return the URL that hyperlinks to the object. May raise a `NoReverseMatch` if the `view_name` and `lookup_field` attributes are not configured to correctly match the URL conf. """ # Unsaved objects will not yet have a valid URL. if hasattr(obj, 'pk') and obj.pk is None: return None kwargs = {'pk': 1} return reverse(view_name, kwargs=kwargs)
Example #29
Source File: serializers.py From steemprojects.com with MIT License | 5 votes |
def to_representation(self, value): self.view_name = "apiv4:{}-detail".format(value.item_type) try: url = self.get_url(value, self.view_name) except NoReverseMatch: msg = ( 'Could not resolve URL for hyperlinked relationship using ' 'view name "%s". You may have failed to include the related ' 'model in your API, or incorrectly configured the ' '`lookup_field` attribute on this field.' ) if value in ('', None): value_string = {'': 'the empty string', None: 'None'}[value] msg += ( " WARNING: The value of the field on the model instance " "was %s, which may be why it didn't match any " "entries in your URL conf." % value_string ) raise ImproperlyConfigured(msg % self.view_name) if url is None: return None return relations.Hyperlink(url, six.text_type(value))
Example #30
Source File: mytag.py From twitterDataMining with GNU General Public License v3.0 | 5 votes |
def active(context, pattern_or_urlname): try: pattern = '^' + reverse(pattern_or_urlname) except NoReverseMatch: pattern = pattern_or_urlname path = context['request'].path if re.search(pattern, path): return 'active' return ''