From d2ac4607fd94c8f25cf6e417de4e0eb0acf93182 Mon Sep 17 00:00:00 2001 From: eribeiro Date: Thu, 27 May 2021 10:27:25 -0300 Subject: [PATCH] Checa timestamp de Norma como time aware --- sapl/lexml/OAIServer.py | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/sapl/lexml/OAIServer.py b/sapl/lexml/OAIServer.py index 6c0bf70f3..340c03dde 100644 --- a/sapl/lexml/OAIServer.py +++ b/sapl/lexml/OAIServer.py @@ -6,9 +6,11 @@ import oaipmh.error import oaipmh.metadata import oaipmh.server from django.urls import reverse +from django.utils import timezone from lxml import etree from lxml.builder import ElementMaker + from sapl.base.models import AppConfig, CasaLegislativa from sapl.lexml.models import LexmlPublicador, LexmlProvedor from sapl.norma.models import NormaJuridica @@ -103,6 +105,7 @@ class OAIServer: def recupera_norma(self, offset, batch_size, from_, until, identifier, esfera): kwargs = {'data__isnull': False, + 'esfera_federacao__isnull': False, 'timestamp__isnull': False, 'timestamp__lte': until} if from_: @@ -234,11 +237,21 @@ class OAIServer: return None def oai_query(self, offset=0, batch_size=10, from_=None, until=None, identifier=None): + from_ = timezone.make_aware(from_) # convert from naive to timezone aware datetime esfera = self.get_esfera_federacao() offset = 0 if offset < 0 else offset batch_size = 10 if batch_size < 0 else batch_size - until = datetime.now() if not until or until > datetime.now() else until - normas = self.recupera_norma(offset, batch_size, from_, until, identifier, esfera) + + until = timezone.make_aware(until) \ + if until and timezone.make_aware(until) < timezone.now() \ + else timezone.now() + + normas = self.recupera_norma(offset, + batch_size, + from_, + until, + identifier, + esfera) for norma in normas: resultado = {} identificador = self.monta_id(norma)