From 66236094874dc7f8c470e72e84e1690c6303388d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ses=C3=B3stris=20Vieira?= Date: Thu, 20 Jan 2022 21:11:14 -0300 Subject: [PATCH] =?UTF-8?q?Prepara=20app=20Ocorrencias=20para=20migra?= =?UTF-8?q?=C3=A7=C3=A3o?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- sigi/apps/ocorrencias/admin.py | 69 +++++------- sigi/apps/ocorrencias/filters.py | 5 +- sigi/apps/ocorrencias/forms.py | 53 ++++----- .../ocorrencias/migrations/0001_initial.py | 20 ++-- .../migrations/0002_auto_20160308_0828.py | 2 +- .../migrations/0003_auto_20210406_1945.py | 2 +- ..._arquivo_alter_anexo_descricao_and_more.py | 48 ++++++++ sigi/apps/ocorrencias/models.py | 105 +++++++++++++----- sigi/settings/base.py | 9 +- 9 files changed, 193 insertions(+), 120 deletions(-) create mode 100644 sigi/apps/ocorrencias/migrations/0006_alter_anexo_arquivo_alter_anexo_descricao_and_more.py diff --git a/sigi/apps/ocorrencias/admin.py b/sigi/apps/ocorrencias/admin.py index c7a093f..9a407ee 100644 --- a/sigi/apps/ocorrencias/admin.py +++ b/sigi/apps/ocorrencias/admin.py @@ -1,67 +1,62 @@ -# -*- coding: utf-8 -*- from django.contrib import admin from django.contrib.admin.views.main import ChangeList from django.utils.translation import gettext as _ +from django.utils.safestring import mark_safe from sigi.apps.ocorrencias.filters import OcorrenciaListFilter -from sigi.apps.ocorrencias.models import Ocorrencia, Comentario, Anexo, Categoria, TipoContato +from sigi.apps.ocorrencias.models import (Ocorrencia, Comentario, Anexo, + Categoria, TipoContato) from sigi.apps.servidores.models import Servidor from sigi.apps.utils.base_admin import BaseModelAdmin from sigi.apps.casas.admin import GerentesInterlegisFilter + class ComentarioViewInline(admin.TabularInline): model = Comentario extra = 0 max_num = 0 can_delete = False - verbose_name, verbose_name_plural = _("Comentário anterior"), _("Comentários anteriores") - fields = ('usuario', 'data_criacao', 'novo_status', 'encaminhar_setor', 'descricao', ) - readonly_fields = ('novo_status', 'encaminhar_setor', 'descricao', 'data_criacao', 'usuario',) - + verbose_name = _("Comentário anterior") + verbose_name_plural = _("Comentários anteriores") + fields = ('usuario', 'data_criacao', 'novo_status', 'encaminhar_setor', + 'descricao', ) + readonly_fields = ('novo_status', 'encaminhar_setor', 'descricao', + 'data_criacao', 'usuario',) class ComentarioInline(admin.StackedInline): model = Comentario extra = 1 - verbose_name, verbose_name_plural = _("Comentário novo"), _("Comentários novos") - fieldsets = ((None, {'fields': (('novo_status', 'encaminhar_setor',), 'descricao', )}),) + verbose_name = _("Comentário novo") + verbose_name_plural = _("Comentários novos") + fieldsets = ((None, {'fields': (('novo_status', 'encaminhar_setor',), + 'descricao', )}),) def get_queryset(self, queryset): return self.model.objects.none() - class AnexosInline(admin.TabularInline): model = Anexo extra = 2 readonly_fields = ['data_pub', ] - class OcorrenciaChangeList(ChangeList): - request = None - - def __init__(self, request, model, list_display, list_display_links, list_filter, date_hierarchy, search_fields, - list_select_related, list_per_page, list_max_show_all, list_editable, model_admin): - self.request = request - super(OcorrenciaChangeList, self).__init__(request, model, list_display, list_display_links, list_filter, - date_hierarchy, search_fields, list_select_related, list_per_page, - list_max_show_all, list_editable, model_admin) - def get_queryset(self, request): tmp_params = self.params.copy() grupo = None if 'grupo' in self.params: grupo = self.params['grupo'] del self.params['grupo'] - qs = super(OcorrenciaChangeList, self).get_query_set(request) + qs = super().get_queryset(request) self.params = tmp_params.copy() if grupo: - servidor = Servidor.objects.get(user=self.request.user) + servidor = Servidor.objects.get(user=request.user) if grupo == 'S': # Apenas do meu setor qs = qs.filter(setor_responsavel=servidor.servico) elif grupo == 'M': # Apenas criados por mim qs = qs.filter(servidor_registro=servidor) return qs - +@admin.register(Ocorrencia) class OcorrenciaAdmin(BaseModelAdmin): list_display = ('data_criacao', 'casa_legislativa', 'get_municipio', 'get_uf', 'assunto', 'prioridade', 'status', @@ -85,22 +80,18 @@ class OcorrenciaAdmin(BaseModelAdmin): def get_changelist(self, request, **kwargs): return OcorrenciaChangeList - # def get_readonly_fields(self, request, obj=None): - # fields = list(self.readonly_fields) - # if obj is not None: - # fields.extend(['casa_legislativa', 'categoria', 'tipo_contato', 'assunto', 'status', 'descricao', ]) - # if obj.status in [Ocorrencia.STATUS_RESOLVIDO, Ocorrencia.STATUS_FECHADO, Ocorrencia.STATUS_DUPLICADO]: # Fechados - # fields.append('prioridade') - # return fields - def get_fieldsets(self, request, obj=None): if obj is None: - self.fields = ('casa_legislativa', 'categoria', 'tipo_contato', 'assunto', 'prioridade', 'ticket', 'descricao', 'resolucao', ) + self.fields = ('casa_legislativa', 'categoria', 'tipo_contato', + 'assunto', 'prioridade', 'ticket', 'descricao', + 'resolucao', ) else: - self.fields = ('casa_legislativa', 'categoria', 'tipo_contato', 'assunto', 'status', 'prioridade', 'ticket', 'descricao', - 'servidor_registro', 'setor_responsavel', 'resolucao', ) + self.fields = ('casa_legislativa', 'categoria', 'tipo_contato', + 'assunto', 'status', 'prioridade', 'ticket', + 'descricao', 'servidor_registro', + 'setor_responsavel', 'resolucao', ) - return super(OcorrenciaAdmin, self).get_fieldsets(request, obj) + return super().get_fieldsets(request, obj) def save_model(self, request, obj, form, change): if not change: @@ -115,19 +106,17 @@ class OcorrenciaAdmin(BaseModelAdmin): if isinstance(instance, Comentario): instance.usuario = servidor instance.save() - super(OcorrenciaAdmin, self).save_formset(request, form, formset, change) + super(OcorrenciaAdmin, self).save_formset(request, form, formset, + change) def get_uf(self, obj): - return obj.casa_legislativa.municipio.uf + return mark_safe(obj.casa_legislativa.municipio.uf) get_uf.short_description = _('UF') - get_uf.admin_order_field = 'casa_legislativa__municipio__uf' def get_municipio(self, obj): - return obj.casa_legislativa.municipio.nome + return mark_safe(obj.casa_legislativa.municipio.nome) get_municipio.short_description = _('Município') get_municipio.admin_order_field = 'casa_legislativa__municipio__nome' - -admin.site.register(Ocorrencia, OcorrenciaAdmin) admin.site.register(Categoria) admin.site.register(TipoContato) diff --git a/sigi/apps/ocorrencias/filters.py b/sigi/apps/ocorrencias/filters.py index 6f567e1..e855359 100644 --- a/sigi/apps/ocorrencias/filters.py +++ b/sigi/apps/ocorrencias/filters.py @@ -1,4 +1,3 @@ -# -*- coding: utf-8 -*- from django.contrib import admin from django.utils.translation import gettext as _ @@ -6,7 +5,6 @@ from sigi.apps.servidores.models import Servidor class OcorrenciaListFilter(admin.SimpleListFilter): - title = _('Relacionadas a Mim') parameter_name = 'minhas' @@ -21,7 +19,6 @@ class OcorrenciaListFilter(admin.SimpleListFilter): def queryset(self, request, queryset): servidor = request.user.servidor - # servidor = Servidor.objects.get(user=request.user) if self.value() == 'S': return queryset.filter(setor_responsavel=servidor.servico) elif self.value() == 'M': @@ -30,3 +27,5 @@ class OcorrenciaListFilter(admin.SimpleListFilter): return queryset.filter( casa_legislativa__gerentes_interlegis=servidor ) + else: + return queryset diff --git a/sigi/apps/ocorrencias/forms.py b/sigi/apps/ocorrencias/forms.py index bc37fea..1b67c25 100644 --- a/sigi/apps/ocorrencias/forms.py +++ b/sigi/apps/ocorrencias/forms.py @@ -1,33 +1,10 @@ -# -*- coding: utf-8 -*- -# -# sigi.apps.ocorrencias.forms -# -# Copyright (c) 2015 by Interlegis -# -# GNU General Public License (GPL) -# -# This program is free software; you can redistribute it and/or -# modify it under the terms of the GNU General Public License -# as published by the Free Software Foundation; either version 2 -# of the License, or (at your option) any later version. -# -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with this program; if not, write to the Free Software -# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -# 02110-1301, USA. -# from django.forms import ModelForm, ModelChoiceField, HiddenInput, TextInput from sigi.apps.ocorrencias.models import Ocorrencia, Comentario, Anexo from sigi.apps.servidores.models import Servico from django.utils.encoding import force_text from django.utils.html import format_html from django.forms.utils import flatatt -from django.core.urlresolvers import reverse_lazy +from django.urls import reverse_lazy from django.utils.safestring import mark_safe class AjaxSelect(TextInput): @@ -35,14 +12,14 @@ class AjaxSelect(TextInput): def __init__(self, url, attrs=None): super(AjaxSelect, self).__init__(attrs) self.url = url - + def render(self, name, value, attrs=None): if value is None: value = '' final_attrs = self.build_attrs(attrs, type=self.input_type) - code_attrs = self.build_attrs(type='hidden', name=name, id='hidden_'+name) + code_attrs = self.build_attrs(type='hidden', name=name, + id='hidden_'+name) if value != '': - # Only add the 'value' attribute if a value is non-empty. final_attrs['value'] = force_text(self._format_value(value)) result = format_html('', flatatt(final_attrs)) + "\n" result = result + format_html('', flatatt(code_attrs)) @@ -59,8 +36,8 @@ class AjaxSelect(TextInput): }); """ % {'name': name, 'url': self.url} result = result + mark_safe(js) - return result - + return result + class AnexoForm(ModelForm): class Meta: model = Anexo @@ -68,8 +45,11 @@ class AnexoForm(ModelForm): widgets = {'ocorrencia': HiddenInput()} class ComentarioForm(ModelForm): - encaminhar_setor = ModelChoiceField(queryset=Servico.objects.all(), cache_choices=True) - + encaminhar_setor = ModelChoiceField( + queryset=Servico.objects.all(), + cache_choices=True + ) + class Meta: model = Comentario fields = ['ocorrencia', 'descricao', 'novo_status', 'encaminhar_setor'] @@ -78,6 +58,11 @@ class ComentarioForm(ModelForm): class OcorrenciaForm(ModelForm): class Meta: model = Ocorrencia - fields = ['casa_legislativa', 'categoria', 'tipo_contato', 'assunto', 'prioridade', 'ticket', - 'descricao', 'setor_responsavel',] - widgets = {'casa_legislativa': AjaxSelect(url=reverse_lazy('painel-buscacasa'), attrs={'size':100}), } \ No newline at end of file + fields = ['casa_legislativa', 'categoria', 'tipo_contato', 'assunto', + 'prioridade', 'ticket', 'descricao', 'setor_responsavel',] + widgets = { + 'casa_legislativa': AjaxSelect( + url=reverse_lazy('painel-buscacasa'), + attrs={'size':100} + ), + } \ No newline at end of file diff --git a/sigi/apps/ocorrencias/migrations/0001_initial.py b/sigi/apps/ocorrencias/migrations/0001_initial.py index 12d05e7..c6f0a63 100644 --- a/sigi/apps/ocorrencias/migrations/0001_initial.py +++ b/sigi/apps/ocorrencias/migrations/0001_initial.py @@ -33,7 +33,7 @@ class Migration(migrations.Migration): ('id', models.AutoField(verbose_name='ID', serialize=False, auto_created=True, primary_key=True)), ('nome', models.CharField(max_length=50, verbose_name='Categoria')), ('descricao', models.TextField(null=True, verbose_name='descri\xe7\xe3o', blank=True)), - ('setor_responsavel', models.ForeignKey(verbose_name='Setor respons\xe1vel', to='servidores.Servico')), + ('setor_responsavel', models.ForeignKey(verbose_name='Setor respons\xe1vel', to='servidores.Servico', on_delete=models.CASCADE)), ], options={ 'verbose_name': 'Categoria', @@ -48,7 +48,7 @@ class Migration(migrations.Migration): ('data_criacao', models.DateTimeField(auto_now_add=True, verbose_name='Data de cria\xe7\xe3o', null=True)), ('descricao', models.TextField(null=True, verbose_name='Descri\xe7\xe3o', blank=True)), ('novo_status', models.IntegerField(blank=True, null=True, verbose_name='Novo status', choices=[(1, 'Aberto'), (2, 'Reaberto'), (3, 'Resolvido'), (4, 'Fechado'), (5, 'Duplicado')])), - ('encaminhar_setor', models.ForeignKey(verbose_name='Encaminhar para setor', blank=True, to='servidores.Servico', null=True)), + ('encaminhar_setor', models.ForeignKey(verbose_name='Encaminhar para setor', blank=True, to='servidores.Servico', null=True, on_delete=models.CASCADE)), ], options={ }, @@ -65,10 +65,10 @@ class Migration(migrations.Migration): ('prioridade', models.IntegerField(default=3, verbose_name='Prioridade', choices=[(1, 'Alt\xedssimo'), (2, 'Alto'), (3, 'Normal'), (4, 'Baixo'), (5, 'Baix\xedssimo')])), ('descricao', models.TextField(verbose_name='descri\xe7\xe3o', blank=True)), ('resolucao', models.TextField(verbose_name='resolu\xe7\xe3o', blank=True)), - ('casa_legislativa', models.ForeignKey(verbose_name='Casa Legislativa', to='casas.CasaLegislativa')), - ('categoria', models.ForeignKey(verbose_name='Categoria', to='ocorrencias.Categoria')), - ('servidor_registro', models.ForeignKey(verbose_name='Servidor que registrou a ocorr\xeancia', to='servidores.Servidor')), - ('setor_responsavel', models.ForeignKey(verbose_name='Setor respons\xe1vel', to='servidores.Servico')), + ('casa_legislativa', models.ForeignKey(verbose_name='Casa Legislativa', to='casas.CasaLegislativa', on_delete=models.CASCADE)), + ('categoria', models.ForeignKey(verbose_name='Categoria', to='ocorrencias.Categoria', on_delete=models.CASCADE)), + ('servidor_registro', models.ForeignKey(verbose_name='Servidor que registrou a ocorr\xeancia', to='servidores.Servidor', on_delete=models.CASCADE)), + ('setor_responsavel', models.ForeignKey(verbose_name='Setor respons\xe1vel', to='servidores.Servico', on_delete=models.CASCADE)), ], options={ 'ordering': ['prioridade', 'data_modificacao', 'data_criacao'], @@ -92,25 +92,25 @@ class Migration(migrations.Migration): migrations.AddField( model_name='ocorrencia', name='tipo_contato', - field=models.ForeignKey(verbose_name='Tipo de contato', to='ocorrencias.TipoContato'), + field=models.ForeignKey(verbose_name='Tipo de contato', to='ocorrencias.TipoContato', on_delete=models.CASCADE), preserve_default=True, ), migrations.AddField( model_name='comentario', name='ocorrencia', - field=models.ForeignKey(verbose_name='Ocorr\xeancia', to='ocorrencias.Ocorrencia'), + field=models.ForeignKey(verbose_name='Ocorr\xeancia', to='ocorrencias.Ocorrencia', on_delete=models.CASCADE), preserve_default=True, ), migrations.AddField( model_name='comentario', name='usuario', - field=models.ForeignKey(verbose_name='Usu\xe1rio', to='servidores.Servidor'), + field=models.ForeignKey(verbose_name='Usu\xe1rio', to='servidores.Servidor', on_delete=models.CASCADE), preserve_default=True, ), migrations.AddField( model_name='anexo', name='ocorrencia', - field=models.ForeignKey(verbose_name='ocorr\xeancia', to='ocorrencias.Ocorrencia'), + field=models.ForeignKey(verbose_name='ocorr\xeancia', to='ocorrencias.Ocorrencia', on_delete=models.CASCADE), preserve_default=True, ), ] diff --git a/sigi/apps/ocorrencias/migrations/0002_auto_20160308_0828.py b/sigi/apps/ocorrencias/migrations/0002_auto_20160308_0828.py index f4aea1f..3ba07ed 100644 --- a/sigi/apps/ocorrencias/migrations/0002_auto_20160308_0828.py +++ b/sigi/apps/ocorrencias/migrations/0002_auto_20160308_0828.py @@ -20,7 +20,7 @@ class Migration(migrations.Migration): migrations.AlterField( model_name='comentario', name='ocorrencia', - field=models.ForeignKey(related_name='comentarios', verbose_name='Ocorr\xeancia', to='ocorrencias.Ocorrencia'), + field=models.ForeignKey(related_name='comentarios', verbose_name='Ocorr\xeancia', to='ocorrencias.Ocorrencia', on_delete=models.CASCADE), preserve_default=True, ), ] diff --git a/sigi/apps/ocorrencias/migrations/0003_auto_20210406_1945.py b/sigi/apps/ocorrencias/migrations/0003_auto_20210406_1945.py index 03ef359..e9f05b5 100644 --- a/sigi/apps/ocorrencias/migrations/0003_auto_20210406_1945.py +++ b/sigi/apps/ocorrencias/migrations/0003_auto_20210406_1945.py @@ -15,7 +15,7 @@ class Migration(migrations.Migration): migrations.AlterField( model_name='ocorrencia', name='casa_legislativa', - field=models.ForeignKey(verbose_name='Casa Legislativa', to='casas.Orgao'), + field=models.ForeignKey(verbose_name='Casa Legislativa', to='casas.Orgao', on_delete=models.CASCADE), preserve_default=True, ), ] diff --git a/sigi/apps/ocorrencias/migrations/0006_alter_anexo_arquivo_alter_anexo_descricao_and_more.py b/sigi/apps/ocorrencias/migrations/0006_alter_anexo_arquivo_alter_anexo_descricao_and_more.py new file mode 100644 index 0000000..024cb0f --- /dev/null +++ b/sigi/apps/ocorrencias/migrations/0006_alter_anexo_arquivo_alter_anexo_descricao_and_more.py @@ -0,0 +1,48 @@ +# Generated by Django 4.0.1 on 2022-01-21 00:09 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('ocorrencias', '0005_auto_20210611_0946'), + ] + + operations = [ + migrations.AlterField( + model_name='anexo', + name='arquivo', + field=models.FileField(max_length=500, upload_to='apps/ocorrencia/anexo/arquivo', verbose_name='Arquivo anexado'), + ), + migrations.AlterField( + model_name='anexo', + name='descricao', + field=models.CharField(max_length=70, verbose_name='descrição do anexo'), + ), + migrations.AlterField( + model_name='anexo', + name='id', + field=models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID'), + ), + migrations.AlterField( + model_name='categoria', + name='id', + field=models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID'), + ), + migrations.AlterField( + model_name='comentario', + name='id', + field=models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID'), + ), + migrations.AlterField( + model_name='ocorrencia', + name='id', + field=models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID'), + ), + migrations.AlterField( + model_name='tipocontato', + name='id', + field=models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID'), + ), + ] diff --git a/sigi/apps/ocorrencias/models.py b/sigi/apps/ocorrencias/models.py index e5bb193..040c8ea 100644 --- a/sigi/apps/ocorrencias/models.py +++ b/sigi/apps/ocorrencias/models.py @@ -1,4 +1,3 @@ -# -*- coding: utf-8 -*- from django.db import models from django.conf import settings from django.utils.translation import gettext as _ @@ -16,23 +15,23 @@ class Categoria(models.Model): ) class Meta: - verbose_name, verbose_name_plural = _('Categoria'), _('Categorias') + verbose_name = _('Categoria') + verbose_name_plural = _('Categorias') ordering = ('nome',) - def __unicode__(self): + def __str__(self): return self.nome - class TipoContato(models.Model): descricao = models.CharField(_("Descrição"), max_length=50) class Meta: - verbose_name, verbose_name_plural = _("Tipo de contato"), _("Tipos de contato") + verbose_name = _("Tipo de contato") + verbose_name_plural = _("Tipos de contato") - def __unicode__(self): + def __str__(self): return self.descricao - class Ocorrencia(models.Model): STATUS_ABERTO = 1 STATUS_REABERTO = 2 @@ -61,8 +60,18 @@ class Ocorrencia(models.Model): on_delete=models.CASCADE, verbose_name=_('Casa Legislativa') ) - data_criacao = models.DateField(_('Data de criação'), null=True, blank=True, auto_now_add=True) - data_modificacao = models.DateField(_('Data de modificação'), null=True, blank=True, auto_now=True) + data_criacao = models.DateField( + _('Data de criação'), + null=True, + blank=True, + auto_now_add=True + ) + data_modificacao = models.DateField( + _('Data de modificação'), + null=True, + blank=True, + auto_now=True + ) categoria = models.ForeignKey( Categoria, on_delete=models.PROTECT, @@ -74,8 +83,16 @@ class Ocorrencia(models.Model): verbose_name=_("Tipo de contato") ) assunto = models.CharField(_('Assunto'), max_length=200) - status = models.IntegerField(_('Status'), choices=STATUS_CHOICES, default=1,) - prioridade = models.IntegerField(_('Prioridade'), choices=PRIORITY_CHOICES, default=3, ) + status = models.IntegerField( + _('Status'), + choices=STATUS_CHOICES, + default=1 + ) + prioridade = models.IntegerField( + _('Prioridade'), + choices=PRIORITY_CHOICES, + default=3 + ) descricao = models.TextField(_('descrição'), blank=True,) resolucao = models.TextField(_('resolução'), blank=True,) servidor_registro = models.ForeignKey( @@ -88,18 +105,28 @@ class Ocorrencia(models.Model): on_delete=models.PROTECT, verbose_name=_("Setor responsável") ) - ticket = models.PositiveIntegerField(_('Número do ticket'), blank=True, null=True, help_text=_("Número do ticket no osTicket")) + ticket = models.PositiveIntegerField( + _('Número do ticket'), + blank=True, + null=True, + help_text=_("Número do ticket no osTicket") + ) class Meta: - verbose_name, verbose_name_plural = _('ocorrência'), _('ocorrências') + verbose_name = _('ocorrência') + verbose_name_plural = _('ocorrências') ordering = ['prioridade', 'data_modificacao', 'data_criacao', ] - def __unicode__(self): - return "%(casa_legislativa)s: %(assunto)s" % {'assunto': self.assunto, 'casa_legislativa': self.casa_legislativa} + def __str__(self): + return _(f"{self.casa_legislativa}: {self.assunto}") def clean(self): - if self.ticket is not None and Ocorrencia.objects.exclude(pk=self.pk).filter(ticket=self.ticket).exists(): - raise ValidationError({'ticket': _("Já existe ocorrência registrada para este ticket")}) + if (self.ticket is not None + and Ocorrencia.objects.exclude(pk=self.pk).filter( + ticket=self.ticket).exists() + ): + raise ValidationError({'ticket': _("Já existe ocorrência " + "registrada para este ticket")}) return super(Ocorrencia, self).clean() def get_ticket_url(self): @@ -112,14 +139,24 @@ class Comentario(models.Model): verbose_name=_('Ocorrência'), related_name='comentarios' ) - data_criacao = models.DateTimeField(_('Data de criação'), null=True, blank=True, auto_now_add=True) + data_criacao = models.DateTimeField( + _('Data de criação'), + null=True, + blank=True, + auto_now_add=True + ) descricao = models.TextField(_('Descrição'), blank=True, null=True) usuario = models.ForeignKey( 'servidores.Servidor', on_delete=models.PROTECT, verbose_name=_('Usuário') ) - novo_status = models.IntegerField(_('Novo status'), choices=Ocorrencia.STATUS_CHOICES, blank=True, null=True) + novo_status = models.IntegerField( + _('Novo status'), + choices=Ocorrencia.STATUS_CHOICES, + blank=True, + null=True + ) encaminhar_setor = models.ForeignKey( 'servidores.Servico', on_delete=models.PROTECT, @@ -129,7 +166,9 @@ class Comentario(models.Model): ) def save(self, *args, **kwargs): - if self.encaminhar_setor and (self.encaminhar_setor != self.ocorrencia.setor_responsavel): + if (self.encaminhar_setor + and (self.encaminhar_setor != self.ocorrencia.setor_responsavel) + ): self.ocorrencia.setor_responsavel = self.encaminhar_setor self.ocorrencia.save() if self.novo_status and (self.novo_status != self.ocorrencia.status): @@ -137,20 +176,32 @@ class Comentario(models.Model): self.ocorrencia.save() super(Comentario, self).save(*args, **kwargs) - class Anexo(models.Model): ocorrencia = models.ForeignKey( Ocorrencia, on_delete=models.CASCADE, verbose_name=_('ocorrência') ) - arquivo = models.FileField(_('Arquivo anexado'), upload_to='apps/ocorrencia/anexo/arquivo', max_length=500) - descricao = models.CharField(_('descrição do anexo'), max_length='70') - data_pub = models.DateTimeField(_('data da publicação do anexo'), null=True, blank=True, auto_now_add=True) + arquivo = models.FileField( + _('Arquivo anexado'), + upload_to='apps/ocorrencia/anexo/arquivo', + max_length=500 + ) + descricao = models.CharField( + _('descrição do anexo'), + max_length=70 + ) + data_pub = models.DateTimeField( + _('data da publicação do anexo'), + null=True, + blank=True, + auto_now_add=True + ) class Meta: ordering = ('-data_pub',) - verbose_name, verbose_name_plural = _('Anexo'), _('Anexos') + verbose_name = _('Anexo') + verbose_name_plural =_('Anexos') - def __unicode__(self): - return "%(arquivo_name)s: %(descricao)s" % {'arquivo_name': self.arquivo.name, 'descricao': self.descricao} + def __str__(self): + return _(f"{self.arquivo.name}: {self.descricao}") diff --git a/sigi/settings/base.py b/sigi/settings/base.py index b23da5f..1456648 100644 --- a/sigi/settings/base.py +++ b/sigi/settings/base.py @@ -20,14 +20,15 @@ BASE_DIR = Path(__file__).resolve().parent.parent # Application definition INSTALLED_APPS = [ - 'sigi.apps.servidores', - 'sigi.apps.contatos', - 'sigi.apps.utils', 'sigi.apps.casas', + 'sigi.apps.contatos', 'sigi.apps.convenios', + 'sigi.apps.eventos', 'sigi.apps.inventario', + 'sigi.apps.ocorrencias', 'sigi.apps.servicos', - 'sigi.apps.eventos', + 'sigi.apps.servidores', + 'sigi.apps.utils', 'localflavor', 'import_export', 'tinymce',