本文整理汇总了Python中django.core.urlresolvers.resolve方法的典型用法代码示例。如果您正苦于以下问题:Python urlresolvers.resolve方法的具体用法?Python urlresolvers.resolve怎么用?Python urlresolvers.resolve使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类django.core.urlresolvers
的用法示例。
在下文中一共展示了urlresolvers.resolve方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: get_context_data
# 需要导入模块: from django.core import urlresolvers [as 别名]
# 或者: from django.core.urlresolvers import resolve [as 别名]
def get_context_data(self, **kwargs):
context = super(EditMissionTestView, self).get_context_data(**kwargs)
context['action'] = reverse('mission-test-edit', kwargs={'pk': self.get_object().id,
'mission': self.kwargs['mission']})
mission_model = Mission.objects.get(id=self.kwargs['mission'])
context['this_mission'] = mission_model
context['display_navbar_save_button'] = True
context['is_read_only'] = resolve(self.request.path_info).url_name == 'mission-test-view'
if self.request.GET.get('scrollPos'):
try:
context['scrollPos'] = int(self.request.GET.get('scrollPos'))
except ValueError:
logger.exception('URL Parameter scrollPos invalid (not an int); setting to None. '
'(Logged in user: {user})'.format(user=self.request.user.username or "**Anonymous**"))
context['scrollPos'] = None
return context
示例2: get_admin_site
# 需要导入模块: from django.core import urlresolvers [as 别名]
# 或者: from django.core.urlresolvers import resolve [as 别名]
def get_admin_site(current_app):
"""
Method tries to get actual admin.site class, if any custom admin sites
were used. Couldn't find any other references to actual class other than
in func_closer dict in index() func returned by resolver.
"""
try:
resolver_match = resolve(reverse('%s:index' % current_app))
# Django 1.9 exposes AdminSite instance directly on view function
if hasattr(resolver_match.func, 'admin_site'):
return resolver_match.func.admin_site
for func_closure in resolver_match.func.__closure__:
if isinstance(func_closure.cell_contents, AdminSite):
return func_closure.cell_contents
except:
pass
from django.contrib import admin
return admin.site
示例3: to_internal_value
# 需要导入模块: from django.core import urlresolvers [as 别名]
# 或者: from django.core.urlresolvers import resolve [as 别名]
def to_internal_value(self, data):
try:
http_prefix = data.startswith(('http:', 'https:'))
except AttributeError:
self.fail('incorrect_type', data_type=type(data).__name__)
if http_prefix:
# If needed convert absolute URLs to relative path
data = urlparse(data).path
prefix = get_script_prefix()
if data.startswith(prefix):
data = '/' + data[len(prefix):]
try:
match = resolve(data)
except Resolver404:
self.fail('no_match')
try:
lookup_value = match.kwargs[self.lookup_url_kwarg]
lookup_kwargs = {self.lookup_field: lookup_value}
model = match.func.cls.model
return model.objects.get(**lookup_kwargs)
except (ObjectDoesNotExist, TypeError, ValueError):
self.fail('does_not_exist')
示例4: test_project_resource_unarchive
# 需要导入模块: from django.core import urlresolvers [as 别名]
# 或者: from django.core.urlresolvers import resolve [as 别名]
def test_project_resource_unarchive(self):
url = reverse('resources:unarchive',
kwargs={'organization': 'org-slug',
'project': 'proj-slug',
'resource': 'abc123'})
assert url == ('/organizations/org-slug/projects/proj-slug/resources/'
'abc123/unarchive/')
resolved = resolve(
'/organizations/org-slug/projects/proj-slug/resources/abc123/'
'unarchive/')
assert (resolved.func.__name__ ==
default.ResourceUnarchive.__name__)
assert resolved.kwargs['organization'] == 'org-slug'
assert resolved.kwargs['project'] == 'proj-slug'
assert resolved.kwargs['resource'] == 'abc123'
示例5: test_project_detail
# 需要导入模块: from django.core import urlresolvers [as 别名]
# 或者: from django.core.urlresolvers import resolve [as 别名]
def test_project_detail(self):
actual = reverse(
version_ns('resources:project_detail'),
kwargs={'organization': 'habitat',
'project': '123abc',
'resource': '456def'}
)
expected = version_url(
'/organizations/habitat/projects/123abc/resources/456def/')
assert actual == expected
resolved = resolve(version_url(
'/organizations/habitat/projects/123abc/resources/456def/'))
assert resolved.func.__name__ == api.ProjectResourcesDetail.__name__
assert resolved.kwargs['organization'] == 'habitat'
assert resolved.kwargs['project'] == '123abc'
assert resolved.kwargs['resource'] == '456def'
示例6: test_project_spatial_list
# 需要导入模块: from django.core import urlresolvers [as 别名]
# 或者: from django.core.urlresolvers import resolve [as 别名]
def test_project_spatial_list(self):
actual = reverse(
version_ns('resources:project_spatial_resource_list'),
kwargs={'organization': 'habitat',
'project': '123abc'}
)
expected = version_url(
'/organizations/habitat/projects/123abc/spatialresources/')
assert actual == expected
resolved = resolve(version_url(
'/organizations/habitat/projects/123abc/spatialresources/'))
assert (resolved.func.__name__ ==
api.ProjectSpatialResources.__name__)
assert resolved.kwargs['organization'] == 'habitat'
assert resolved.kwargs['project'] == '123abc'
示例7: test_project_spatial_detail
# 需要导入模块: from django.core import urlresolvers [as 别名]
# 或者: from django.core.urlresolvers import resolve [as 别名]
def test_project_spatial_detail(self):
actual = reverse(
version_ns('resources:project_spatial_resource_detail'),
kwargs={'organization': 'habitat',
'project': '123abc',
'resource': '456def'}
)
expected = version_url(
'/organizations/habitat/projects/123abc/spatialresources/456def/')
assert actual == expected
resolved = resolve(version_url(
'/organizations/habitat/projects/123abc/spatialresources/456def/'))
assert (resolved.func.__name__ ==
api.ProjectSpatialResourcesDetail.__name__)
assert resolved.kwargs['organization'] == 'habitat'
assert resolved.kwargs['project'] == '123abc'
assert resolved.kwargs['resource'] == '456def'
示例8: test_parties_detail
# 需要导入模块: from django.core import urlresolvers [as 别名]
# 或者: from django.core.urlresolvers import resolve [as 别名]
def test_parties_detail(self):
url = reverse('parties:detail',
kwargs={'organization': 'org-slug',
'project': 'proj-slug',
'party': 'abc123'})
assert (url ==
'/organizations/org-slug/projects/proj-slug/records/'
'parties/abc123/')
resolved = resolve(
'/organizations/org-slug/projects/proj-slug/records/'
'parties/abc123/')
assert resolved.func.__name__ == default.PartiesDetail.__name__
assert resolved.kwargs['organization'] == 'org-slug'
assert resolved.kwargs['project'] == 'proj-slug'
assert resolved.kwargs['party'] == 'abc123'
示例9: test_parties_edit
# 需要导入模块: from django.core import urlresolvers [as 别名]
# 或者: from django.core.urlresolvers import resolve [as 别名]
def test_parties_edit(self):
url = reverse('parties:edit',
kwargs={'organization': 'org-slug',
'project': 'proj-slug',
'party': 'abc123'})
assert (url ==
'/organizations/org-slug/projects/proj-slug/records/'
'parties/abc123/edit/')
resolved = resolve(
'/organizations/org-slug/projects/proj-slug/records/'
'parties/abc123/edit/')
assert resolved.func.__name__ == default.PartiesEdit.__name__
assert resolved.kwargs['organization'] == 'org-slug'
assert resolved.kwargs['project'] == 'proj-slug'
assert resolved.kwargs['party'] == 'abc123'
示例10: test_parties_delete
# 需要导入模块: from django.core import urlresolvers [as 别名]
# 或者: from django.core.urlresolvers import resolve [as 别名]
def test_parties_delete(self):
url = reverse('parties:delete',
kwargs={'organization': 'org-slug',
'project': 'proj-slug',
'party': 'abc123'})
assert (url ==
'/organizations/org-slug/projects/proj-slug/records/'
'parties/abc123/delete/')
resolved = resolve(
'/organizations/org-slug/projects/proj-slug/records/'
'parties/abc123/delete/')
assert resolved.func.__name__ == default.PartiesDelete.__name__
assert resolved.kwargs['organization'] == 'org-slug'
assert resolved.kwargs['project'] == 'proj-slug'
assert resolved.kwargs['party'] == 'abc123'
示例11: test_resource_add_from_lib
# 需要导入模块: from django.core import urlresolvers [as 别名]
# 或者: from django.core.urlresolvers import resolve [as 别名]
def test_resource_add_from_lib(self):
url = reverse('parties:resource_add',
kwargs={'organization': 'org-slug',
'project': 'proj-slug',
'party': 'abc123'})
assert (url ==
'/organizations/org-slug/projects/proj-slug/records/'
'parties/abc123/resources/add/')
resolved = resolve(
'/organizations/org-slug/projects/proj-slug/records/parties/'
'abc123/resources/add/')
assert resolved.func.__name__ == default.PartyResourcesAdd.__name__
assert resolved.kwargs['organization'] == 'org-slug'
assert resolved.kwargs['project'] == 'proj-slug'
assert resolved.kwargs['party'] == 'abc123'
示例12: test_relationship_detail
# 需要导入模块: from django.core import urlresolvers [as 别名]
# 或者: from django.core.urlresolvers import resolve [as 别名]
def test_relationship_detail(self):
url = reverse('parties:relationship_detail',
kwargs={'organization': 'org-slug',
'project': 'proj-slug',
'relationship': 'xyz456'})
assert (url ==
'/organizations/org-slug/projects/proj-slug/'
'relationships/xyz456/')
resolved = resolve(
'/organizations/org-slug/projects/proj-slug/'
'relationships/xyz456/')
assert (resolved.func.__name__ ==
default.PartyRelationshipDetail.__name__)
assert resolved.kwargs['organization'] == 'org-slug'
assert resolved.kwargs['project'] == 'proj-slug'
assert resolved.kwargs['relationship'] == 'xyz456'
示例13: test_relationship_edit
# 需要导入模块: from django.core import urlresolvers [as 别名]
# 或者: from django.core.urlresolvers import resolve [as 别名]
def test_relationship_edit(self):
url = reverse('parties:relationship_edit',
kwargs={'organization': 'org-slug',
'project': 'proj-slug',
'relationship': 'xyz456'})
assert (url ==
'/organizations/org-slug/projects/proj-slug/'
'relationships/xyz456/edit/')
resolved = resolve(
'/organizations/org-slug/projects/proj-slug/'
'relationships/xyz456/edit/')
assert (resolved.func.__name__ ==
default.PartyRelationshipEdit.__name__)
assert resolved.kwargs['organization'] == 'org-slug'
assert resolved.kwargs['project'] == 'proj-slug'
assert resolved.kwargs['relationship'] == 'xyz456'
示例14: test_relationship_delete
# 需要导入模块: from django.core import urlresolvers [as 别名]
# 或者: from django.core.urlresolvers import resolve [as 别名]
def test_relationship_delete(self):
url = reverse('parties:relationship_delete',
kwargs={'organization': 'org-slug',
'project': 'proj-slug',
'relationship': 'xyz456'})
assert (url ==
'/organizations/org-slug/projects/proj-slug/'
'relationships/xyz456/delete/')
resolved = resolve(
'/organizations/org-slug/projects/proj-slug/'
'relationships/xyz456/delete/')
assert (resolved.func.__name__ ==
default.PartyRelationshipDelete.__name__)
assert resolved.kwargs['organization'] == 'org-slug'
assert resolved.kwargs['project'] == 'proj-slug'
assert resolved.kwargs['relationship'] == 'xyz456'
示例15: test_relationship_resources_new
# 需要导入模块: from django.core import urlresolvers [as 别名]
# 或者: from django.core.urlresolvers import resolve [as 别名]
def test_relationship_resources_new(self):
url = reverse('parties:relationship_resource_new',
kwargs={'organization': 'org-slug',
'project': 'proj-slug',
'relationship': 'xyz456'})
assert (url ==
'/organizations/org-slug/projects/proj-slug/'
'relationships/xyz456/resources/new/')
resolved = resolve(
'/organizations/org-slug/projects/proj-slug/'
'relationships/xyz456/resources/new/')
assert (resolved.func.__name__ ==
default.PartyRelationshipResourceNew.__name__)
assert resolved.kwargs['organization'] == 'org-slug'
assert resolved.kwargs['project'] == 'proj-slug'
assert resolved.kwargs['relationship'] == 'xyz456'