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


Python routers.ExtendedSimpleRouter類代碼示例

本文整理匯總了Python中rest_framework_extensions.routers.ExtendedSimpleRouter的典型用法代碼示例。如果您正苦於以下問題:Python ExtendedSimpleRouter類的具體用法?Python ExtendedSimpleRouter怎麽用?Python ExtendedSimpleRouter使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


在下文中一共展示了ExtendedSimpleRouter類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: test_nested_route

    def test_nested_route(self):
        router = ExtendedSimpleRouter()
        (
            router.register(r'users', UserViewSet, 'user')
                  .register(r'groups', GroupViewSet, 'users-group', parents_query_lookups=['user'])
        )

        # test user list
        self.assertEqual(router.urls[0].name, 'user-list')
        self.assertEqual(router.urls[0]._regex, r'^users/$')

        # test user detail
        self.assertEqual(router.urls[1].name, 'user-detail')
        self.assertEqual(router.urls[1]._regex, r'^users/{0}/$'.format(self.get_lookup_regex('pk')))

        # test users group list
        self.assertEqual(router.urls[2].name, 'users-group-list')
        self.assertEqual(router.urls[2]._regex, r'^users/{0}/groups/$'.format(
                self.get_parent_lookup_regex('user')
            )
        )

        # test users group detail
        self.assertEqual(router.urls[3].name, 'users-group-detail')
        self.assertEqual(router.urls[3]._regex, r'^users/{0}/groups/{1}/$'.format(
                self.get_parent_lookup_regex('user'),
                self.get_lookup_regex('pk')
            ),
        )
開發者ID:AdrianRibao,項目名稱:drf-extensions,代碼行數:29,代碼來源:tests.py

示例2: test_urls_have_trailing_slash_by_default

    def test_urls_have_trailing_slash_by_default(self):
        router = ExtendedSimpleRouter()
        router.register(r'router-viewset', RouterViewSet)
        urls = router.urls

        for exp in ['^router-viewset/$',
                    '^router-viewset/(?P<pk>[^/.]+)/$',
                    '^router-viewset/list_controller/$',
                    '^router-viewset/(?P<pk>[^/.]+)/detail_controller/$']:
            msg = 'Should find url pattern with regexp %s' % exp
            self.assertIsNotNone(get_url_pattern_by_regex_pattern(urls, exp), msg=msg)
開發者ID:chibisov,項目名稱:drf-extensions,代碼行數:11,代碼來源:tests.py

示例3: test_one_route

    def test_one_route(self):
        router = ExtendedSimpleRouter()
        router.register(r'users', UserViewSet, 'user')

        # test user list
        self.assertEqual(router.urls[0].name, 'user-list')
        self.assertEqual(router.urls[0]._regex, r'^users/$')

        # test user detail
        self.assertEqual(router.urls[1].name, 'user-detail')
        self.assertEqual(router.urls[1]._regex, r'^users/{0}/$'.format(self.get_lookup_regex('pk')))
開發者ID:AdrianRibao,項目名稱:drf-extensions,代碼行數:11,代碼來源:tests.py

示例4: test_urls_have_trailing_slash_by_default

    def test_urls_have_trailing_slash_by_default(self):
        router = ExtendedSimpleRouter()
        router.register(r'router-viewset', RouterViewSet)
        urls = router.urls

        lookup_allowed_symbols = get_lookup_allowed_symbols()

        for exp in ['^router-viewset/$',
                    '^router-viewset/{0}/$'.format(lookup_allowed_symbols),
                    '^router-viewset/list_controller/$',
                    '^router-viewset/{0}/detail_controller/$'.format(lookup_allowed_symbols)]:
            msg = 'Should find url pattern with regexp %s' % exp
            self.assertIsNotNone(get_url_pattern_by_regex_pattern(urls, exp), msg=msg)
開發者ID:Tim-Erwin,項目名稱:drf-extensions,代碼行數:13,代碼來源:tests.py

示例5: test_nested_route_depth_3

    def test_nested_route_depth_3(self):
        router = ExtendedSimpleRouter()
        (
            router.register(r'users', UserViewSet, 'user')
                  .register(r'groups', GroupViewSet, 'users-group', parents_query_lookups=['user'])
                  .register(r'permissions', PermissionViewSet, 'users-groups-permission', parents_query_lookups=[
                               'group__user',
                               'group',
                            ]
                  )
        )

        # test user list
        self.assertEqual(router.urls[0].name, 'user-list')
        self.assertEqual(router.urls[0]._regex, r'^users/$')

        # test user detail
        self.assertEqual(router.urls[1].name, 'user-detail')
        self.assertEqual(router.urls[1]._regex, r'^users/{0}/$'.format(self.get_lookup_regex('pk')))

        # test users group list
        self.assertEqual(router.urls[2].name, 'users-group-list')
        self.assertEqual(router.urls[2]._regex, r'^users/{0}/groups/$'.format(
                self.get_parent_lookup_regex('user')
            )
        )

        # test users group detail
        self.assertEqual(router.urls[3].name, 'users-group-detail')
        self.assertEqual(router.urls[3]._regex, r'^users/{0}/groups/{1}/$'.format(
                self.get_parent_lookup_regex('user'),
                self.get_lookup_regex('pk')
            ),
        )

        # test users groups permission list
        self.assertEqual(router.urls[4].name, 'users-groups-permission-list')
        self.assertEqual(router.urls[4]._regex, r'^users/{0}/groups/{1}/permissions/$'.format(
                self.get_parent_lookup_regex('group__user'),
                self.get_parent_lookup_regex('group'),
            )
        )

        # test users groups permission detail
        self.assertEqual(router.urls[5].name, 'users-groups-permission-detail')
        self.assertEqual(router.urls[5]._regex, r'^users/{0}/groups/{1}/permissions/{2}/$'.format(
                self.get_parent_lookup_regex('group__user'),
                self.get_parent_lookup_regex('group'),
                self.get_lookup_regex('pk')
            ),
        )
開發者ID:AdrianRibao,項目名稱:drf-extensions,代碼行數:51,代碼來源:tests.py

示例6: test_urls_can_have_trailing_slash_removed

    def test_urls_can_have_trailing_slash_removed(self):
        router = ExtendedSimpleRouter(trailing_slash=False)
        router.register(r'router-viewset', RouterViewSet)
        urls = router.urls

        lookup_allowed_symbols = get_lookup_allowed_symbols(
            force_dot=get_rest_framework_features()['allow_dot_in_lookup_regex_without_trailing_slash']
        )

        for exp in ['^router-viewset$',
                    '^router-viewset/{0}$'.format(lookup_allowed_symbols),
                    '^router-viewset/list_controller$',
                    '^router-viewset/{0}/detail_controller$'.format(lookup_allowed_symbols)]:
            msg = 'Should find url pattern with regexp %s' % exp
            self.assertIsNotNone(get_url_pattern_by_regex_pattern(urls, exp), msg=msg)
開發者ID:Tim-Erwin,項目名稱:drf-extensions,代碼行數:15,代碼來源:tests.py

示例7: test_urls_can_have_trailing_slash_removed

    def test_urls_can_have_trailing_slash_removed(self):
        router = ExtendedSimpleRouter(trailing_slash=False)
        router.register(r'router-viewset', RouterViewSet)
        urls = router.urls

        if get_rest_framework_features()['allow_dot_in_lookup_regex_without_trailing_slash']:
            lookup_allowed_symbols = '(?P<pk>[^/.]+)'
        else:
            lookup_allowed_symbols = '(?P<pk>[^/]+)'

        for exp in ['^router-viewset$',
                    '^router-viewset/' + lookup_allowed_symbols + r'$',
                    '^router-viewset/list_controller$',
                    '^router-viewset/' + lookup_allowed_symbols + '/detail_controller$']:
            msg = 'Should find url pattern with regexp %s' % exp
            self.assertIsNotNone(get_url_pattern_by_regex_pattern(urls, exp), msg=msg)
開發者ID:Bazzinga,項目名稱:drf-extensions,代碼行數:16,代碼來源:tests.py

示例8: import

# -*- coding: utf-8 -*-
from rest_framework_extensions.routers import ExtendedSimpleRouter

from .views import (
    UserViewSet,
    GroupViewSet,
    PermissionViewSet,
)


router = ExtendedSimpleRouter()
# main routes
(
    router.register(r'users', UserViewSet)
          .register(r'groups', GroupViewSet, 'users-group', parents_query_lookups=['user_groups'])
          .register(r'permissions', PermissionViewSet, 'users-groups-permission', parents_query_lookups=['group__user', 'group'])
)

# register on one depth
permissions_routes = router.register(r'permissions', PermissionViewSet)
permissions_routes.register(r'groups', GroupViewSet, 'permissions-group', parents_query_lookups=['permissions'])
permissions_routes.register(r'users', UserViewSet, 'permissions-user', parents_query_lookups=['groups__permissions'])

# simple routes
router.register(r'groups', GroupViewSet, 'group')
router.register(r'permissions', PermissionViewSet, 'permission')

urlpatterns = router.urls
開發者ID:raphendyr,項目名稱:drf-extensions,代碼行數:28,代碼來源:urls.py

示例9: url

        r'^{course_id}$'.format(course_id=COURSE_ID_PATTERN),
        publication_views.AtomicPublicationView.as_view(),
        name='update'
    ),
]

urlpatterns = [
    url(r'^baskets/', include(BASKET_URLS, namespace='baskets')),
    url(r'^checkout/$', include(CHECKOUT_URLS, namespace='checkout')),
    url(r'^coupons/', include(COUPON_URLS, namespace='coupons')),
    url(r'^payment/', include(PAYMENT_URLS, namespace='payment')),
    url(r'^refunds/', include(REFUND_URLS, namespace='refunds')),
    url(r'^publication/', include(ATOMIC_PUBLICATION_URLS, namespace='publication')),
]

router = ExtendedSimpleRouter()
router.register(r'courses', course_views.CourseViewSet) \
    .register(r'products', product_views.ProductViewSet,
              base_name='course-product', parents_query_lookups=['course_id'])
router.register(r'partners', partner_views.PartnerViewSet) \
    .register(r'products', product_views.ProductViewSet,
              base_name='partner-product', parents_query_lookups=['stockrecords__partner_id'])
router.register(r'partners', partner_views.PartnerViewSet) \
    .register(r'catalogs', catalog_views.CatalogViewSet,
              base_name='partner-catalogs', parents_query_lookups=['partner_id'])
router.register(r'products', product_views.ProductViewSet)
router.register(r'stockrecords', stockrecords_views.StockRecordViewSet, base_name='stockrecords')

router.register(r'catalogs', catalog_views.CatalogViewSet) \
    .register(r'products', product_views.ProductViewSet, base_name='catalog-product',
              parents_query_lookups=['stockrecords__catalogs'])
開發者ID:BehavioralInsightsTeam,項目名稱:ecommerce,代碼行數:31,代碼來源:urls.py

示例10: import

from rest_framework_extensions.routers import ExtendedSimpleRouter

from .views import (
    TaskViewSet,
    TaskCommentViewSet,
    BookViewSet,
    BookCommentViewSet
)


router = ExtendedSimpleRouter()
# tasks route
(
    router.register(r'tasks', TaskViewSet)
          .register(r'comments', TaskCommentViewSet, 'tasks-comment', parents_query_lookups=['object_id'])
)
# books route
(
    router.register(r'books', BookViewSet)
          .register(r'comments', BookCommentViewSet, 'books-comment', parents_query_lookups=['object_id'])
)

urlpatterns = router.urls
開發者ID:chibisov,項目名稱:drf-extensions,代碼行數:23,代碼來源:urls_generic_relations.py

示例11: url

    url(
        r"^{course_id}$".format(course_id=COURSE_ID_PATTERN),
        publication_views.AtomicPublicationView.as_view(),
        name="update",
    ),
]

urlpatterns = [
    url(r"^baskets/", include(BASKET_URLS, namespace="baskets")),
    url(r"^coupons/", include(COUPON_URLS, namespace="coupons")),
    url(r"^payment/", include(PAYMENT_URLS, namespace="payment")),
    url(r"^refunds/", include(REFUND_URLS, namespace="refunds")),
    url(r"^publication/", include(ATOMIC_PUBLICATION_URLS, namespace="publication")),
]

router = ExtendedSimpleRouter()
router.register(r"courses", course_views.CourseViewSet).register(
    r"products", product_views.ProductViewSet, base_name="course-product", parents_query_lookups=["course_id"]
)
router.register(r"partners", partner_views.PartnerViewSet).register(
    r"products",
    product_views.ProductViewSet,
    base_name="partner-product",
    parents_query_lookups=["stockrecords__partner_id"],
)
router.register(r"partners", partner_views.PartnerViewSet).register(
    r"catalogs", catalog_views.CatalogViewSet, base_name="partner-catalogs", parents_query_lookups=["partner_id"]
)
router.register(r"products", product_views.ProductViewSet)
router.register(r"stockrecords", stockrecords_views.StockRecordViewSet, base_name="stockrecords")
開發者ID:fghaas,項目名稱:edx-ecommerce,代碼行數:30,代碼來源:urls.py

示例12: import

#!/usr/bin/env python
# -*- coding: utf-8 -*-
from django.conf.urls import include
from django.conf.urls import url
from django.contrib import admin

from rest_framework_extensions.routers import (
    ExtendedSimpleRouter as SimpleRouter
)

from project.applications.users.views import UserViewSet
from project.applications.authentication.views import AuthenticationViewSet
from project.applications.questions.views import QuestionViewSet, AnswerViewSet

api_router = SimpleRouter()
api_router.register(r'users', UserViewSet)
api_router.register(r'auth', AuthenticationViewSet)

qa_router = api_router.register(r'questions', QuestionViewSet)
qa_router.register(r'answers',
                   AnswerViewSet,
                   'question-answers',
                   parents_query_lookups=['id'])

urlpatterns = [
    url(r'^api/', include(api_router.urls)),
    url(r'^admin/', admin.site.urls),
]
開發者ID:davidvuong,項目名稱:healthshare-qa,代碼行數:28,代碼來源:urls.py

示例13: url

PAYMENT_URLS = [
    url(r"^processors/$", cache_page(60 * 30)(views.PaymentProcessorListView.as_view()), name="list_processors")
]

REFUND_URLS = [
    url(r"^$", views.RefundCreateView.as_view(), name="create"),
    url(r"^(?P<pk>[\d]+)/process/$", views.RefundProcessView.as_view(), name="process"),
]

ATOMIC_PUBLICATION_URLS = [
    url(r"^$", views.AtomicPublicationView.as_view(), name="create"),
    url(r"^{course_id}$".format(course_id=COURSE_ID_PATTERN), views.AtomicPublicationView.as_view(), name="update"),
]

urlpatterns = [
    url(r"^baskets/", include(BASKET_URLS, namespace="baskets")),
    url(r"^orders/", include(ORDER_URLS, namespace="orders")),
    url(r"^payment/", include(PAYMENT_URLS, namespace="payment")),
    url(r"^refunds/", include(REFUND_URLS, namespace="refunds")),
    url(r"^publication/", include(ATOMIC_PUBLICATION_URLS, namespace="publication")),
]

router = ExtendedSimpleRouter()
router.register(r"courses", views.CourseViewSet).register(
    r"products", views.ProductViewSet, base_name="course-product", parents_query_lookups=["course_id"]
)
router.register(r"products", views.ProductViewSet)

urlpatterns += router.urls
開發者ID:nikolicnikola,項目名稱:ecommerce,代碼行數:29,代碼來源:urls.py

示例14: PostListSerializer

        page = self.paginate_queryset(queryset)
        if page is not None:
            serializer = PostListSerializer(page, many=True)
            return self.get_paginated_response(serializer.data)

        serializer = NewsListSerializer(queryset, many=True)
        return Response(serializer.data)

    def retrieve(self, request, *args, **kwargs):
        instance = self.get_object()
        instance.add_view()
        serializer = self.get_serializer(instance)
        return Response(serializer.data)


router = ExtendedSimpleRouter()
router.register(r'^news', NewsViewset, 'news')
router.register(r'^stats', PostViewset, 'posts')


def news_list(request):
    news = News.objects.all()[:10]
    return render_to_response('ajax_templates/blog/news_list.html', {'news': news},
                              context_instance=RequestContext(request))


def news_retrieve(request, slug):
    news = get_object_or_404(News, slug=slug)
    return render_to_response('ajax_templates/blog/news_retrieve.html', {'data': news},
                              context_instance=RequestContext(request))
開發者ID:Shaper2111,項目名稱:maes,代碼行數:30,代碼來源:views.py

示例15: ExtendedSimpleRouter

from django.conf.urls import url, include
from django.contrib import admin
from django.contrib.auth.models import User
from rest_framework import routers, serializers, viewsets, permissions
from rest_framework_extensions.routers import ExtendedSimpleRouter
from app.views import *
from app import models

router = ExtendedSimpleRouter()
(
    router.register(r'events', EventViewSet, base_name='events')
          .register(r'attractions',
                    AttractionViewSet,
                    base_name='events-attractions',
                    parents_query_lookups=['event_id'])
)

router.register(r'categories', create_model_view_set(Category), base_name='categories')

urlpatterns = [
    url(r'^admin/', admin.site.urls),
    url(r'^api-auth/', include('rest_framework.urls', namespace='rest_framework')),
    url(r'^reactions/', ReactionView.as_view()),
    url(r'^', include(router.urls)),
]
開發者ID:marconvcm,項目名稱:eventbox,代碼行數:25,代碼來源:urls.py


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