Browse Source

Checa timestamp de Norma como time aware

pull/3402/head
eribeiro 4 years ago
parent
commit
d2ac4607fd
  1. 17
      sapl/lexml/OAIServer.py

17
sapl/lexml/OAIServer.py

@ -6,9 +6,11 @@ import oaipmh.error
import oaipmh.metadata import oaipmh.metadata
import oaipmh.server import oaipmh.server
from django.urls import reverse from django.urls import reverse
from django.utils import timezone
from lxml import etree from lxml import etree
from lxml.builder import ElementMaker from lxml.builder import ElementMaker
from sapl.base.models import AppConfig, CasaLegislativa from sapl.base.models import AppConfig, CasaLegislativa
from sapl.lexml.models import LexmlPublicador, LexmlProvedor from sapl.lexml.models import LexmlPublicador, LexmlProvedor
from sapl.norma.models import NormaJuridica from sapl.norma.models import NormaJuridica
@ -103,6 +105,7 @@ class OAIServer:
def recupera_norma(self, offset, batch_size, from_, until, identifier, esfera): def recupera_norma(self, offset, batch_size, from_, until, identifier, esfera):
kwargs = {'data__isnull': False, kwargs = {'data__isnull': False,
'esfera_federacao__isnull': False,
'timestamp__isnull': False, 'timestamp__isnull': False,
'timestamp__lte': until} 'timestamp__lte': until}
if from_: if from_:
@ -234,11 +237,21 @@ class OAIServer:
return None return None
def oai_query(self, offset=0, batch_size=10, from_=None, until=None, identifier=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() esfera = self.get_esfera_federacao()
offset = 0 if offset < 0 else offset offset = 0 if offset < 0 else offset
batch_size = 10 if batch_size < 0 else batch_size 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: for norma in normas:
resultado = {} resultado = {}
identificador = self.monta_id(norma) identificador = self.monta_id(norma)

Loading…
Cancel
Save