-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
66 additions
and
110 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
from django.urls import path | ||
from rest_framework.routers import SimpleRouter | ||
from rest_framework_json_api.utils import get_resource_type_from_serializer | ||
|
||
from addon_service import views | ||
|
||
|
||
def _urls_for_viewset(viewset, *, relationship_view=None): | ||
"""returns urlpatterns for a viewset that corresponds to a resource type | ||
includes patterns for jsonapi-style relationships | ||
""" | ||
_resource_name = get_resource_type_from_serializer(viewset.serializer_class) | ||
_router = SimpleRouter() | ||
_router.register( | ||
prefix=_resource_name, | ||
viewset=viewset, | ||
basename=_resource_name, | ||
) | ||
_urlpatterns = [*_router.urls] | ||
# add route for all relationship "related" links | ||
# https://django-rest-framework-json-api.readthedocs.io/en/stable/usage.html#related-urls | ||
_urlpatterns.append( | ||
path( | ||
f"{_resource_name}/<pk>/<related_field>/", | ||
viewset.as_view({"get": "retrieve_related"}), | ||
name=f"{_resource_name}-related", | ||
), | ||
) | ||
if relationship_view is not None: | ||
# add route for all relationship "self" links | ||
# https://django-rest-framework-json-api.readthedocs.io/en/stable/usage.html#relationshipview | ||
_urlpatterns.append( | ||
path( | ||
f"{_resource_name}/<pk>/relationships/<related_field>/", | ||
relationship_view.as_view(), | ||
name=f"{_resource_name}-relationships", | ||
), | ||
) | ||
return _urlpatterns | ||
|
||
|
||
# NOTE: assumes each viewset corresponds to a distinct resource_name | ||
urlpatterns = [ | ||
*_urls_for_viewset( | ||
views.AuthorizedStorageAccountViewSet, | ||
relationship_view=views.AuthorizedStorageAccountRelationshipView, | ||
), | ||
*_urls_for_viewset( | ||
views.ConfiguredStorageAddonViewSet, | ||
relationship_view=views.ConfiguredStorageAddonRelationshipView, | ||
), | ||
*_urls_for_viewset( | ||
views.ExternalStorageServiceViewSet, | ||
relationship_view=views.ExternalStorageServiceRelationshipView, | ||
), | ||
*_urls_for_viewset( | ||
views.InternalResourceViewSet, | ||
relationship_view=views.InternalResourceRelationshipView, | ||
), | ||
*_urls_for_viewset( | ||
views.InternalUserViewSet, | ||
relationship_view=views.InternalUserRelationshipView, | ||
), | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,41 +1,9 @@ | ||
"""gravyvalet URL Configuration | ||
The `urlpatterns` list routes URLs to views. For more information please see: | ||
https://docs.djangoproject.com/en/3.1/topics/http/urls/ | ||
Examples: | ||
Function views | ||
1. Add an import: from my_app import views | ||
2. Add a URL to urlpatterns: path('', views.home, name='home') | ||
Class-based views | ||
1. Add an import: from other_app.views import Home | ||
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.urls import ( | ||
include, | ||
path, | ||
) | ||
|
||
from addon_service.authorized_storage_account import urls as asa_urls | ||
from addon_service.configured_storage_addon import urls as csa_urls | ||
from addon_service.external_storage_service import urls as ess_urls | ||
from addon_service.internal_resource import urls as ir_urls | ||
from addon_service.internal_user import urls as iu_urls | ||
|
||
|
||
urlpatterns = [ | ||
path( | ||
"v1/", | ||
include( | ||
[ | ||
*asa_urls.urlpatterns, | ||
*csa_urls.urlpatterns, | ||
*ess_urls.urlpatterns, | ||
*ir_urls.urlpatterns, | ||
*iu_urls.urlpatterns, | ||
] | ||
), | ||
), | ||
path("v1/", include("addon_service.urls")), | ||
] |