Python django.core.urlresolvers.resolve() Examples
The following are 30
code examples of django.core.urlresolvers.resolve().
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: test_urls_default.py From cadasta-platform with GNU Affero General Public License v3.0 | 6 votes |
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'
Example #2
Source File: serializers.py From gro-api with GNU General Public License v2.0 | 6 votes |
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')
Example #3
Source File: test_urls_api.py From cadasta-platform with GNU Affero General Public License v3.0 | 6 votes |
def test_spatial_unit_resource_list(self): actual = reverse( version_ns('spatial:resource_list'), kwargs={ 'organization': 'habitat', 'project': '123abc', 'location': '123456123456123456123456', } ) expected = version_url( '/organizations/habitat/projects/123abc/' 'spatial/123456123456123456123456/resources/') assert actual == expected resolved = resolve(version_url( '/organizations/habitat/projects/123abc/spatial/' '123456123456123456123456/resources/')) assert resolved.func.__name__ == api.SpatialUnitResourceList.__name__ assert resolved.kwargs['organization'] == 'habitat' assert resolved.kwargs['project'] == '123abc' assert resolved.kwargs['location'] == '123456123456123456123456'
Example #4
Source File: suit_menu.py From DCRM with GNU Affero General Public License v3.0 | 6 votes |
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
Example #5
Source File: test_urls_default.py From cadasta-platform with GNU Affero General Public License v3.0 | 6 votes |
def test_user_activate(self): url = reverse('user:activate', kwargs={'user': 'user-name'}) assert (url == '/users/user-name/activate/') url = reverse('user:activate', kwargs={'user': 'user-name-with-+@.'}) assert (url == '/users/user-name-with-+@./activate/') resolved = resolve('/users/user-name/activate/') assert resolved.func.__name__ == default.UserActivation.__name__ assert resolved.kwargs['user'] == 'user-name' assert resolved.func.view_initkwargs['new_state'] is True resolved = resolve('/users/user-name-with-+@./activate/') assert resolved.func.__name__ == default.UserActivation.__name__ assert resolved.kwargs['user'] == 'user-name-with-+@.' assert resolved.func.view_initkwargs['new_state'] is True
Example #6
Source File: test_urls_api.py From cadasta-platform with GNU Affero General Public License v3.0 | 6 votes |
def test_project_spatial_unit_list(self): actual = reverse( version_ns('spatial:list'), kwargs={ 'organization': 'habitat', 'project': '123abc', } ) expected = version_url( '/organizations/habitat/projects/123abc/spatial/') assert actual == expected resolved = resolve(version_url( '/organizations/habitat/projects/123abc/spatial/')) assert resolved.func.__name__ == api.SpatialUnitList.__name__ assert resolved.kwargs['organization'] == 'habitat' assert resolved.kwargs['project'] == '123abc'
Example #7
Source File: test_urls_default.py From cadasta-platform with GNU Affero General Public License v3.0 | 6 votes |
def test_relationship_new(self): url = reverse('locations:relationship_add', kwargs={'organization': 'org-slug', 'project': 'proj-slug', 'location': 'abc123'}) assert (url == '/organizations/org-slug/projects/proj-slug/records/' 'locations/abc123/relationships/new/') resolved = resolve( '/organizations/org-slug/projects/proj-slug/records/locations/' 'abc123/relationships/new/') assert (resolved.func.__name__ == default.TenureRelationshipAdd.__name__) assert resolved.kwargs['organization'] == 'org-slug' assert resolved.kwargs['project'] == 'proj-slug' assert resolved.kwargs['location'] == 'abc123'
Example #8
Source File: test_urls_default.py From cadasta-platform with GNU Affero General Public License v3.0 | 6 votes |
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'
Example #9
Source File: test_urls_default.py From cadasta-platform with GNU Affero General Public License v3.0 | 6 votes |
def test_resource_add_new(self): url = reverse('locations:resource_new', kwargs={'organization': 'org-slug', 'project': 'proj-slug', 'location': 'abc123'}) assert (url == '/organizations/org-slug/projects/proj-slug/records/' 'locations/abc123/resources/new/') resolved = resolve( '/organizations/org-slug/projects/proj-slug/records/locations/' 'abc123/resources/new/') assert resolved.func.__name__ == default.LocationResourceNew.__name__ assert resolved.kwargs['organization'] == 'org-slug' assert resolved.kwargs['project'] == 'proj-slug' assert resolved.kwargs['location'] == 'abc123'
Example #10
Source File: test_urls_api.py From cadasta-platform with GNU Affero General Public License v3.0 | 6 votes |
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'
Example #11
Source File: test_urls_api.py From cadasta-platform with GNU Affero General Public License v3.0 | 6 votes |
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'
Example #12
Source File: test_urls_api.py From cadasta-platform with GNU Affero General Public License v3.0 | 6 votes |
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'
Example #13
Source File: test_urls_default.py From cadasta-platform with GNU Affero General Public License v3.0 | 6 votes |
def test_resource_add_from_lib(self): url = reverse('locations:resource_add', kwargs={'organization': 'org-slug', 'project': 'proj-slug', 'location': 'abc123'}) assert (url == '/organizations/org-slug/projects/proj-slug/records/' 'locations/abc123/resources/add/') resolved = resolve( '/organizations/org-slug/projects/proj-slug/records/locations/' 'abc123/resources/add/') assert resolved.func.__name__ == default.LocationResourceAdd.__name__ assert resolved.kwargs['organization'] == 'org-slug' assert resolved.kwargs['project'] == 'proj-slug' assert resolved.kwargs['location'] == 'abc123'
Example #14
Source File: test_urls_default.py From cadasta-platform with GNU Affero General Public License v3.0 | 6 votes |
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'
Example #15
Source File: test_urls_default.py From cadasta-platform with GNU Affero General Public License v3.0 | 6 votes |
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'
Example #16
Source File: test_urls_api.py From cadasta-platform with GNU Affero General Public License v3.0 | 6 votes |
def test_project_spatial_unit_relationships_list(self): actual = reverse( version_ns('spatial:rel_list'), kwargs={ 'organization': 'habitat', 'project': '123abc', 'location': '123456123456123456123456', } ) expected = version_url( '/organizations/habitat/projects/123abc/' 'spatial/123456123456123456123456/relationships/') assert actual == expected resolved = resolve(version_url( '/organizations/habitat/projects/123abc/' 'spatial/123456123456123456123456/relationships/')) assert resolved.func.__name__ == RelationshipList.__name__ assert resolved.kwargs['organization'] == 'habitat' assert resolved.kwargs['project'] == '123abc' assert resolved.kwargs['location'] == '123456123456123456123456'
Example #17
Source File: test_urls_default.py From cadasta-platform with GNU Affero General Public License v3.0 | 6 votes |
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'
Example #18
Source File: test_urls_default.py From cadasta-platform with GNU Affero General Public License v3.0 | 6 votes |
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'
Example #19
Source File: test_urls_default.py From cadasta-platform with GNU Affero General Public License v3.0 | 6 votes |
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'
Example #20
Source File: test_urls_default.py From cadasta-platform with GNU Affero General Public License v3.0 | 6 votes |
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'
Example #21
Source File: test_urls_default.py From cadasta-platform with GNU Affero General Public License v3.0 | 6 votes |
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'
Example #22
Source File: test_urls_default.py From cadasta-platform with GNU Affero General Public License v3.0 | 6 votes |
def test_relationship_resources_add(self): url = reverse('parties:relationship_resource_add', kwargs={'organization': 'org-slug', 'project': 'proj-slug', 'relationship': 'xyz456'}) assert (url == '/organizations/org-slug/projects/proj-slug/' 'relationships/xyz456/resources/add/') resolved = resolve( '/organizations/org-slug/projects/proj-slug/' 'relationships/xyz456/resources/add/') assert (resolved.func.__name__ == default.PartyRelationshipResourceAdd.__name__) assert resolved.kwargs['organization'] == 'org-slug' assert resolved.kwargs['project'] == 'proj-slug' assert resolved.kwargs['relationship'] == 'xyz456'
Example #23
Source File: test_urls_api.py From cadasta-platform with GNU Affero General Public License v3.0 | 6 votes |
def test_project_party_detail(self): actual = reverse( version_ns('party:detail'), kwargs={ 'organization': 'habitat', 'project': '123abc', 'party': '123456123456123456123456', } ) expected = version_url( '/organizations/habitat/projects/123abc/' 'parties/123456123456123456123456/') assert actual == expected resolved = resolve(version_url( '/organizations/habitat/projects/123abc/' 'parties/123456123456123456123456/')) assert resolved.func.__name__ == api.PartyDetail.__name__ assert resolved.kwargs['organization'] == 'habitat' assert resolved.kwargs['project'] == '123abc' assert resolved.kwargs['party'] == '123456123456123456123456'
Example #24
Source File: test_urls_api.py From cadasta-platform with GNU Affero General Public License v3.0 | 6 votes |
def test_project_party_resource_list(self): actual = reverse( version_ns('party:resource_list'), kwargs={ 'organization': 'habitat', 'project': '123abc', 'party': '123456123456123456123456', } ) expected = version_url( '/organizations/habitat/projects/123abc/' 'parties/123456123456123456123456/resources/') assert actual == expected resolved = resolve(version_url( '/organizations/habitat/projects/123abc/' 'parties/123456123456123456123456/resources/')) assert resolved.func.__name__ == api.PartyResourceList.__name__ assert resolved.kwargs['organization'] == 'habitat' assert resolved.kwargs['project'] == '123abc' assert resolved.kwargs['party'] == '123456123456123456123456'
Example #25
Source File: test_urls_api.py From cadasta-platform with GNU Affero General Public License v3.0 | 6 votes |
def test_project_party_resource_detail(self): actual = reverse( version_ns('party:resource_detail'), kwargs={ 'organization': 'habitat', 'project': '123abc', 'party': '123456123456123456123456', 'resource': '352091238623324256823' } ) expected = version_url( '/organizations/habitat/projects/123abc/' 'parties/123456123456123456123456/' 'resources/352091238623324256823/') assert actual == expected resolved = resolve(version_url( '/organizations/habitat/projects/123abc/' 'parties/123456123456123456123456/' 'resources/352091238623324256823/')) assert resolved.func.__name__ == api.PartyResourceDetail.__name__ assert resolved.kwargs['organization'] == 'habitat' assert resolved.kwargs['project'] == '123abc' assert resolved.kwargs['party'] == '123456123456123456123456' assert resolved.kwargs['resource'] == '352091238623324256823'
Example #26
Source File: test_urls_api.py From cadasta-platform with GNU Affero General Public License v3.0 | 6 votes |
def test_project_party_relationships_list(self): actual = reverse( version_ns('party:rel_list'), kwargs={ 'organization': 'habitat', 'project': '123abc', 'party': '123456123456123456123456', } ) expected = version_url( '/organizations/habitat/projects/123abc/' 'parties/123456123456123456123456/relationships/') assert actual == expected resolved = resolve(version_url( '/organizations/habitat/projects/123abc/' 'parties/123456123456123456123456/relationships/')) assert resolved.func.__name__ == api.RelationshipList.__name__ assert resolved.kwargs['organization'] == 'habitat' assert resolved.kwargs['project'] == '123abc' assert resolved.kwargs['party'] == '123456123456123456123456'
Example #27
Source File: test_urls_api.py From cadasta-platform with GNU Affero General Public License v3.0 | 6 votes |
def generic_test_project_relationship_list(self, rel_class, view): actual = reverse( version_ns('relationship:{}_rel_list'.format(rel_class)), kwargs={ 'organization': 'habitat', 'project': '123abc', } ) expected = version_url( '/organizations/habitat/projects/123abc/' 'relationships/{}/'.format(rel_class)) assert actual == expected resolved = resolve(version_url( '/organizations/habitat/projects/123abc/' 'relationships/{}/'.format(rel_class))) assert resolved.func.__name__ == view.__name__ assert resolved.kwargs['organization'] == 'habitat' assert resolved.kwargs['project'] == '123abc'
Example #28
Source File: test_urls_api.py From cadasta-platform with GNU Affero General Public License v3.0 | 6 votes |
def test_project_party_resource_list(self): actual = reverse( version_ns('relationship:tenure_rel_resource_list'), kwargs={ 'organization': 'habitat', 'project': '123abc', 'tenure_rel_id': '123456123456123456123456', } ) expected = version_url( '/organizations/habitat/projects/123abc/relationships/' 'tenure/123456123456123456123456/resources/') assert actual == expected resolved = resolve(version_url( '/organizations/habitat/projects/123abc/relationships/' 'tenure/123456123456123456123456/resources/')) assert (resolved.func.__name__ == api.TenureRelationshipResourceList.__name__) assert resolved.kwargs['organization'] == 'habitat' assert resolved.kwargs['project'] == '123abc' assert resolved.kwargs['tenure_rel_id'] == '123456123456123456123456'
Example #29
Source File: test_urls_default.py From cadasta-platform with GNU Affero General Public License v3.0 | 6 votes |
def test_locations_delete(self): url = reverse('locations:delete', kwargs={'organization': 'org-slug', 'project': 'proj-slug', 'location': 'abc123'}) assert (url == '/organizations/org-slug/projects/proj-slug/records/' 'locations/abc123/delete/') resolved = resolve( '/organizations/org-slug/projects/proj-slug/records/' 'locations/abc123/delete/') assert resolved.func.__name__ == default.LocationDelete.__name__ assert resolved.kwargs['organization'] == 'org-slug' assert resolved.kwargs['project'] == 'proj-slug' assert resolved.kwargs['location'] == 'abc123'
Example #30
Source File: test_urls_default.py From cadasta-platform with GNU Affero General Public License v3.0 | 6 votes |
def test_locations_detail(self): url = reverse('locations:detail', kwargs={'organization': 'org-slug', 'project': 'proj-slug', 'location': 'abc123'}) assert (url == '/organizations/org-slug/projects/proj-slug/records/' 'locations/abc123/') resolved = resolve( '/organizations/org-slug/projects/proj-slug/records/' 'locations/abc123/') assert resolved.func.__name__ == default.LocationDetail.__name__ assert resolved.kwargs['organization'] == 'org-slug' assert resolved.kwargs['project'] == 'proj-slug' assert resolved.kwargs['location'] == 'abc123'