-
Notifications
You must be signed in to change notification settings - Fork 134
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add endpoint for fetching currently running csv imports #2299
base: main
Are you sure you want to change the base?
Conversation
3c79a16
to
863f4e8
Compare
036b4ab
to
26080a3
Compare
- Format the file using black
The class is used to allow the `create` route of a viewset to have detail passed to it i.e /<route>/<pk>
- Add _get_active_tasks utility function - Modify `retrieve` route; Remove uneeded if statement since the get_object function raises a 404 error if object is missing
- Update test; ensure that the expected args are present
3293457
to
f55cbf3
Compare
28276df
to
cc30a35
Compare
cc30a35
to
d54af21
Compare
overwrite, str) else overwrite) | ||
|
||
# Block imports from running when an overwrite is ongoing | ||
active_tasks = self._get_active_tasks(xform) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why not get_active_tasks(self.task_names, xform)
it is still clean and there is nothing special about the _get_active_tasks()
that requires it to be a class method.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Will make this change
class DetailedPostRouter(routers.DefaultRouter): | ||
""" | ||
Custom router | ||
""" | ||
routes = [ | ||
# List route. | ||
routers.Route( | ||
url=r"^{prefix}{trailing_slash}$", | ||
mapping={"get": "list", "post": "create"}, | ||
name="{basename}-list", | ||
detail=False, | ||
initkwargs={"suffix": "List"}, | ||
), | ||
# Dynamically generated list routes. Generated using | ||
# @action(detail=False) decorator on methods of the viewset. | ||
routers.DynamicRoute( | ||
url=r"^{prefix}/{url_path}{trailing_slash}$", | ||
name="{basename}-{url_name}", | ||
detail=False, | ||
initkwargs={}, | ||
), | ||
# Detail route. | ||
routers.Route( | ||
url=r"^{prefix}/{lookup}{trailing_slash}$", | ||
mapping={ | ||
"get": "retrieve", | ||
"put": "update", | ||
"patch": "partial_update", | ||
"delete": "destroy", | ||
"post": "create", | ||
}, | ||
name="{basename}-detail", | ||
detail=True, | ||
initkwargs={"suffix": "Instance"}, | ||
), | ||
# Dynamically generated detail routes. Generated using | ||
# @action(detail=True) decorator on methods of the viewset. | ||
routers.DynamicRoute( | ||
url=r"^{prefix}/{lookup}/{url_path}{trailing_slash}$", | ||
name="{basename}-{url_name}", | ||
detail=True, | ||
initkwargs={}, | ||
), | ||
] | ||
|
||
# pylint: disable=redefined-outer-name | ||
def extend(self, router): | ||
""" | ||
Extends the routers routes with the routes from another router | ||
""" | ||
self.registry.extend(router.registry) | ||
|
||
|
||
base_router = MultiLookupRouter(trailing_slash=False) | ||
router = DetailedPostRouter(trailing_slash=False) | ||
base_router.register(r"open-data", TableauViewSet, basename="open-data") | ||
router.register(r"imports", ImportsViewSet, basename="imports") | ||
|
||
router.extend(base_router) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why is the DetailedPostRouter necessary? Which path is impossible to do with the existing default and custom routers that we need another custom router?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This was mostly implemented so that we could pass a detail to a POST route; AFAIK the post (create) route on DRF doesn't usually support detail... Is there a particular way we could implement this without having to create our own custom route?
tl;dr This was done so that we could pass detail to the default create
function; Allowing requests such as curl -X POST "http://<domain>/api/v2/imports/<xform_id>"
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should use create/post on the /api/v2/imports
to create a new import instead of /api/v2/imports/<xform_id>
. The xform_id
should be a mandatory post parameter in the post to create an import. With that approach, there is no need for a custom router. We already take this approach with the /api/v1/forms
, /api/v1/dataviews
and other endpoints.
Before submitting this PR for review, please make sure you have:
Closes #2204