-
Notifications
You must be signed in to change notification settings - Fork 31
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
moving app/resource es indexing apis under /indexes/ namespaces
- Loading branch information
1 parent
6dac55d
commit 1b361b0
Showing
15 changed files
with
123 additions
and
87 deletions.
There are no files selected for viewing
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
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
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
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
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
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
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
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
Empty file.
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,9 @@ | ||
from django.urls import path | ||
|
||
from core.indexes import views | ||
|
||
urlpatterns = [ | ||
path("apps/populate/", views.PopulateESIndexView.as_view(), name='populate-indexes'), | ||
path("apps/rebuild/", views.RebuildESIndexView.as_view(), name='rebuild-indexes'), | ||
path("resources/<str:resource>/", views.ResourceIndexView.as_view(), name='resource-indexes'), | ||
] |
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,61 @@ | ||
from drf_yasg.utils import swagger_auto_schema | ||
from pydash import compact | ||
from rest_framework import status | ||
from rest_framework.parsers import MultiPartParser | ||
from rest_framework.response import Response | ||
from rest_framework.views import APIView | ||
|
||
from core.common.permissions import IsSuperuser | ||
from core.common.swagger_parameters import apps_param, ids_param, resources_body_param | ||
from core.common.tasks import rebuild_indexes, populate_indexes | ||
from core.common.utils import get_resource_class_from_resource_name | ||
|
||
|
||
class BaseESIndexView(APIView): # pragma: no cover | ||
permission_classes = (IsSuperuser,) | ||
parser_classes = (MultiPartParser,) | ||
task = None | ||
|
||
@swagger_auto_schema(manual_parameters=[apps_param]) | ||
def post(self, request): | ||
apps = request.data.get('apps', None) | ||
if apps: | ||
apps = apps.split(',') | ||
result = self.task.delay(apps) | ||
|
||
return Response( | ||
dict(state=result.state, username=self.request.user.username, task=result.task_id, queue='default'), | ||
status=status.HTTP_202_ACCEPTED | ||
) | ||
|
||
|
||
class RebuildESIndexView(BaseESIndexView): # pragma: no cover | ||
task = rebuild_indexes | ||
|
||
|
||
class PopulateESIndexView(BaseESIndexView): # pragma: no cover | ||
task = populate_indexes | ||
|
||
|
||
class ResourceIndexView(APIView): | ||
permission_classes = (IsSuperuser,) | ||
parser_classes = (MultiPartParser,) | ||
|
||
@swagger_auto_schema(manual_parameters=[ids_param, resources_body_param]) | ||
def post(self, _, resource): | ||
model = get_resource_class_from_resource_name(resource) | ||
|
||
if not model: | ||
return Response(status.HTTP_404_NOT_FOUND) | ||
|
||
ids = self.request.data.get('ids', None) | ||
if ids: | ||
ids = [i.strip() for i in compact(ids.split(','))] | ||
|
||
if not ids: | ||
return Response(status.HTTP_400_BAD_REQUEST) | ||
|
||
for instance in model.objects.filter(**{"{}__in".format(model.mnemonic_attr): ids}): | ||
instance.save() | ||
|
||
return Response(status=status.HTTP_202_ACCEPTED) |
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
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
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
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