-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Muevo admins custom a un módulo aparte
Overridea defaults de django_datajsonar para modelos Field y Distribution, particularmente acciones custom relacionadas a la API de series (búsqueda e indexacion de datos)
- Loading branch information
1 parent
eaf2c96
commit 9dd6c8b
Showing
5 changed files
with
60 additions
and
42 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
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,48 @@ | ||
from django.contrib import admin | ||
|
||
from django_datajsonar.admin import FieldAdmin, DistributionAdmin | ||
from django_datajsonar.models import Field, Distribution | ||
|
||
from series_tiempo_ar_api.apps.metadata.utils import delete_metadata | ||
from .tasks import reindex_distribution | ||
|
||
admin.site.unregister(Field) | ||
admin.site.unregister(Distribution) | ||
|
||
|
||
@admin.register(Field) | ||
class CustomFieldAdmin(FieldAdmin): | ||
actions = ('delete_model',) | ||
|
||
def get_actions(self, request): | ||
# Borro la acción de borrado default | ||
actions = super(CustomFieldAdmin, self).get_actions(request) | ||
if 'delete_selected' in actions: | ||
del actions['delete_selected'] | ||
return actions | ||
|
||
def delete_model(self, _, queryset): | ||
delete_metadata(list(queryset)) | ||
queryset.delete() | ||
|
||
|
||
@admin.register(Distribution) | ||
class CustomDistributionAdmin(DistributionAdmin): | ||
actions = ('delete_model', 'reindex') | ||
|
||
def get_actions(self, request): | ||
# Borro la acción de borrado default | ||
actions = super(CustomDistributionAdmin, self).get_actions(request) | ||
if 'delete_selected' in actions: | ||
del actions['delete_selected'] | ||
return actions | ||
|
||
def delete_model(self, _, queryset): | ||
fields = Field.objects.filter(distribution__identifier__in=queryset.values_list('identifier', flat=True)) | ||
delete_metadata(list(fields)) | ||
queryset.delete() | ||
|
||
def reindex(self, _, queryset): | ||
for distribution in queryset: | ||
reindex_distribution.delay(distribution) | ||
reindex.short_description = "Refrescar datos" |
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,10 @@ | ||
from django.conf import settings | ||
from django_datajsonar.models import Distribution | ||
from django_rq import job | ||
|
||
from series_tiempo_ar_api.libs.indexing.indexer.distribution_indexer import DistributionIndexer | ||
|
||
|
||
@job('indexing', timeout=settings.DISTRIBUTION_INDEX_JOB_TIMEOUT) | ||
def reindex_distribution(distribution: Distribution): | ||
DistributionIndexer(index=settings.TS_INDEX).reindex(distribution) |