diff --git a/drfautoapi/drfautoapi.py b/drfautoapi/drfautoapi.py index 06a74e1d7..4c4eacefc 100644 --- a/drfautoapi/drfautoapi.py +++ b/drfautoapi/drfautoapi.py @@ -226,7 +226,7 @@ class ApiViewSetConstrutor(): return cls @classmethod - def last_modified_method(cls, klass): + def last_modified_class(cls, klass): cls.LastModifiedDecorator = klass return cls diff --git a/frontend/src/__apps/parlamentar/main.js b/frontend/src/__apps/parlamentar/main.js index 97f5e5c75..4392fa9ee 100644 --- a/frontend/src/__apps/parlamentar/main.js +++ b/frontend/src/__apps/parlamentar/main.js @@ -3,6 +3,12 @@ import Vue from 'vue' import { FormSelectPlugin } from 'bootstrap-vue' import axios from 'axios' +// TODO: refatorar para aproveitar cache e LastModified no frontend oficial +// Configuração global para todas as requisições GET do axios +axios.defaults.headers.get['Cache-Control'] = 'no-cache, no-store, must-revalidate' +axios.defaults.headers.get['Pragma'] = 'no-cache' // Suporte para navegadores mais antigos +axios.defaults.headers.get['Expires'] = '0' // Expira imediatamente + axios.defaults.xsrfCookieName = 'csrftoken' axios.defaults.xsrfHeaderName = 'X-CSRFToken' diff --git a/frontend/src/__global/js/functions.js b/frontend/src/__global/js/functions.js index 1f9b44a6a..cfc86fa4a 100644 --- a/frontend/src/__global/js/functions.js +++ b/frontend/src/__global/js/functions.js @@ -66,7 +66,8 @@ window.autorModal = function () { $('#pesquisar').click(function () { const json_data = { - q: $('#q').val() + q: $('#q').val(), + utc_time: Date.now(), // get_all: true } $.get('/api/base/autor', json_data, function (data) { diff --git a/sapl/api/views.py b/sapl/api/views.py index 08d600edf..aeaa1d974 100644 --- a/sapl/api/views.py +++ b/sapl/api/views.py @@ -36,11 +36,7 @@ class LastModifiedDecorator: - Se for uma listagem, considera o último AuditLog de todos os objetos retornados na listagem levando em consideração resultado de FilterSet. - Retorna 304 Not Modified se o recurso não foi modificado - """ - def __init__(self): - pass - def __call__(self, cls): original_dispatch = cls.dispatch @@ -53,7 +49,7 @@ class LastModifiedDecorator: last_modified_func = self.last_modified_func if not hasattr(view, 'last_modified_func') else view.last_modified_func def patched_viewset_method(*_args, **_kwargs): - return original_dispatch(view, drf_request, *_args, **_kwargs) + return original_dispatch(view, drf_request, *args, **kwargs) django_decorator = django_condition(last_modified_func=last_modified_func) decorated_viewset_method = django_decorator(patched_viewset_method) @@ -63,6 +59,10 @@ class LastModifiedDecorator: return cls def last_modified_func(self, request, *args, **kwargs): + """ - Método padrão para obter o last_modified baseado no AuditLog + - Pode ser sobrescrito na customização do ViewSet caso necessário + - Existe um exemplo de sobrescrita em sapl/api/views_materia.py + """ try: if 'pk' in kwargs: obj_id = kwargs['pk'] @@ -75,6 +75,7 @@ class LastModifiedDecorator: if view: for backend in list(view.filter_backends): queryset = backend().filter_queryset(request, view.queryset, view) + if queryset.exists(): last_log = AuditLog.objects.filter( model_name=self.model._meta.model_name, @@ -97,7 +98,7 @@ class LastModifiedDecorator: return None SaplApiViewSetConstrutor = ApiViewSetConstrutor -SaplApiViewSetConstrutor.last_modified_method(LastModifiedDecorator) +SaplApiViewSetConstrutor.last_modified_class(LastModifiedDecorator) SaplApiViewSetConstrutor.import_modules([ 'sapl.api.views_audiencia', 'sapl.api.views_base', diff --git a/sapl/templates/crud/detail.html b/sapl/templates/crud/detail.html index 2f9a2c6c0..c4ebc0d36 100644 --- a/sapl/templates/crud/detail.html +++ b/sapl/templates/crud/detail.html @@ -104,7 +104,7 @@ {% if view.openapi_url %}
- + {% trans 'OpenAPI' %} diff --git a/sapl/templates/crud/detail_detail.html b/sapl/templates/crud/detail_detail.html index 5f4b59d72..ad011ae4c 100644 --- a/sapl/templates/crud/detail_detail.html +++ b/sapl/templates/crud/detail_detail.html @@ -67,7 +67,7 @@ {% if view.openapi_url %}