本文整理汇总了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')
),
)
示例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)
示例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')))
示例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)
示例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')
),
)
示例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)
示例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)
示例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
示例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'])
示例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
示例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")
示例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),
]
示例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
示例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))
示例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)),
]