當前位置: 首頁>>代碼示例>>Python>>正文


Python urlresolvers.resolve方法代碼示例

本文整理匯總了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 
開發者ID:lmco,項目名稱:dart,代碼行數:19,代碼來源:views.py

示例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 
開發者ID:82Flex,項目名稱:DCRM,代碼行數:21,代碼來源:suit_menu.py

示例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') 
開發者ID:OpenAgricultureFoundation,項目名稱:gro-api,代碼行數:27,代碼來源:serializers.py

示例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' 
開發者ID:Cadasta,項目名稱:cadasta-platform,代碼行數:18,代碼來源:test_urls_default.py

示例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' 
開發者ID:Cadasta,項目名稱:cadasta-platform,代碼行數:19,代碼來源:test_urls_api.py

示例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' 
開發者ID:Cadasta,項目名稱:cadasta-platform,代碼行數:18,代碼來源:test_urls_api.py

示例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' 
開發者ID:Cadasta,項目名稱:cadasta-platform,代碼行數:20,代碼來源:test_urls_api.py

示例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' 
開發者ID:Cadasta,項目名稱:cadasta-platform,代碼行數:18,代碼來源:test_urls_default.py

示例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' 
開發者ID:Cadasta,項目名稱:cadasta-platform,代碼行數:18,代碼來源:test_urls_default.py

示例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' 
開發者ID:Cadasta,項目名稱:cadasta-platform,代碼行數:18,代碼來源:test_urls_default.py

示例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' 
開發者ID:Cadasta,項目名稱:cadasta-platform,代碼行數:18,代碼來源:test_urls_default.py

示例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' 
開發者ID:Cadasta,項目名稱:cadasta-platform,代碼行數:19,代碼來源:test_urls_default.py

示例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' 
開發者ID:Cadasta,項目名稱:cadasta-platform,代碼行數:19,代碼來源:test_urls_default.py

示例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' 
開發者ID:Cadasta,項目名稱:cadasta-platform,代碼行數:19,代碼來源:test_urls_default.py

示例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' 
開發者ID:Cadasta,項目名稱:cadasta-platform,代碼行數:19,代碼來源:test_urls_default.py


注:本文中的django.core.urlresolvers.resolve方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。