Пример #1
0
class TestNestedSimpleRouter(TestCase):
    def setUp(self):
        self.router = SimpleRouter()
        self.router.register(r'a', AViewSet)
        self.a_router = NestedSimpleRouter(self.router, r'a', lookup='a')
        self.a_router.register(r'b', BViewSet)
        self.b_router = NestedSimpleRouter(self.a_router, r'b', lookup='b')
        self.b_router.register(r'c', CViewSet)

    def test_recursive_nested_simple_routers(self):
        self.assertFalse(hasattr(self.router, 'parent_regex'))
        urls = self.router.urls
        self.assertEquals(len(urls), 2)
        self.assertEquals(urls[0].regex.pattern, u'^a/$')
        self.assertEquals(urls[1].regex.pattern, u'^a/(?P<pk>[0-9a-f]{32})/$')

        self.assertEqual(self.a_router.parent_regex,
                         u'a/(?P<a_pk>[0-9a-f]{32})/')
        urls = self.a_router.urls
        self.assertEquals(len(urls), 2)
        self.assertEquals(urls[0].regex.pattern,
                          u'^a/(?P<a_pk>[0-9a-f]{32})/b/$')
        self.assertEquals(urls[1].regex.pattern,
                          u'^a/(?P<a_pk>[0-9a-f]{32})/b/(?P<pk>[^/.]+)/$')

        self.assertEqual(self.b_router.parent_regex,
                         u'a/(?P<a_pk>[0-9a-f]{32})/b/(?P<b_pk>[^/.]+)/')
        urls = self.b_router.urls
        self.assertEquals(len(urls), 2)
        self.assertEquals(urls[0].regex.pattern,
                          u'^a/(?P<a_pk>[0-9a-f]{32})/b/(?P<b_pk>[^/.]+)/c/$')
        self.assertEquals(
            urls[1].regex.pattern,
            u'^a/(?P<a_pk>[0-9a-f]{32})/b/(?P<b_pk>[^/.]+)/c/(?P<pk>[^/.]+)/$')
Пример #2
0
 def _attach_nested_custom_fields(self, prefix, viewset, base_name):
     """
     Creates dedicated viewset for nested customfields in context of
     particular model.
     """
     # cyclic imports, meh
     from .viewsets import ObjectCustomFieldsViewSet
     from ralph.api.viewsets import RalphAPIViewSet
     model = viewset.queryset.model
     custom_fields_related_viewset = type(
         '{}CustomFieldsViewSet'.format(model._meta.object_name),
         (ObjectCustomFieldsViewSet, RalphAPIViewSet),
         {'related_model': model})
     # notice that, although it's custom fields (nested) resource,
     # for every model separated (nested) router is created!
     nested_router = NestedSimpleRouter(
         self,
         prefix,
         lookup=custom_fields_related_viewset.related_model_router_lookup)
     nested_router.register(
         self.nested_resource_prefix,
         custom_fields_related_viewset,
         base_name=self.nested_resource_base_name.format(base_name),
     )
     self.nested_registry.append(nested_router)
def test_drf_nested_routers_basic_example_variation(no_warnings):
    from rest_framework_nested.routers import NestedSimpleRouter

    class RootViewSet(viewsets.ModelViewSet):
        queryset = Root.objects.all()
        serializer_class = RootSerializer
        lookup_value_regex = "[0-9]+"

    class ChildViewSet(viewsets.ModelViewSet):
        serializer_class = ChildSerializer

        def get_queryset(self):
            return Child.objects.filter(id=self.kwargs.get("parent_pk"))

    router = routers.SimpleRouter()
    router.register('root', RootViewSet, basename='root')

    root_router = NestedSimpleRouter(router, r'root', lookup='parent')
    root_router.register(r'child', ChildViewSet, basename='child')

    urlpatterns = [
        path(r'', include(router.urls)),
        path(r'', include(root_router.urls)),
    ]
    generate_schema(None, patterns=urlpatterns)
Пример #4
0
    def test_explicit_no_trailing_slash(self):
        router = SimpleRouter(trailing_slash=True)
        router.register('a', AViewSet)
        a_router = NestedSimpleRouter(router, 'a', lookup='a', trailing_slash=False)
        a_router.register('b', BViewSet)

        self._assertDoesNotHaveTrailingSlash(a_router)
Пример #5
0
class TestNestedSimpleRouter(TestCase):
    def setUp(self):
        self.router = SimpleRouter()
        self.router.register(r'a', AViewSet)
        self.a_router = NestedSimpleRouter(self.router, r'a', lookup='a')
        self.a_router.register(r'b', BViewSet)
        self.b_router = NestedSimpleRouter(self.a_router, r'b', lookup='b')
        self.b_router.register(r'c', CViewSet)

    def test_recursive_nested_simple_routers(self):
        self.assertFalse(hasattr(self.router, 'parent_regex'))
        urls = self.router.urls
        self.assertEquals(len(urls), 2)
        self.assertEquals(urls[0].regex.pattern, u'^a/$')
        self.assertEquals(urls[1].regex.pattern, u'^a/(?P<pk>[0-9a-f]{32})/$')

        self.assertEqual(self.a_router.parent_regex, u'a/(?P<a_pk>[0-9a-f]{32})/')
        urls = self.a_router.urls
        self.assertEquals(len(urls), 2)
        self.assertEquals(urls[0].regex.pattern, u'^a/(?P<a_pk>[0-9a-f]{32})/b/$')
        self.assertEquals(urls[1].regex.pattern, u'^a/(?P<a_pk>[0-9a-f]{32})/b/(?P<pk>[^/.]+)/$')

        self.assertEqual(self.b_router.parent_regex, u'a/(?P<a_pk>[0-9a-f]{32})/b/(?P<b_pk>[^/.]+)/')
        urls = self.b_router.urls
        self.assertEquals(len(urls), 2)
        self.assertEquals(urls[0].regex.pattern, u'^a/(?P<a_pk>[0-9a-f]{32})/b/(?P<b_pk>[^/.]+)/c/$')
        self.assertEquals(urls[1].regex.pattern, u'^a/(?P<a_pk>[0-9a-f]{32})/b/(?P<b_pk>[^/.]+)/c/(?P<pk>[^/.]+)/$')
    class TestNestedSimpleRouter(TestCase):
        def setUp(self):
            self.router = SimpleRouter()
            self.router.register(r'detail', DetailRouteViewSet)
            self.detail_router = NestedSimpleRouter(
                self.router,
                r'detail',
                lookup='detail'
            )
            self.detail_router.register(r'list', ListRouteViewSet)
            self.list_router = NestedSimpleRouter(
                self.detail_router,
                r'list',
                lookup='list'
            )

        def test_dynamic_routes(self):
            self.assertFalse(hasattr(self.router, 'parent_regex'))
            urls = map_by_name(self.router.urls)
            self.assertEquals(
                get_regex_pattern(urls['basicmodel-list']), u'^detail/$'
            )
            self.assertEquals(
                get_regex_pattern(urls['basicmodel-detail']),
                u'^detail/(?P<pk>[^/.]+)/$'
            )
            self.assertEquals(
                get_regex_pattern(urls['basicmodel-set-password']),
                u'^detail/(?P<pk>[^/.]+)/set_password/$'
            )

        def test_nested_parent(self):
            self.assertEqual(
                self.detail_router.parent_regex,
                u'detail/(?P<detail_pk>[^/.]+)/'
            )
            urls = map_by_name(self.detail_router.urls)

            self.assertEquals(
                get_regex_pattern(urls['basicmodel-list']),
                u'^detail/(?P<detail_pk>[^/.]+)/list/$'
            )

            self.assertEquals(
                get_regex_pattern(urls['basicmodel-recent-users']),
                u'^detail/(?P<detail_pk>[^/.]+)/list/recent_users/$'
            )

            self.assertEquals(
                get_regex_pattern(urls['basicmodel-detail']),
                u'^detail/(?P<detail_pk>[^/.]+)/list/(?P<pk>[^/.]+)/$'
            )

        def test_nested_child(self):
            self.assertEqual(
                self.list_router.parent_regex,
                u'detail/(?P<detail_pk>[^/.]+)/list/(?P<list_pk>[^/.]+)/'
            )
    class TestNestedSimpleRouter(TestCase):
        def setUp(self):
            self.router = SimpleRouter()
            self.router.register(r'detail', DetailRouteViewSet)
            self.detail_router = NestedSimpleRouter(
                self.router,
                r'detail',
                lookup='detail'
            )
            self.detail_router.register(r'list', ListRouteViewSet)
            self.list_router = NestedSimpleRouter(
                self.detail_router,
                r'list',
                lookup='list'
            )

        def test_dynamic_routes(self):
            self.assertFalse(hasattr(self.router, 'parent_regex'))
            urls = map_by_name(self.router.urls)
            self.assertEquals(
                get_regex_pattern(urls['basicmodel-list']), u'^detail/$'
            )
            self.assertEquals(
                get_regex_pattern(urls['basicmodel-detail']),
                u'^detail/(?P<pk>[^/.]+)/$'
            )
            self.assertEquals(
                get_regex_pattern(urls['basicmodel-set-password']),
                u'^detail/(?P<pk>[^/.]+)/set_password/$'
            )

        def test_nested_parent(self):
            self.assertEqual(
                self.detail_router.parent_regex,
                u'detail/(?P<detail_pk>[^/.]+)/'
            )
            urls = map_by_name(self.detail_router.urls)

            self.assertEquals(
                get_regex_pattern(urls['basicmodel-list']),
                u'^detail/(?P<detail_pk>[^/.]+)/list/$'
            )

            self.assertEquals(
                get_regex_pattern(urls['basicmodel-recent-users']),
                u'^detail/(?P<detail_pk>[^/.]+)/list/recent_users/$'
            )

            self.assertEquals(
                get_regex_pattern(urls['basicmodel-detail']),
                u'^detail/(?P<detail_pk>[^/.]+)/list/(?P<pk>[^/.]+)/$'
            )

        def test_nested_child(self):
            self.assertEqual(
                self.list_router.parent_regex,
                u'detail/(?P<detail_pk>[^/.]+)/list/(?P<list_pk>[^/.]+)/'
            )
Пример #8
0
class TestBadLookupValue(TestCase):
    def setUp(self):
        self.router = SimpleRouter()
        self.router.register(r'parents', AViewSet, base_name='ui-parent_1')

    def test_bad_lookup(self):
        with self.assertRaises(ValueError):
            self.a_router = NestedSimpleRouter(self.router, r'parents', lookup='ui-parent_2')
            self.a_router.register(r'child', BViewSet, base_name='ui-parent-child')
Пример #9
0
class TestBadLookupValue(TestCase):
    def setUp(self):
        self.router = SimpleRouter()
        self.router.register(r'parents', AViewSet, base_name='ui-parent_1')

    def test_bad_lookup(self):
        with self.assertRaises(ValueError):
            self.a_router = NestedSimpleRouter(self.router, r'parents', lookup='ui-parent_2')
            self.a_router.register(r'child', BViewSet, base_name='ui-parent-child')
Пример #10
0
    def test_explicit_no_trailing_slash(self):
        router = SimpleRouter(trailing_slash=True)
        router.register('a', AViewSet)
        a_router = NestedSimpleRouter(router,
                                      'a',
                                      lookup='a',
                                      trailing_slash=False)
        a_router.register('b', BViewSet)

        self._assertDoesNotHaveTrailingSlash(a_router)
Пример #11
0
    def test_inherits_trailing_slash(self):
        """
        Test whether the trailing_slash=False value is inherited when it
        is unspecified on the nested router.
        """
        router = SimpleRouter(trailing_slash=True)
        router.register('a', AViewSet)
        a_router = NestedSimpleRouter(router, 'a', lookup='a')
        a_router.register('b', BViewSet)

        self._assertHasTrailingSlash(a_router)
Пример #12
0
    def test_explicit_trailing_slash(self):
        """
        Test whether the trailing_slash=False value is properly overridden when setting
        trailing_slash=True on the nested router.
        """
        router = SimpleRouter(trailing_slash=False)
        router.register('a', AViewSet)
        a_router = NestedSimpleRouter(router, 'a', lookup='a', trailing_slash=True)
        a_router.register('b', BViewSet)

        self._assertHasTrailingSlash(a_router)
Пример #13
0
    def test_inherits_trailing_slash(self):
        """
        Test whether the trailing_slash=False value is inherited when it
        is unspecified on the nested router.
        """
        router = SimpleRouter(trailing_slash=True)
        router.register('a', AViewSet)
        a_router = NestedSimpleRouter(router, 'a', lookup='a')
        a_router.register('b', BViewSet)

        self._assertHasTrailingSlash(a_router)
Пример #14
0
class TestEmptyPrefix(TestCase):
    def setUp(self):
        self.router = SimpleRouter()
        self.router.register(r'', AViewSet)
        self.a_router = NestedSimpleRouter(self.router, r'', lookup='a')
        self.a_router.register(r'b', BViewSet)

    def test_empty_prefix(self):
        urls = self.router.urls
        urls = self.a_router.urls
        self.assertEquals(len(urls), 2)
        self.assertEquals(get_regex_pattern(urls[0]), u'^(?P<a_pk>[0-9a-f]{32})/b/$')
        self.assertEquals(get_regex_pattern(urls[1]), u'^(?P<a_pk>[0-9a-f]{32})/b/(?P<pk>[^/.]+)/$')
Пример #15
0
class TestEmptyPrefix(TestCase):
    def setUp(self):
        self.router = SimpleRouter()
        self.router.register(r'', AViewSet)
        self.a_router = NestedSimpleRouter(self.router, r'', lookup='a')
        self.a_router.register(r'b', BViewSet)

    def test_empty_prefix(self):
        urls = self.router.urls
        urls = self.a_router.urls
        self.assertEquals(len(urls), 2)
        self.assertEquals(get_regex_pattern(urls[0]), u'^(?P<a_pk>[0-9a-f]{32})/b/$')
        self.assertEquals(get_regex_pattern(urls[1]), u'^(?P<a_pk>[0-9a-f]{32})/b/(?P<pk>[^/.]+)/$')
Пример #16
0
    def test_inherits_nonstandard_trailing_slash(self):
        """
        Test whether the trailing_slash attribute, when set with a custom value,
        is inherited by the nested routed.
        """
        router = SimpleRouter()
        router.trailing_slash = '/?'
        router.register('a', AViewSet)
        a_router = NestedSimpleRouter(router, 'a', lookup='a')
        a_router.register('b', BViewSet)

        self.assertEqual(a_router.trailing_slash, u'/?', "router does not have trailing slash when it should")
        self.assertTrue(pattern_from_url(a_router.urls[0]).endswith('/?$'),
                        "router created url without trailing slash when it should have")
Пример #17
0
    def test_explicit_trailing_slash(self):
        """
        Test whether the trailing_slash=False value is properly overridden when setting
        trailing_slash=True on the nested router.
        """
        router = SimpleRouter(trailing_slash=False)
        router.register('a', AViewSet)
        a_router = NestedSimpleRouter(router,
                                      'a',
                                      lookup='a',
                                      trailing_slash=True)
        a_router.register('b', BViewSet)

        self._assertHasTrailingSlash(a_router)
Пример #18
0
    def test_inherits_nonstandard_trailing_slash(self):
        """
        Test whether the trailing_slash attribute, when set with a custom value,
        is inherited by the nested routed.
        """
        router = SimpleRouter()
        router.trailing_slash = '/?'
        router.register('a', AViewSet)
        a_router = NestedSimpleRouter(router, 'a', lookup='a')
        a_router.register('b', BViewSet)

        self.assertEqual(a_router.trailing_slash, u'/?',
                         "router does not have trailing slash when it should")
        self.assertTrue(
            pattern_from_url(a_router.urls[0]).endswith('/?$'),
            "router created url without trailing slash when it should have")
Пример #19
0
    def register_nested(self, parent_prefix, prefix, viewset,
                        base_name=None, parent_lookup_name=None):
        """
        Register a nested viewset wihtout worrying of instantiate a nested
        router for registry.
        """
        kwargs = {
            'trailing_slash': bool(self.trailing_slash)
        }

        if parent_lookup_name is not None:
            kwargs.update(lookup=parent_lookup_name)

        nested_router = NestedSimpleRouter(
            self,
            parent_prefix,
            **kwargs
        )

        nested_router.register(prefix, viewset, base_name)
        self._nested_object_registry.append(nested_router)
Пример #20
0
    def register_nested(self,
                        parent_prefix,
                        prefix,
                        viewset,
                        base_name=None,
                        parent_lookup_name=None,
                        depth_level=1):
        """
        Register a nested viewset wihtout worrying of instantiate a nested
        router for registry.
        """
        kwargs = {'trailing_slash': bool(self.trailing_slash)}

        if parent_lookup_name is not None:
            kwargs.update(lookup=parent_lookup_name)

        # Section for the depth of the route and add more routes

        if depth_level > 1:
            routers = ifilter(
                lambda r:
                (r._depth_level ==
                 (depth_level - 1)) and r._nested_prefix == parent_prefix,
                self._nested_object_registry)

            try:
                parent_router = routers.next()
            except StopIteration:
                raise RuntimeError('parent registered resource not found')

        else:
            parent_router = self

        nested_router = NestedSimpleRouter(parent_router, parent_prefix,
                                           **kwargs)

        nested_router._nested_prefix = prefix
        nested_router._depth_level = depth_level
        nested_router.register(prefix, viewset, base_name)
        self._nested_object_registry.append(nested_router)
def test_drf_nested_routers_basic_example(no_warnings):
    from rest_framework_nested.routers import NestedSimpleRouter

    class RootViewSet(viewsets.ModelViewSet):
        serializer_class = RootSerializer
        queryset = Root.objects.all()

    class ChildViewSet(viewsets.ModelViewSet):
        serializer_class = ChildSerializer
        queryset = Child.objects.all()

    router = SimpleRouter()
    router.register('root', RootViewSet, basename='root')

    root_router = NestedSimpleRouter(router, r'root', lookup='parent')
    root_router.register(r'child', ChildViewSet, basename='child')

    urlpatterns = [
        re_path(r'^', include(router.urls)),
        re_path(r'^', include(root_router.urls)),
    ]
    schema = generate_schema(None, patterns=urlpatterns)
    assert_schema(schema, 'tests/contrib/test_drf_nested_routers.yml')
    assert schema
Пример #22
0
from django.urls import path, include
from rest_framework.routers import SimpleRouter
from rest_framework_nested.routers import NestedSimpleRouter

from accounts import views

router = SimpleRouter()
router.register(r'accounts', views.UserViewSet, basename='accounts')

notifications_router = NestedSimpleRouter(router, 'accounts', lookup='account')
notifications_router.register('notifications', views.UserNotificationsViewSet, basename='notifications')

urlpatterns = [
    path('', include(router.urls)),
    path('', include(notifications_router.urls))
]
Пример #23
0
from rest_framework.routers import DefaultRouter
from rest_framework_nested.routers import NestedSimpleRouter

from . import views
from ..accounts.urls import router as accounts_router

router = DefaultRouter()
router.register(r'weight_entries', views.WeightEntryViewSet)
router.register(r'exercise_score_entries', views.ExerciseScoreEntryViewSet)

user_entries_router = NestedSimpleRouter(accounts_router, r'users', lookup='user')
user_entries_router.register(
    'weight_entries',
    viewset=views.UserWeightEntryViewSet,
    basename='user-weight-entry'
)
user_entries_router.register(
    'exercise_entries',
    viewset=views.UserExerciseScoreEntryViewSet,
    basename='user-exercise-entry'
)

urlpatterns = router.urls + user_entries_router.urls
Пример #24
0
from rest_framework.routers import SimpleRouter
from rest_framework_nested.routers import NestedSimpleRouter

from mkt.extensions.views import (ExtensionSearchView, ExtensionVersionViewSet,
                                  ExtensionViewSet,
                                  ReviewerExtensionSearchView,
                                  ReviewersExtensionViewSet, ValidationViewSet)

extensions = SimpleRouter()
extensions.register(r'validation', ValidationViewSet,
                    base_name='extension-validation')
extensions.register(r'extension', ExtensionViewSet)
extensions.register(r'queue', ReviewersExtensionViewSet,
                    base_name='extension-queue')

# Router for children of /extensions/extension/{extension_pk}/.
sub_extensions = NestedSimpleRouter(
    extensions, r'extension', lookup='extension')
sub_extensions.register(r'versions', ExtensionVersionViewSet,
                        base_name='extension-version')


urlpatterns = patterns(
    '',
    url(r'', include(extensions.urls)),
    url(r'', include(sub_extensions.urls)),
    url(r'search/$', ExtensionSearchView.as_view(), name='extension-search'),
    url(r'search/reviewers/$', ReviewerExtensionSearchView.as_view(),
        name='extension-search-reviewers'),
)
Пример #25
0
from rest_framework_nested.routers import NestedSimpleRouter

from olympia.activity.views import VersionReviewNotesViewSet
from olympia.reviews.views import ReviewViewSet

from .views import (
    AddonFeaturedView, AddonSearchView, AddonVersionViewSet, AddonViewSet,
    StaticCategoryView)


addons = SimpleRouter()
addons.register(r'addon', AddonViewSet)

# Router for children of /addons/addon/{addon_pk}/.
sub_addons = NestedSimpleRouter(addons, r'addon', lookup='addon')
sub_addons.register('versions', AddonVersionViewSet, base_name='addon-version')
sub_addons.register('reviews', ReviewViewSet, base_name='addon-review')
sub_versions = NestedSimpleRouter(sub_addons, r'versions', lookup='version')
sub_versions.register(r'reviewnotes', VersionReviewNotesViewSet,
                      base_name='version-reviewnotes')

urlpatterns = patterns(
    '',
    url(r'', include(addons.urls)),
    url(r'', include(sub_addons.urls)),
    url(r'', include(sub_versions.urls)),
    url(r'^search/$', AddonSearchView.as_view(), name='addon-search'),
    url(r'^featured/$', AddonFeaturedView.as_view(), name='addon-featured'),
    url(r'^categories/$', StaticCategoryView.as_view(), name='category-list'),
)
Пример #26
0
from api.users import views as api_users_views

router = SimpleRouter()
router.register('users', api_users_views.UserViewSet)
router.register('teams', api_teams_views.TeamViewSet)
router.register('tasks', api_tasks_views.TaskViewSet)
router.register('task_tags', api_tasks_views.TaskTagViewSet)
router.register('task_files', api_tasks_views.TaskFileViewSet, basename='task_files')
router.register('task_hints', api_tasks_views.TaskHintViewSet)
router.register('posts', api_posts_views.PostViewSet)
router.register('contests', api_contests_views.ContestViewSet)
router.register('contest_participant_relationship', api_contests_views.ContestParticipantRelationshipViewSet)
router.register('contest_task_relationship', api_contests_views.ContestTaskRelationshipViewSet)

contests_router = NestedSimpleRouter(router, 'contests', lookup='contest')
contests_router.register('tasks', api_contests_views.ContestTaskViewSet)

urlpatterns = [
    re_path('^', include(router.urls)),
    re_path('^', include(contests_router.urls)),

    re_path('^register/$', api_users_views.UserCreateView.as_view(), name='registration_view'),

    re_path('^confirm_email/$',
            api_users_views.EmailConfirmationEndpointView.as_view(),
            name='email_confirmation_view'),

    re_path('^resend_confirmation/$',
            api_users_views.ActivationEmailResendView.as_view(),
            name='email_confirmation_resend_view'),
Пример #27
0
from django.conf.urls import include, url

from rest_framework.routers import SimpleRouter
from rest_framework_nested.routers import NestedSimpleRouter

from .views import (
    AddonReviewerViewSet, ReviewAddonVersionViewSet,
    ReviewAddonVersionCompareViewSet)


addons = SimpleRouter()
addons.register(r'addon', AddonReviewerViewSet, basename='reviewers-addon')

versions = NestedSimpleRouter(addons, r'addon', lookup='addon')
versions.register(
    r'versions', ReviewAddonVersionViewSet, basename='reviewers-versions')

compare = NestedSimpleRouter(versions, r'versions', lookup='version')
compare.register(
    r'compare_to', ReviewAddonVersionCompareViewSet,
    basename='reviewers-versions-compare')

urlpatterns = [
    url(r'', include(addons.urls)),
    url(r'', include(versions.urls)),
    url(r'', include(compare.urls)),
]
Пример #28
0
cs_router.register(r'layercategories', LayerCategoryViewSet)
cs_router.register(r'levels', AdminLevelViewSet)
cs_router.register(r'areas', AreaViewSet)
cs_router.register(r'publications', PublicationInCasestudyViewSet)
cs_router.register(r'aims', AimViewSet)
cs_router.register(r'userobjectives', UserObjectiveViewSet)
cs_router.register(r'challenges', ChallengeViewSet)
cs_router.register(r'wmsresources', WMSResourceInCasestudyViewSet)
cs_router.register(r'sections', SectionViewSet)
cs_router.register(r'consensuslevels', ConsensusViewSet)

# /casestudies/*/userobjectives/...
uo_router = NestedSimpleRouter(cs_router,
                               r'userobjectives',
                               lookup='userobjective')
uo_router.register(r'flowtargets', FlowTargetViewSet)

# /casestudies/*/layercategories/...
layercat_router = NestedSimpleRouter(cs_router,
                                     r'layercategories',
                                     lookup='layercategory')
layercat_router.register(r'layers', LayerViewSet)

# /casestudies/*/levels/...
levels_router = NestedSimpleRouter(cs_router, r'levels', lookup='level')
levels_router.register(r'areas', AreaInLevelViewSet)

# /casestudies/*/chartcategories/...
chart_router = NestedSimpleRouter(cs_router,
                                  r'chartcategories',
                                  lookup='chartcategory')
Пример #29
0
Class-based views
    1. Add an import:  from other_app.views import Home
    2. Add a URL to urlpatterns:  url(r'^$', Home.as_view(), name='home')
Including another URLconf
    1. Import the include() function: from django.conf.urls import url, include
    2. Add a URL to urlpatterns:  url(r'^blog/', include('blog.urls'))
"""

from django.conf.urls import url, include
from playlist import views
from rest_framework.routers import DefaultRouter 
from rest_framework_nested.routers import NestedSimpleRouter


# Create a router and register our viewsets with it.
router = DefaultRouter()
router.register(r'playlists', views.PlaylistViewSet)
router.register(r'tracks', views.TrackViewSet)
router.register(r'users', views.UserViewSet)

playlists_router = NestedSimpleRouter(router, r'playlists', lookup='playlist')
playlists_router.register(r'tracks', views.PlaylistTrackViewSet)

# The API URLs are now determined automatically by the router.
# Additionally, we include the login URLs for the browsable API.
urlpatterns = [
    url(r'^', include(router.urls)),
    url(r'^', include(playlists_router.urls)),
    url(r'^api-auth/', include('rest_framework.urls', namespace='rest_framework'))
]
Пример #30
0
    destroy = not_allowed

    def create(self, request, patch_pk):
        p = Patch.objects.get(id=patch_pk)
        if not p.is_editable(request.user):
            raise PermissionDenied()
        request.patch = p
        return super(CheckViewSet, self).create(request)

    def list(self, request, patch_pk):
        queryset = self.filter_queryset(self.get_queryset())
        queryset = queryset.filter(patch=patch_pk)

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

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


router = DefaultRouter()
router.register("patches", PatchViewSet, "patch")
router.register("people", PeopleViewSet, "person")
router.register("projects", ProjectViewSet, "project")
router.register("users", UserViewSet, "user")

patches_router = NestedSimpleRouter(router, r"patches", lookup="patch")
patches_router.register(r"checks", CheckViewSet, base_name="patch-checks")
Пример #31
0
from django.conf.urls import include, url

from rest_framework.routers import SimpleRouter
from rest_framework_nested.routers import NestedSimpleRouter

from olympia.bandwagon.views import CollectionAddonViewSet, CollectionViewSet

from . import views


accounts = SimpleRouter()
accounts.register(r'account', views.AccountViewSet, basename='account')

collections = NestedSimpleRouter(accounts, r'account', lookup='user')
collections.register(r'collections', CollectionViewSet,
                     basename='collection')
sub_collections = NestedSimpleRouter(collections, r'collections',
                                     lookup='collection')
sub_collections.register('addons', CollectionAddonViewSet,
                         basename='collection-addon')

notifications = NestedSimpleRouter(accounts, r'account', lookup='user')
notifications.register(r'notifications', views.AccountNotificationViewSet,
                       basename='notification')

urlpatterns = [
    url(r'^authenticate/$', views.AuthenticateView.as_view(),
        name='accounts.authenticate'),
    url(r'^login/start/$',
        views.LoginStartView.as_view(),
        name='accounts.login_start'),
Пример #32
0
from django.conf.urls import url
from rest_framework import routers
from rest_framework_nested.routers import NestedSimpleRouter
from . import views


urlpatterns = [
    url(r'^$', views.QuestionsListView.as_view(), name='questions_latest'),
    url(r'^best/$', views.BestQuestionsListView.as_view(), name='questions_best'),
    url(r'^unanswered/$', views.UnansweredQuestionsListView.as_view(), name='questions_unanswered'),
    url(r'^bytag/(?P<pk>[0-9]+)/$', views.ByTagIdQuestionsListView.as_view(), name='questions_by_tag_id'),
    url(r'^(?P<pk>[0-9]+)/$', views.QuestionsDetailView.as_view(), name='questions_detail'),
    url(r'^add_question/$', views.AddQuestionView.as_view(), name='add_question'),
]

router = routers.SimpleRouter()
router.register(r'questions', views.QuestionsViewSet, base_name='questions')
router.register(r'comments', views.CommentsViewSet, base_name='comments')

answers_router = NestedSimpleRouter(router, r'questions', lookup='question')
answers_router.register(r'answers', views.AnswersViewSet, base_name='answers')


urlpatterns += router.urls
urlpatterns += answers_router.urls
Пример #33
0
    TranscriptomeModelViewSet,
    DataFileViewSet,
    CovarianceViewSet,
)


# Create a router and register our viewsets with it.
router = DefaultRouter()

read_only_router = ReadOnlyRouter()
read_only_router.register("users", SimpleUserViewSet, "user")
read_only_router.register("transcriptomes", TranscriptomeModelViewSet, "transcriptome")
read_only_router.register("covariances", CovarianceViewSet, "covariance")

user_router = NestedSimpleRouter(read_only_router, r"users", lookup="user")
user_router.register(r"jobs", JobViewSet, base_name="jobs")

jobs_router = NestedSimpleRouter(user_router, r"jobs", lookup="job")
jobs_router.register(r"files", DataFileViewSet, base_name="")

urlpatterns = [
    url(r"^", include(router.urls)),
    url(r"^", include(read_only_router.urls)),
    url(r"^", include(user_router.urls)),
    url(r"^", include(jobs_router.urls)),
    url(r"^signup/$", CreateUserView.as_view()),
    url(r"^login/$", LoginView.as_view()),
]

# TODO: remove
urlpatterns += [url(r"^api-auth/", include("rest_framework.urls", namespace="rest_framework"))]
Пример #34
0
from django.conf.urls import include
from django.urls import re_path

from rest_framework.routers import SimpleRouter
from rest_framework_nested.routers import NestedSimpleRouter

from olympia.bandwagon.views import CollectionAddonViewSet, CollectionViewSet

from . import views

accounts = SimpleRouter()
accounts.register(r'account', views.AccountViewSet, basename='account')

collections = NestedSimpleRouter(accounts, r'account', lookup='user')
collections.register(r'collections', CollectionViewSet, basename='collection')
sub_collections = NestedSimpleRouter(collections,
                                     r'collections',
                                     lookup='collection')
sub_collections.register('addons',
                         CollectionAddonViewSet,
                         basename='collection-addon')

notifications = NestedSimpleRouter(accounts, r'account', lookup='user')
notifications.register(r'notifications',
                       views.AccountNotificationViewSet,
                       basename='notification')

accounts_v4 = [
    re_path(r'^login/start/$',
            views.LoginStartView.as_view(),
            name='accounts.login_start'),
Пример #35
0
from django.conf.urls import patterns, url, include

from rest_framework import routers
from rest_framework_nested.routers import NestedSimpleRouter

from . import views

router = routers.DefaultRouter()
router.register(r"category", views.CategoryViewSet)
router.register(r"eligibility_check", views.EligibilityCheckViewSet, base_name="eligibility_check")
router.register(r"case", views.CaseViewSet)

eligibility_check_router = NestedSimpleRouter(router, "eligibility_check", lookup="eligibility_check_")

eligibility_check_router.register(r"property", views.PropertyViewSet, base_name="property")

urlpatterns = patterns("", url(r"^", include(router.urls)), url(r"^", include(eligibility_check_router.urls)))
Пример #36
0
router.register("ambulance", AmbulanceViewSet)

router.register("patient", PatientViewSet)
router.register("consultation", PatientConsultationViewSet)

# Local Body / LSG Viewsets
router.register("state", StateViewSet)
router.register("district", DistrictViewSet)
router.register("local_body", LocalBodyViewSet)

# Patient Sample
router.register("test_sample", PatientSampleViewSet)

# Ref: https://github.com/alanjds/drf-nested-routers
facility_nested_router = NestedSimpleRouter(router, r"facility", lookup="facility")
facility_nested_router.register(r"hospital_doctor", HospitalDoctorViewSet)
facility_nested_router.register(r"capacity", FacilityCapacityViewSet)
facility_nested_router.register(r"patient_stats", FacilityPatientStatsHistoryViewSet)

patient_nested_router = NestedSimpleRouter(router, r"patient", lookup="patient")
patient_nested_router.register(r"test_sample", PatientSampleViewSet)

consultation_nested_router = NestedSimpleRouter(router, r"consultation", lookup="consultation")
consultation_nested_router.register(r"daily_rounds", DailyRoundsViewSet)

app_name = "api"
urlpatterns = [
    url(r"^", include(router.urls)),
    url(r"^", include(facility_nested_router.urls)),
    url(r"^", include(patient_nested_router.urls)),
    url(r"^", include(consultation_nested_router.urls)),
Пример #37
0
from django.conf.urls import include, url
from django.contrib import admin
from rest_framework.routers import DefaultRouter, SimpleRouter
from rest_framework_nested.routers import NestedSimpleRouter

from rest_framework.authtoken.views import obtain_auth_token
from django.conf import settings

from domains.views import DomainsViewSet, NestedRecordsViewSet, panel

domains_router = SimpleRouter(trailing_slash=False)
domains_router.register(r'domains', DomainsViewSet)


records_router = NestedSimpleRouter(domains_router, r'domains', lookup='domain', trailing_slash=False)
records_router.register(r'records', NestedRecordsViewSet, base_name='records')


urlpatterns = [

    url(r'^$', panel, name='panel'),

    url(r'^panel/$', panel, name='panel'),

    # Stock django auth forms
    url('^', include('django.contrib.auth.urls')),

    url(r'^api/', include(domains_router.urls)),
    url(r'^api/', include(records_router.urls)),

    url(r'^rest-auth/', include('rest_auth.urls')),
Пример #38
0
from rest_framework import routers
from rest_framework_nested.routers import NestedSimpleRouter

from . import views

router = routers.DefaultRouter()
router.register(r'muscle_groups', views.MuscleGroupViewSet)
router.register(r'exercises', views.ExerciseViewSet)
router.register(r'workouts', views.WorkoutViewSet, basename='workout')

exercises_router = NestedSimpleRouter(router, r'workouts', lookup='workout')
exercises_router.register(
    r'exercises',
    viewset=views.WorkoutExerciseViewSet,
    basename='workout-exercise'
)


urlpatterns = router.urls + exercises_router.urls
Пример #39
0
from django.contrib.auth.models import User
from rest_framework import routers, serializers, viewsets
from rest_framework_nested.routers import NestedSimpleRouter

from authentication.views import IndexView, LoginView, LogoutView

# Routers provide an easy way of automatically determining the URL conf.
router = routers.DefaultRouter()
router.register(r'accounts', AccountViewSet)
router.register(r'registration', RegistrationViewSet)
router.register(r'brewer', BrewerViewSet)
router.register(r'brews', BrewViewSet, 'Brew')
router.register(r'tastings', TastingViewSet)

accounts_router = NestedSimpleRouter(
    router, r'accounts', lookup='account'
)
accounts_router.register(r'brews', AccountBrewsViewSet)

urlpatterns = patterns(
    '',

    url(r'^api/v1/', include(router.urls)),
    url(r'^api/v1/', include(accounts_router.urls)),
    url(r'^api/v1/auth/login/$', LoginView.as_view(), name='login'),
    url(r'^api/v1/auth/logout/$', LogoutView.as_view(), name='logout'),
    url(r'^api-auth/', include('rest_framework.urls', namespace='rest_framework')),

    url('^.*$', IndexView.as_view(), name='index'),
)
Пример #40
0
# -*- coding: utf-8 -*-
from rest_framework_nested.routers import SimpleRouter, NestedSimpleRouter

# Custom
from .views import TaskListViewSet
from tasks.views import TaskViewSet


router = SimpleRouter()
router.register(r'list-tasks', TaskListViewSet, 'tasklist')


# For nested url
task_router = NestedSimpleRouter(router, r'list-tasks', lookup='tasklist')
task_router.register(r'tasks', TaskViewSet, 'task')
from django.contrib import admin
from rest_framework.urlpatterns import format_suffix_patterns
from buppli import api
from rest_framework.routers import DefaultRouter
from rest_framework_jwt.views import obtain_jwt_token, refresh_jwt_token
from rest_framework_nested.routers import NestedSimpleRouter
from buppli.views import IndexView, BucketListView, logout_view

router = DefaultRouter()
router.register(r'auth/register', api.UserViewSet)
router.register(r'bucketlists', api.BucketListViewSet)
router.register(r'public-bucketlist', api.PublicBucketListViewSet,
                base_name='public_bucketlist')
bucketlist_router = NestedSimpleRouter(router, r'bucketlists',
                                       lookup='bucketlist')
bucketlist_router.register(r'items', api.BucketListItemViewSet)

urlpatterns = [
    url(r'^$', IndexView.as_view()),
    url(r'^bucketlists$', BucketListView.as_view()),
    url(r'^logout$', logout_view),
    url(r'^api/v1/login/$', obtain_jwt_token, name='login'),
    url(r'^api/v1/login/refresh_token/$', refresh_jwt_token),
    url(r'^api/v1/', include(router.urls)),
    url(r'^api/v1/', include(bucketlist_router.urls)),
    url(r'^api/v1/docs/', include("rest_framework_swagger.urls")),
    url(r'^admin/', include(admin.site.urls)),
    url(r'^static/(?P<path>.*)$',
        django.views.static.serve, {'document_root': settings.STATIC_ROOT}),
]
Пример #42
0
from django.conf.urls import include, url
from rest_framework.authtoken import views
from rest_framework.routers import DefaultRouter
from rest_framework_nested.routers import NestedSimpleRouter

from api.views import (CustomerViewSet, ProviderViewSet, UserPreferenceViewSet,
                       UserViewSet, costs, instance_type, status, storage)

ROUTER = DefaultRouter()
ROUTER.register(r'customers', CustomerViewSet)
ROUTER.register(r'providers', ProviderViewSet)
ROUTER.register(r'users', UserViewSet)

USER_ROUTER = NestedSimpleRouter(ROUTER, r'users', lookup='user')
USER_ROUTER.register(r'preferences',
                     UserPreferenceViewSet,
                     base_name='preferences')

# pylint: disable=invalid-name
urlpatterns = [
    url(r'^token-auth/', views.obtain_auth_token, name='token-auth'),
    url(r'^status/$', status, name='server-status'),
    url(r'^reports/costs/$', costs, name='reports-costs'),
    url(r'^reports/inventory/instance-type/$',
        instance_type,
        name='reports-instance-type'),
    url(r'^reports/inventory/storage/$', storage, name='reports-storage'),
    url(r'^', include(ROUTER.urls)),
    url(r'^', include(USER_ROUTER.urls))
]
Пример #43
0
from django.urls import include, path
from rest_framework_nested.routers import DefaultRouter, NestedSimpleRouter

from .views import *

router = DefaultRouter()
router.register(r'cameras', CameraViewSet)
router.register(r'cafeterias', CafeteriaViewSet)
router.register(r'fixed_menu_reviews', FixedMenuOptionReviewViewSet)

cafeterias_router = NestedSimpleRouter(router,
                                       r'cafeterias',
                                       lookup='cafeteria')
cafeterias_router.register(r'fixed_menu_options',
                           FixedMenuOptionViewSet,
                           basename='cafeteria-fixed_menu_options')

fixed_menu_options_router = NestedSimpleRouter(cafeterias_router,
                                               r'fixed_menu_options',
                                               lookup='option')
fixed_menu_options_router.register(
    r'reviews',
    CafeteriaFixedMenuOptionReviewViewSet,
    basename='cafeteria-fixed_menu_options-review')

cameras_router = NestedSimpleRouter(router, r'cameras', lookup='camera')
cameras_router.register(r'events',
                        CameraEventsViewSet,
                        basename='camera_events')

urlpatterns = [
Пример #44
0
from django.conf.urls import include, url

from rest_framework.routers import SimpleRouter
from rest_framework_nested.routers import NestedSimpleRouter

from .views import (
    AddonReviewerViewSet, ReviewAddonVersionViewSet)


addons = SimpleRouter()
addons.register(r'addon', AddonReviewerViewSet, basename='reviewers-addon')

versions = NestedSimpleRouter(addons, r'addon', lookup='addon')
versions.register(
    r'versions', ReviewAddonVersionViewSet, basename='reviewers-versions')


urlpatterns = [
    url(r'', include(addons.urls)),
    url(r'', include(versions.urls)),
]
Пример #45
0
    2. Add a URL to urlpatterns:  path('', Home.as_view(), name='home')
Including another URLconf
    1. Import the include() function: from django.urls import include, path
    2. Add a URL to urlpatterns:  path('blog/', include('blog.urls'))
"""
from django.conf.urls import url
from django.contrib import admin
from django.urls import include, path
from polls.views import PollViewSet, QuestionViewSet, interactive_hook
from rest_framework_nested.routers import DefaultRouter, NestedSimpleRouter
from rest_framework_simplejwt.views import (
    TokenObtainPairView,
    TokenRefreshView,
)

router = DefaultRouter()
router.register(r'polls', PollViewSet)

poll_router = NestedSimpleRouter(router, r'polls', lookup='poll')
poll_router.register(r'questions', QuestionViewSet, basename='poll-questions')

# urlpatterns = router.urls
urlpatterns = (
    # url(r'^', include(router.urls)),
    # url(r'^', include(poll_router.urls)),
    path('', admin.site.urls),
    # url('api/token/', TokenObtainPairView.as_view(), name='token_obtain_pair'),
    # url('api/token/refresh/', TokenRefreshView.as_view(), name='token_refresh'),
    path('event/hook/', interactive_hook, name='event_hook'),
)
Пример #46
0
    basename="district-summary-patient",
)

router.register("items", FacilityInventoryItemViewSet)
router.register("burn_rate", FacilityInventoryBurnRateViewSet)

router.register("shift", ShiftingViewSet, basename="patient-shift")

router.register("investigation/group", InvestigationGroupViewset)
router.register("investigation", PatientInvestigationViewSet)

# Ref: https://github.com/alanjds/drf-nested-routers
facility_nested_router = NestedSimpleRouter(router,
                                            r"facility",
                                            lookup="facility")
facility_nested_router.register(r"hospital_doctor", HospitalDoctorViewSet)
facility_nested_router.register(r"capacity", FacilityCapacityViewSet)
facility_nested_router.register(r"patient_stats",
                                FacilityPatientStatsHistoryViewSet)
facility_nested_router.register(r"inventory", FacilityInventoryLogViewSet)
facility_nested_router.register(r"inventorysummary",
                                FacilityInventorySummaryViewSet)
facility_nested_router.register(r"min_quantity",
                                FacilityInventoryMinQuantityViewSet)
facility_nested_router.register("burn_rate", FacilityInventoryBurnRateViewSet)

patient_nested_router = NestedSimpleRouter(router,
                                           r"patient",
                                           lookup="patient")
patient_nested_router.register(r"test_sample", PatientSampleViewSet)
patient_nested_router.register(r"investigation",
Пример #47
0
from django.conf.urls import url, include
from rest_framework_nested.routers import SimpleRouter, DefaultRouter, NestedSimpleRouter
from classes.views import ClassesViewSet, SemesterViewSet
from classes.views import ClassesSemesterViewSet
from student.views import ClassesStudentViewSet

root_router = DefaultRouter()
root_router.register('classes', ClassesViewSet, 'classes')
root_router.register('semester', SemesterViewSet, 'semester')

classes_router = SimpleRouter()
classes_router.register('classes', ClassesViewSet, base_name='list-classes')
classes_semester_router = NestedSimpleRouter(classes_router, 'classes', lookup='classes')
classes_semester_router.register('semester', ClassesSemesterViewSet, base_name='list-classes-semester')
classes_student_router = NestedSimpleRouter(classes_router, 'classes', lookup='classes')
classes_student_router.register('student', ClassesStudentViewSet, base_name='list-classes-student')

urlpatterns = [
    url(r'', include(root_router.urls)),
    url(r'list/', include(classes_router.urls)),
    url(r'list/', include(classes_semester_router.urls)),
    url(r'list/', include(classes_student_router.urls)),
]
Пример #48
0
from bugtracking.users.api.views import UserViewSet
from bugtracking.tracker.api.viewsets import TeamViewSet, TeamMembershipViewSet, ProjectViewSet, TicketViewSet, TeamInvitationViewSet

if settings.DEBUG:
    router = DefaultRouter()
else:
    router = SimpleRouter()

router.register("users", UserViewSet)
router.register(r'teams', TeamViewSet, basename='teams')
router.register(r'invitations', TeamInvitationViewSet, basename='invitations')
# don't want the memberships viewset registered by default; only using it to debug stuff
# router.register(r'memberships', TeamMembershipViewSet, basename='memberships')

team_router = NestedSimpleRouter(router, r'teams', lookup='team')
team_router.register(r'projects', ProjectViewSet, basename='projects')
team_router.register(r'invitations',
                     TeamInvitationViewSet,
                     basename='invitations')
project_router = NestedSimpleRouter(team_router, r'projects', lookup='project')
project_router.register(r'tickets', TicketViewSet, basename='tickets')

app_name = "api"
# urlpatterns = router.urls

urlpatterns = [
    path(r'', include(router.urls)),
    path(r'', include(team_router.urls)),
    path(r'', include(project_router.urls))
]
Пример #49
0
    1. Add an import:  from other_app.views import Home
    2. Add a URL to urlpatterns:  url(r'^$', Home.as_view(), name='home')
Including another URLconf
    1. Add an import:  from blog import urls as blog_urls
    2. Add a URL to urlpatterns:  url(r'^blog/', include(blog_urls))
"""
from django.conf.urls import include, url
from django.contrib import admin

from rest_framework.routers import DefaultRouter
from rest_framework_nested.routers import NestedSimpleRouter

from blogposts.views import BlogpostViewSet, CommentViewSet, NestedCommentViewSet

from .views import UserViewSet

router = DefaultRouter()
router.register(r'users', UserViewSet)
router.register(r'blogposts', BlogpostViewSet)
router.register(r'comments', CommentViewSet)

blogposts_router = NestedSimpleRouter(router, r'blogposts', lookup='blogpost')
blogposts_router.register(r'comments', NestedCommentViewSet)

urlpatterns = [
    url(r'^admin/', include(admin.site.urls)),
    url(r'^api/', include(router.urls)),
    url(r'^api/', include(blogposts_router.urls)),
    url(r'^o/', include('oauth2_provider.urls', namespace='oauth2_provider')),
]
Пример #50
0
from django.conf.urls import include, url
from django.conf.urls.static import static
from rest_framework.routers import DefaultRouter
from rest_framework_nested.routers import NestedSimpleRouter

from wristband.stages.views import StagesViewSet
from wristband.apps.views import NestedAppViewSet, AppViewSet, DeployAppView
from wristband.authentication.views import login_view, logout_view, ObtainAuthToken
from wristband.common.views import healthcheck_view

router = DefaultRouter()
router.register(r'stages', StagesViewSet, base_name='stages')
router.register(r'apps', AppViewSet, base_name='apps')

stages_router = NestedSimpleRouter(router, r'stages', lookup='stage')
stages_router.register(r'apps', NestedAppViewSet, base_name='apps')


urlpatterns = [
    url(r'^login/$', login_view, name='login'),
    url(r'^logout/$', logout_view, name='logout'),
    url(r'^token/$', ObtainAuthToken.as_view(), name='token'),
    url(r'^ping/ping/$', healthcheck_view, name='healthcheck'),
    url(r'^api/', include(router.urls)),
    url(r'^api/', include(stages_router.urls)),
    url(r'^api/apps/(?P<app_name>.*)/stages/(?P<stage>.*)/version/(?P<version>.*)/', DeployAppView.as_view()),
    url(r'^docs/', include('rest_framework_swagger.urls'))


] + static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)
Пример #51
0
from django.urls import include, path
from rest_framework_nested.routers import NestedSimpleRouter, SimpleRouter

from . import viewsets

tests_router = SimpleRouter()
tests_router.register('tests', viewsets.TestsViewSet, base_name='tests')

questions_router = NestedSimpleRouter(tests_router, 'tests', lookup='test')
questions_router.register('questions',
                          viewsets.QuestionsViewSet,
                          base_name='questions')

answers_router = NestedSimpleRouter(questions_router,
                                    'questions',
                                    lookup='question')
answers_router.register('answers',
                        viewsets.AnswersViewSet,
                        base_name='answers')

urlpatterns = [
    path('', include(tests_router.get_urls())),
    path('', include(questions_router.get_urls())),
    path('', include(answers_router.get_urls())),
]
Пример #52
0
from django.conf.urls import url
from django.urls import include
from rest_framework import routers
from rest_framework_nested.routers import NestedSimpleRouter
from api.controls.views.element import ElementViewSet, ElementWithPermissionsViewSet
from api.controls.views.system import SystemViewSet, SystemControlsViewSet, SystemAssessmentViewSet, SystemPoamViewSet

router = routers.DefaultRouter()
router.register(r'elements', ElementViewSet)
router.register(r'element_permissions', ElementWithPermissionsViewSet)
router.register(r'systems', SystemViewSet)

systems_router = NestedSimpleRouter(router, r'systems', lookup='systems')
systems_router.register(r'controls',
                        SystemControlsViewSet,
                        basename='systems-controls')
systems_router.register(r'assessments',
                        SystemAssessmentViewSet,
                        basename='systems-assessments')
systems_router.register(r'poams', SystemPoamViewSet, basename='systems-poams')

urlpatterns = [
    url(r'^', include(router.urls)),
    url(r'^', include(systems_router.urls))
]
Пример #53
0
from rest_framework_nested.routers import NestedSimpleRouter

from commons.views import csrf_token
from users.views import UserViewSet
from users.views import signin
from users.views import signout
from tasks.views import TaskViewSet
from tasks.views import PomodoroViewSet


router = DefaultRouter()
router.register(r'users', UserViewSet, base_name='user')
router.register(r'tasks', TaskViewSet, base_name='task')

tasks_router = NestedSimpleRouter(router, r'tasks', lookup='task')
tasks_router.register(r'pomodoros', PomodoroViewSet, base_name='pomodoro')


urlpatterns = [
    url(r'^admin/', admin.site.urls),

    # get csrf token
    url(r'^csrf_token', csrf_token, name='csrf_token'),

    # login/logout
    url(r'^auth/signin', signin, name='signin'),
    url(r'^auth/signout', signout, name='signout'),

    # test auth from django-rest-framework
    url(r'^test/auth/', include('rest_framework.urls', namespace='rest_framework')),
from django.conf.urls import patterns, url, include
from django.views.generic.base import TemplateView

from rest_framework import routers
from rest_framework_nested.routers import NestedSimpleRouter

from authentication.views import AccountViewSet, LoginView, LogoutView
from posts.views import AccountPostsViewSet, PostViewSet

router = routers.SimpleRouter()
router.register(r'accounts', AccountViewSet)
router.register(r'posts', PostViewSet)

accounts_router = NestedSimpleRouter(
    router, r'accounts', lookup='account'
)
accounts_router.register(r'posts', AccountPostsViewSet)

urlpatterns = patterns(
    '',
    url(r'^api/v1/auth/login/$', LoginView.as_view(), name="login"),
    url(r'^api/v1/auth/logout/$', LogoutView.as_view(), name="logout"),
    url(r'^api/v1/', include(router.urls)),
    url(r'^api/v1/', include(accounts_router.urls)),

    url(r'^', TemplateView.as_view(template_name='index.html'), name='index'),
)
Пример #55
0
from django.conf.urls import patterns, url, include

from rest_framework import routers
from rest_framework_nested.routers import NestedSimpleRouter

from . import views


router = routers.DefaultRouter()
router.register(r'category', views.CategoryViewSet)
router.register(r'eligibility_check', views.EligibilityCheckViewSet, base_name='eligibility_check')
router.register(r'case', views.CaseViewSet)

eligibility_check_router = \
    NestedSimpleRouter(router,
                       'eligibility_check',
                       lookup='eligibility_check_')

eligibility_check_router.register(r'property',
                                  views.PropertyViewSet,
                                  base_name='property',
                                )


urlpatterns = patterns('',
    url(r'^', include(router.urls)),
    url(r'^', include(eligibility_check_router.urls)),
)
Пример #56
0
Файл: urls.py Проект: sdob/dsapi
import sitestatistics.views
from authviews.views import FacebookLogin, GoogleLogin

router = SimpleRouter()
router.register(r'comments/compressors', comments.views.CompressorCommentViewSet)
router.register(r'comments/divesites', comments.views.DivesiteCommentViewSet)
router.register(r'comments/slipways', comments.views.SlipwayCommentViewSet)

router.register(r'compressors', divesites.views.CompressorViewSet, base_name='compressor')
router.register(r'divesites', divesites.views.DivesiteViewSet, base_name='divesite')
router.register(r'dives', divesites.views.DiveViewSet)
router.register(r'slipways', divesites.views.SlipwayViewSet, base_name='slipway')
router.register(r'users', profiles.views.ProfileViewSet, base_name='profile')

compressors_router = NestedSimpleRouter(router, r'compressors', lookup='compressor')
compressors_router.register(r'images', images.views.ImageViewSet, base_name='compressor-image')

divesites_router = NestedSimpleRouter(router, r'divesites', lookup='divesite')
divesites_router.register(r'images', images.views.ImageViewSet, base_name='divesite-image')

slipways_router = NestedSimpleRouter(router, r'slipways', lookup='slipway')
slipways_router.register(r'images', images.views.ImageViewSet, base_name='slipway-image')

urlpatterns = [
    url(r'^admin/', admin.site.urls),
    url(r'^', include(router.urls)),
    url(r'^', include(compressors_router.urls)),
    url(r'^', include(divesites_router.urls)),
    url(r'^', include(slipways_router.urls)),
    url(r'^auth/', include('rest_auth.urls')),
    url(r'^auth/facebook/$', FacebookLogin.as_view(), name='fb_login'),
Пример #57
0
from django.urls import path, include
from rest_framework.routers import SimpleRouter
from rest_framework_nested.routers import NestedSimpleRouter

from auth.viewsets import ObtainTokenViewSet, LogoutViewSet, RegisterViewSet
from event.viewsets import EventViewSet
from user.viewsets import UserViewSet
from comment.viewsets import CommentViewSet

router = SimpleRouter()

# Auth
router.register(r'logout', LogoutViewSet, basename='auth-logout')
router.register(r'account', RegisterViewSet, basename='auth-login')
router.register(r'auth', ObtainTokenViewSet, basename='auth-token')

# user
router.register(r'user', UserViewSet, basename='user')

# event
router.register(r'event', EventViewSet, basename='event')

event_router = NestedSimpleRouter(router, r'event', lookup='event')
event_router.register(r'comment', CommentViewSet, basename='event-comment')

urlpatterns = [
    path(r'v1/', include(router.urls + event_router.urls)),
]
Пример #58
0
    AddonRecommendationView,
    AddonSearchView,
    AddonVersionViewSet,
    AddonViewSet,
    CompatOverrideView,
    LanguageToolsView,
    ReplacementAddonView,
    StaticCategoryView,
)

addons = SimpleRouter()
addons.register(r'addon', AddonViewSet, basename='addon')

# Router for children of /addons/addon/{addon_pk}/.
sub_addons = NestedSimpleRouter(addons, r'addon', lookup='addon')
sub_addons.register('versions', AddonVersionViewSet, basename='addon-version')
sub_versions = NestedSimpleRouter(sub_addons, r'versions', lookup='version')
sub_versions.register(r'reviewnotes',
                      VersionReviewNotesViewSet,
                      basename='version-reviewnotes')

uploads = SimpleRouter()
uploads.register(r'upload', FileUploadViewSet, basename='addon-upload')

urls = [
    re_path(r'', include(addons.urls)),
    re_path(r'', include(sub_addons.urls)),
    re_path(r'', include(sub_versions.urls)),
    re_path(
        r'^autocomplete/$',
        AddonAutoCompleteSearchView.as_view(),
Пример #59
0
from django.conf.urls import url, include
from rest_framework_nested.routers import SimpleRouter, DefaultRouter, NestedSimpleRouter
from score.views import ScoreViewSet, ScoreDataViewSet

root_router = DefaultRouter()
root_router.register('score', ScoreViewSet, 'score')
root_router.register('score-data', ScoreDataViewSet, 'score-data')

score_router = SimpleRouter()
score_router.register('score', ScoreViewSet, base_name='list-score')
score_data_router = NestedSimpleRouter(score_router, 'score', lookup='score')
score_data_router.register('data', ScoreDataViewSet, base_name='list-score-data')

urlpatterns = [
    url(r'', include(root_router.urls)),
    url(r'list/', include(score_router.urls)),
    url(r'list/', include(score_data_router.urls)),
]