Browse Source

Usar timezone nos campos date/time

pull/159/head
Sesostris Vieira 3 years ago
parent
commit
40ee11d551
  1. 8
      sigi/apps/casas/models.py
  2. 1
      sigi/apps/casas/views.py
  3. 10
      sigi/apps/convenios/models.py
  4. 2
      sigi/apps/convenios/views.py
  5. 4
      sigi/apps/eventos/models.py
  6. 20
      sigi/apps/eventos/views.py
  7. 3
      sigi/apps/home/views.py

8
sigi/apps/casas/models.py

@ -1,11 +1,11 @@
from datetime import datetime
import random import random
from string import ascii_uppercase from string import ascii_uppercase
from unicodedata import normalize from unicodedata import normalize
from django.core.exceptions import ValidationError
from django.utils.translation import gettext as _
from django.contrib.contenttypes.fields import GenericRelation from django.contrib.contenttypes.fields import GenericRelation
from django.core.exceptions import ValidationError
from django.db import models from django.db import models
from django.utils import timezone
from django.utils.translation import gettext as _
from sigi.apps.contatos.models import Municipio from sigi.apps.contatos.models import Municipio
from sigi.apps.servidores.models import Servidor from sigi.apps.servidores.models import Servidor
@ -219,7 +219,7 @@ class Orgao(models.Model):
address_changed = True address_changed = True
if address_changed: if address_changed:
self.ult_alt_endereco = datetime.now() self.ult_alt_endereco = timezone.localtime()
return super(Orgao, self).save(*args, **kwargs) return super(Orgao, self).save(*args, **kwargs)

1
sigi/apps/casas/views.py

@ -1,5 +1,4 @@
import csv import csv
from datetime import datetime
from functools import reduce from functools import reduce
from django.contrib import messages from django.contrib import messages

10
sigi/apps/convenios/models.py

@ -1,11 +1,11 @@
import re import re
import requests import requests
from datetime import datetime, date
from django.db import models from django.db import models
from django.db.models import Q, fields from django.db.models import Q, fields
from django.core.mail import send_mail from django.core.mail import send_mail
from django.core.validators import FileExtensionValidator from django.core.validators import FileExtensionValidator
from django.urls import reverse from django.urls import reverse
from django.utils import timezone
from django.utils.formats import date_format from django.utils.formats import date_format
from django.utils.translation import gettext as _ from django.utils.translation import gettext as _
from tinymce.models import HTMLField from tinymce.models import HTMLField
@ -350,7 +350,7 @@ class Anexo(models.Model):
) )
descricao = models.CharField(_("descrição"), max_length=70) descricao = models.CharField(_("descrição"), max_length=70)
data_pub = models.DateTimeField( data_pub = models.DateTimeField(
_("data da publicação do anexo"), default=datetime.now _("data da publicação do anexo"), default=timezone.localtime
) )
class Meta: class Meta:
@ -495,7 +495,7 @@ class Gescon(models.Model):
self.ultima_importacao = "" self.ultima_importacao = ""
self.add_message( self.add_message(
_( _(
f"Importação iniciada em {datetime.now():%d/%m/%Y %H:%M:%S}\n" f"Importação iniciada em {timezone.localtime():%d/%m/%Y %H:%M:%S}\n"
"==========================================================\n" "==========================================================\n"
) )
) )
@ -693,7 +693,7 @@ class Gescon(models.Model):
data_retorno_assinatura=contrato["inicioVigencia"], data_retorno_assinatura=contrato["inicioVigencia"],
data_termino_vigencia=contrato["terminoVigencia"], data_termino_vigencia=contrato["terminoVigencia"],
data_pub_diario=contrato["publicacao"], data_pub_diario=contrato["publicacao"],
atualizacao_gescon=datetime.now(), atualizacao_gescon=timezone.localtime(),
observacao_gescon=_( observacao_gescon=_(
"Importado integralmente do" "Gescon" "Importado integralmente do" "Gescon"
), ),
@ -703,7 +703,7 @@ class Gescon(models.Model):
continue continue
elif chk == 1: elif chk == 1:
convenio = convenios.get() convenio = convenios.get()
convenio.atualizacao_gescon = datetime.now() convenio.atualizacao_gescon = timezone.localtime()
convenio.observacao_gescon = "" convenio.observacao_gescon = ""
if convenio.casa_legislativa != orgao: if convenio.casa_legislativa != orgao:
self.add_message( self.add_message(

2
sigi/apps/convenios/views.py

@ -1,7 +1,5 @@
import csv import csv
import datetime
# from django.contrib import messages # from django.contrib import messages
from django.contrib import admin from django.contrib import admin
from django.http.response import HttpResponseForbidden from django.http.response import HttpResponseForbidden

4
sigi/apps/eventos/models.py

@ -1,8 +1,8 @@
import re import re
from datetime import datetime
from django.db import models from django.db import models
from django.db.models import Sum from django.db.models import Sum
from django.urls import reverse from django.urls import reverse
from django.utils import timezone
from django.utils.translation import gettext as _ from django.utils.translation import gettext as _
from sigi.apps.casas.models import Orgao from sigi.apps.casas.models import Orgao
from sigi.apps.contatos.models import Municipio from sigi.apps.contatos.models import Municipio
@ -320,7 +320,7 @@ class Anexo(models.Model):
) )
descricao = models.CharField(_("descrição"), max_length=70) descricao = models.CharField(_("descrição"), max_length=70)
data_pub = models.DateTimeField( data_pub = models.DateTimeField(
_("data da publicação do anexo"), default=datetime.now _("data da publicação do anexo"), default=timezone.localtime
) )
convite = models.ForeignKey( convite = models.ForeignKey(
Convite, blank=True, null=True, on_delete=models.SET_NULL Convite, blank=True, null=True, on_delete=models.SET_NULL

20
sigi/apps/eventos/views.py

@ -1,5 +1,4 @@
import calendar import calendar
import datetime
import locale import locale
from django.contrib import messages from django.contrib import messages
from django.contrib.admin.sites import site from django.contrib.admin.sites import site
@ -8,6 +7,7 @@ from django.http import HttpResponse
from django.shortcuts import redirect, render, get_object_or_404 from django.shortcuts import redirect, render, get_object_or_404
from django.template import Template, Context from django.template import Template, Context
from django.template.exceptions import TemplateSyntaxError from django.template.exceptions import TemplateSyntaxError
from django.utils import timezone
from django.utils.text import slugify from django.utils.text import slugify
from django.utils.translation import to_locale, get_language, gettext as _ from django.utils.translation import to_locale, get_language, gettext as _
from django.urls import reverse from django.urls import reverse
@ -28,8 +28,8 @@ from sigi.apps.servidores.models import Servidor
@login_required @login_required
def calendario(request): def calendario(request):
mes_pesquisa = int(request.GET.get("mes", datetime.date.today().month)) mes_pesquisa = int(request.GET.get("mes", timezone.localdate().month))
ano_pesquisa = int(request.GET.get("ano", datetime.date.today().year)) ano_pesquisa = int(request.GET.get("ano", timezone.localdate().year))
formato = request.GET.get("fmt", "html") formato = request.GET.get("fmt", "html")
meses = {} meses = {}
@ -88,7 +88,7 @@ def declaracao(request, id):
"pagemargin": modelo.margem, "pagemargin": modelo.margem,
"evento": evento, "evento": evento,
"servidor": servidor, "servidor": servidor,
"data": datetime.date.today(), "data": timezone.localdate(),
} }
) )
string = Template(template_string).render(context) string = Template(template_string).render(context)
@ -187,7 +187,7 @@ def convida_casa(request, evento_id, casa_id):
evento=evento, evento=evento,
casa=casa, casa=casa,
servidor=request.user.servidor, servidor=request.user.servidor,
data_convite=datetime.date.today(), data_convite=timezone.localdate(),
) )
presidente = casa.presidente or Funcionario( presidente = casa.presidente or Funcionario(
@ -254,7 +254,7 @@ def convida_casa(request, evento_id, casa_id):
"casa": casa, "casa": casa,
"presidente": presidente, "presidente": presidente,
"contato": contato, "contato": contato,
"data": datetime.date.today(), "data": timezone.localdate(),
"ente": ente, "ente": ente,
"doravante": casa.tipo.nome.split(" ")[0], "doravante": casa.tipo.nome.split(" ")[0],
} }
@ -318,7 +318,7 @@ def gerar_anexo(casa, presidente, contato, path, modelo, nome, texto):
"casa": casa, "casa": casa,
"presidente": presidente, "presidente": presidente,
"contato": contato, "contato": contato,
"data": datetime.date.today(), "data": timezone.localdate(),
"doravante": casa.tipo.nome.split(" ")[0], "doravante": casa.tipo.nome.split(" ")[0],
} }
) )
@ -341,8 +341,8 @@ def gerar_anexo(casa, presidente, contato, path, modelo, nome, texto):
# @login_required # @login_required
# def calendario(request): # def calendario(request):
# mes_pesquisa = int(request.GET.get('mes', datetime.date.today().month)) # mes_pesquisa = int(request.GET.get('mes', timezone.localdate().month))
# ano_pesquisa = int(request.GET.get('ano', datetime.date.today().year)) # ano_pesquisa = int(request.GET.get('ano', timezone.localdate().year))
# formato = request.GET.get('fmt', 'html') # formato = request.GET.get('fmt', 'html')
# dia1 = datetime.date(ano_pesquisa, mes_pesquisa, 1) # dia1 = datetime.date(ano_pesquisa, mes_pesquisa, 1)
@ -426,7 +426,7 @@ def gerar_anexo(casa, presidente, contato, path, modelo, nome, texto):
# @login_required # @login_required
# def alocacao_equipe(request): # def alocacao_equipe(request):
# ano_pesquisa = int(request.GET.get('ano', datetime.date.today().year)) # ano_pesquisa = int(request.GET.get('ano', timezone.localdate().year))
# formato = request.GET.get('fmt', 'html') # formato = request.GET.get('fmt', 'html')
# data = {'ano_pesquisa': ano_pesquisa} # data = {'ano_pesquisa': ano_pesquisa}

3
sigi/apps/home/views.py

@ -16,6 +16,7 @@ from django.http import (
) )
from django.shortcuts import render, get_object_or_404 from django.shortcuts import render, get_object_or_404
from django.template.loader import render_to_string from django.template.loader import render_to_string
from django.utils import timezone
from django.utils.text import slugify from django.utils.text import slugify
from django.utils.translation import gettext as _ from django.utils.translation import gettext as _
from django.views.decorators.cache import never_cache from django.views.decorators.cache import never_cache
@ -358,7 +359,7 @@ def resumo_seit(request):
@never_cache @never_cache
@login_required @login_required
def chart_seit(request): def chart_seit(request):
hoje = datetime.date.today() hoje = timezone.localdate()
mes = request.GET.get("mes", hoje.month) mes = request.GET.get("mes", hoje.month)
ano = request.GET.get("ano", hoje.year) ano = request.GET.get("ano", hoje.year)

Loading…
Cancel
Save