Browse Source

Prepara app Ocorrencias para migração

revisaoSidenav
Sesostris Vieira 3 years ago
parent
commit
6623609487
  1. 69
      sigi/apps/ocorrencias/admin.py
  2. 5
      sigi/apps/ocorrencias/filters.py
  3. 45
      sigi/apps/ocorrencias/forms.py
  4. 20
      sigi/apps/ocorrencias/migrations/0001_initial.py
  5. 2
      sigi/apps/ocorrencias/migrations/0002_auto_20160308_0828.py
  6. 2
      sigi/apps/ocorrencias/migrations/0003_auto_20210406_1945.py
  7. 48
      sigi/apps/ocorrencias/migrations/0006_alter_anexo_arquivo_alter_anexo_descricao_and_more.py
  8. 105
      sigi/apps/ocorrencias/models.py
  9. 9
      sigi/settings/base.py

69
sigi/apps/ocorrencias/admin.py

@ -1,67 +1,62 @@
# -*- coding: utf-8 -*-
from django.contrib import admin from django.contrib import admin
from django.contrib.admin.views.main import ChangeList from django.contrib.admin.views.main import ChangeList
from django.utils.translation import gettext as _ 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.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.servidores.models import Servidor
from sigi.apps.utils.base_admin import BaseModelAdmin from sigi.apps.utils.base_admin import BaseModelAdmin
from sigi.apps.casas.admin import GerentesInterlegisFilter from sigi.apps.casas.admin import GerentesInterlegisFilter
class ComentarioViewInline(admin.TabularInline): class ComentarioViewInline(admin.TabularInline):
model = Comentario model = Comentario
extra = 0 extra = 0
max_num = 0 max_num = 0
can_delete = False can_delete = False
verbose_name, verbose_name_plural = _("Comentário anterior"), _("Comentários anteriores") verbose_name = _("Comentário anterior")
fields = ('usuario', 'data_criacao', 'novo_status', 'encaminhar_setor', 'descricao', ) verbose_name_plural = _("Comentários anteriores")
readonly_fields = ('novo_status', 'encaminhar_setor', 'descricao', 'data_criacao', 'usuario',) fields = ('usuario', 'data_criacao', 'novo_status', 'encaminhar_setor',
'descricao', )
readonly_fields = ('novo_status', 'encaminhar_setor', 'descricao',
'data_criacao', 'usuario',)
class ComentarioInline(admin.StackedInline): class ComentarioInline(admin.StackedInline):
model = Comentario model = Comentario
extra = 1 extra = 1
verbose_name, verbose_name_plural = _("Comentário novo"), _("Comentários novos") verbose_name = _("Comentário novo")
fieldsets = ((None, {'fields': (('novo_status', 'encaminhar_setor',), 'descricao', )}),) verbose_name_plural = _("Comentários novos")
fieldsets = ((None, {'fields': (('novo_status', 'encaminhar_setor',),
'descricao', )}),)
def get_queryset(self, queryset): def get_queryset(self, queryset):
return self.model.objects.none() return self.model.objects.none()
class AnexosInline(admin.TabularInline): class AnexosInline(admin.TabularInline):
model = Anexo model = Anexo
extra = 2 extra = 2
readonly_fields = ['data_pub', ] readonly_fields = ['data_pub', ]
class OcorrenciaChangeList(ChangeList): 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): def get_queryset(self, request):
tmp_params = self.params.copy() tmp_params = self.params.copy()
grupo = None grupo = None
if 'grupo' in self.params: if 'grupo' in self.params:
grupo = self.params['grupo'] grupo = self.params['grupo']
del 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() self.params = tmp_params.copy()
if grupo: if grupo:
servidor = Servidor.objects.get(user=self.request.user) servidor = Servidor.objects.get(user=request.user)
if grupo == 'S': # Apenas do meu setor if grupo == 'S': # Apenas do meu setor
qs = qs.filter(setor_responsavel=servidor.servico) qs = qs.filter(setor_responsavel=servidor.servico)
elif grupo == 'M': # Apenas criados por mim elif grupo == 'M': # Apenas criados por mim
qs = qs.filter(servidor_registro=servidor) qs = qs.filter(servidor_registro=servidor)
return qs return qs
@admin.register(Ocorrencia)
class OcorrenciaAdmin(BaseModelAdmin): class OcorrenciaAdmin(BaseModelAdmin):
list_display = ('data_criacao', 'casa_legislativa', 'get_municipio', list_display = ('data_criacao', 'casa_legislativa', 'get_municipio',
'get_uf', 'assunto', 'prioridade', 'status', 'get_uf', 'assunto', 'prioridade', 'status',
@ -85,22 +80,18 @@ class OcorrenciaAdmin(BaseModelAdmin):
def get_changelist(self, request, **kwargs): def get_changelist(self, request, **kwargs):
return OcorrenciaChangeList 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): def get_fieldsets(self, request, obj=None):
if obj is 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: else:
self.fields = ('casa_legislativa', 'categoria', 'tipo_contato', 'assunto', 'status', 'prioridade', 'ticket', 'descricao', self.fields = ('casa_legislativa', 'categoria', 'tipo_contato',
'servidor_registro', 'setor_responsavel', 'resolucao', ) '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): def save_model(self, request, obj, form, change):
if not change: if not change:
@ -115,19 +106,17 @@ class OcorrenciaAdmin(BaseModelAdmin):
if isinstance(instance, Comentario): if isinstance(instance, Comentario):
instance.usuario = servidor instance.usuario = servidor
instance.save() 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): 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.short_description = _('UF')
get_uf.admin_order_field = 'casa_legislativa__municipio__uf'
def get_municipio(self, obj): 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.short_description = _('Município')
get_municipio.admin_order_field = 'casa_legislativa__municipio__nome' get_municipio.admin_order_field = 'casa_legislativa__municipio__nome'
admin.site.register(Ocorrencia, OcorrenciaAdmin)
admin.site.register(Categoria) admin.site.register(Categoria)
admin.site.register(TipoContato) admin.site.register(TipoContato)

5
sigi/apps/ocorrencias/filters.py

@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
from django.contrib import admin from django.contrib import admin
from django.utils.translation import gettext as _ from django.utils.translation import gettext as _
@ -6,7 +5,6 @@ from sigi.apps.servidores.models import Servidor
class OcorrenciaListFilter(admin.SimpleListFilter): class OcorrenciaListFilter(admin.SimpleListFilter):
title = _('Relacionadas a Mim') title = _('Relacionadas a Mim')
parameter_name = 'minhas' parameter_name = 'minhas'
@ -21,7 +19,6 @@ class OcorrenciaListFilter(admin.SimpleListFilter):
def queryset(self, request, queryset): def queryset(self, request, queryset):
servidor = request.user.servidor servidor = request.user.servidor
# servidor = Servidor.objects.get(user=request.user)
if self.value() == 'S': if self.value() == 'S':
return queryset.filter(setor_responsavel=servidor.servico) return queryset.filter(setor_responsavel=servidor.servico)
elif self.value() == 'M': elif self.value() == 'M':
@ -30,3 +27,5 @@ class OcorrenciaListFilter(admin.SimpleListFilter):
return queryset.filter( return queryset.filter(
casa_legislativa__gerentes_interlegis=servidor casa_legislativa__gerentes_interlegis=servidor
) )
else:
return queryset

45
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 django.forms import ModelForm, ModelChoiceField, HiddenInput, TextInput
from sigi.apps.ocorrencias.models import Ocorrencia, Comentario, Anexo from sigi.apps.ocorrencias.models import Ocorrencia, Comentario, Anexo
from sigi.apps.servidores.models import Servico from sigi.apps.servidores.models import Servico
from django.utils.encoding import force_text from django.utils.encoding import force_text
from django.utils.html import format_html from django.utils.html import format_html
from django.forms.utils import flatatt 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 from django.utils.safestring import mark_safe
class AjaxSelect(TextInput): class AjaxSelect(TextInput):
@ -40,9 +17,9 @@ class AjaxSelect(TextInput):
if value is None: if value is None:
value = '' value = ''
final_attrs = self.build_attrs(attrs, type=self.input_type) 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 != '': if value != '':
# Only add the 'value' attribute if a value is non-empty.
final_attrs['value'] = force_text(self._format_value(value)) final_attrs['value'] = force_text(self._format_value(value))
result = format_html('<input{0} />', flatatt(final_attrs)) + "\n" result = format_html('<input{0} />', flatatt(final_attrs)) + "\n"
result = result + format_html('<input{0} />', flatatt(code_attrs)) result = result + format_html('<input{0} />', flatatt(code_attrs))
@ -68,7 +45,10 @@ class AnexoForm(ModelForm):
widgets = {'ocorrencia': HiddenInput()} widgets = {'ocorrencia': HiddenInput()}
class ComentarioForm(ModelForm): 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: class Meta:
model = Comentario model = Comentario
@ -78,6 +58,11 @@ class ComentarioForm(ModelForm):
class OcorrenciaForm(ModelForm): class OcorrenciaForm(ModelForm):
class Meta: class Meta:
model = Ocorrencia model = Ocorrencia
fields = ['casa_legislativa', 'categoria', 'tipo_contato', 'assunto', 'prioridade', 'ticket', fields = ['casa_legislativa', 'categoria', 'tipo_contato', 'assunto',
'descricao', 'setor_responsavel',] 'prioridade', 'ticket', 'descricao', 'setor_responsavel',]
widgets = {'casa_legislativa': AjaxSelect(url=reverse_lazy('painel-buscacasa'), attrs={'size':100}), } widgets = {
'casa_legislativa': AjaxSelect(
url=reverse_lazy('painel-buscacasa'),
attrs={'size':100}
),
}

20
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)), ('id', models.AutoField(verbose_name='ID', serialize=False, auto_created=True, primary_key=True)),
('nome', models.CharField(max_length=50, verbose_name='Categoria')), ('nome', models.CharField(max_length=50, verbose_name='Categoria')),
('descricao', models.TextField(null=True, verbose_name='descri\xe7\xe3o', blank=True)), ('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={ options={
'verbose_name': 'Categoria', '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)), ('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)), ('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')])), ('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={ 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')])), ('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)), ('descricao', models.TextField(verbose_name='descri\xe7\xe3o', blank=True)),
('resolucao', models.TextField(verbose_name='resolu\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')), ('casa_legislativa', models.ForeignKey(verbose_name='Casa Legislativa', to='casas.CasaLegislativa', on_delete=models.CASCADE)),
('categoria', models.ForeignKey(verbose_name='Categoria', to='ocorrencias.Categoria')), ('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')), ('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')), ('setor_responsavel', models.ForeignKey(verbose_name='Setor respons\xe1vel', to='servidores.Servico', on_delete=models.CASCADE)),
], ],
options={ options={
'ordering': ['prioridade', 'data_modificacao', 'data_criacao'], 'ordering': ['prioridade', 'data_modificacao', 'data_criacao'],
@ -92,25 +92,25 @@ class Migration(migrations.Migration):
migrations.AddField( migrations.AddField(
model_name='ocorrencia', model_name='ocorrencia',
name='tipo_contato', 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, preserve_default=True,
), ),
migrations.AddField( migrations.AddField(
model_name='comentario', model_name='comentario',
name='ocorrencia', 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, preserve_default=True,
), ),
migrations.AddField( migrations.AddField(
model_name='comentario', model_name='comentario',
name='usuario', 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, preserve_default=True,
), ),
migrations.AddField( migrations.AddField(
model_name='anexo', model_name='anexo',
name='ocorrencia', 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, preserve_default=True,
), ),
] ]

2
sigi/apps/ocorrencias/migrations/0002_auto_20160308_0828.py

@ -20,7 +20,7 @@ class Migration(migrations.Migration):
migrations.AlterField( migrations.AlterField(
model_name='comentario', model_name='comentario',
name='ocorrencia', 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, preserve_default=True,
), ),
] ]

2
sigi/apps/ocorrencias/migrations/0003_auto_20210406_1945.py

@ -15,7 +15,7 @@ class Migration(migrations.Migration):
migrations.AlterField( migrations.AlterField(
model_name='ocorrencia', model_name='ocorrencia',
name='casa_legislativa', 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, preserve_default=True,
), ),
] ]

48
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'),
),
]

105
sigi/apps/ocorrencias/models.py

@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
from django.db import models from django.db import models
from django.conf import settings from django.conf import settings
from django.utils.translation import gettext as _ from django.utils.translation import gettext as _
@ -16,23 +15,23 @@ class Categoria(models.Model):
) )
class Meta: class Meta:
verbose_name, verbose_name_plural = _('Categoria'), _('Categorias') verbose_name = _('Categoria')
verbose_name_plural = _('Categorias')
ordering = ('nome',) ordering = ('nome',)
def __unicode__(self): def __str__(self):
return self.nome return self.nome
class TipoContato(models.Model): class TipoContato(models.Model):
descricao = models.CharField(_("Descrição"), max_length=50) descricao = models.CharField(_("Descrição"), max_length=50)
class Meta: 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 return self.descricao
class Ocorrencia(models.Model): class Ocorrencia(models.Model):
STATUS_ABERTO = 1 STATUS_ABERTO = 1
STATUS_REABERTO = 2 STATUS_REABERTO = 2
@ -61,8 +60,18 @@ class Ocorrencia(models.Model):
on_delete=models.CASCADE, on_delete=models.CASCADE,
verbose_name=_('Casa Legislativa') verbose_name=_('Casa Legislativa')
) )
data_criacao = models.DateField(_('Data de criação'), null=True, blank=True, auto_now_add=True) data_criacao = models.DateField(
data_modificacao = models.DateField(_('Data de modificação'), null=True, blank=True, auto_now=True) _('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 = models.ForeignKey(
Categoria, Categoria,
on_delete=models.PROTECT, on_delete=models.PROTECT,
@ -74,8 +83,16 @@ class Ocorrencia(models.Model):
verbose_name=_("Tipo de contato") verbose_name=_("Tipo de contato")
) )
assunto = models.CharField(_('Assunto'), max_length=200) assunto = models.CharField(_('Assunto'), max_length=200)
status = models.IntegerField(_('Status'), choices=STATUS_CHOICES, default=1,) status = models.IntegerField(
prioridade = models.IntegerField(_('Prioridade'), choices=PRIORITY_CHOICES, default=3, ) _('Status'),
choices=STATUS_CHOICES,
default=1
)
prioridade = models.IntegerField(
_('Prioridade'),
choices=PRIORITY_CHOICES,
default=3
)
descricao = models.TextField(_('descrição'), blank=True,) descricao = models.TextField(_('descrição'), blank=True,)
resolucao = models.TextField(_('resolução'), blank=True,) resolucao = models.TextField(_('resolução'), blank=True,)
servidor_registro = models.ForeignKey( servidor_registro = models.ForeignKey(
@ -88,18 +105,28 @@ class Ocorrencia(models.Model):
on_delete=models.PROTECT, on_delete=models.PROTECT,
verbose_name=_("Setor responsável") 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: 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', ] ordering = ['prioridade', 'data_modificacao', 'data_criacao', ]
def __unicode__(self): def __str__(self):
return "%(casa_legislativa)s: %(assunto)s" % {'assunto': self.assunto, 'casa_legislativa': self.casa_legislativa} return _(f"{self.casa_legislativa}: {self.assunto}")
def clean(self): def clean(self):
if self.ticket is not None and Ocorrencia.objects.exclude(pk=self.pk).filter(ticket=self.ticket).exists(): if (self.ticket is not None
raise ValidationError({'ticket': _("Já existe ocorrência registrada para este ticket")}) 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() return super(Ocorrencia, self).clean()
def get_ticket_url(self): def get_ticket_url(self):
@ -112,14 +139,24 @@ class Comentario(models.Model):
verbose_name=_('Ocorrência'), verbose_name=_('Ocorrência'),
related_name='comentarios' 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) descricao = models.TextField(_('Descrição'), blank=True, null=True)
usuario = models.ForeignKey( usuario = models.ForeignKey(
'servidores.Servidor', 'servidores.Servidor',
on_delete=models.PROTECT, on_delete=models.PROTECT,
verbose_name=_('Usuário') 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( encaminhar_setor = models.ForeignKey(
'servidores.Servico', 'servidores.Servico',
on_delete=models.PROTECT, on_delete=models.PROTECT,
@ -129,7 +166,9 @@ class Comentario(models.Model):
) )
def save(self, *args, **kwargs): 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.setor_responsavel = self.encaminhar_setor
self.ocorrencia.save() self.ocorrencia.save()
if self.novo_status and (self.novo_status != self.ocorrencia.status): if self.novo_status and (self.novo_status != self.ocorrencia.status):
@ -137,20 +176,32 @@ class Comentario(models.Model):
self.ocorrencia.save() self.ocorrencia.save()
super(Comentario, self).save(*args, **kwargs) super(Comentario, self).save(*args, **kwargs)
class Anexo(models.Model): class Anexo(models.Model):
ocorrencia = models.ForeignKey( ocorrencia = models.ForeignKey(
Ocorrencia, Ocorrencia,
on_delete=models.CASCADE, on_delete=models.CASCADE,
verbose_name=_('ocorrência') verbose_name=_('ocorrência')
) )
arquivo = models.FileField(_('Arquivo anexado'), upload_to='apps/ocorrencia/anexo/arquivo', max_length=500) arquivo = models.FileField(
descricao = models.CharField(_('descrição do anexo'), max_length='70') _('Arquivo anexado'),
data_pub = models.DateTimeField(_('data da publicação do anexo'), null=True, blank=True, auto_now_add=True) 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: class Meta:
ordering = ('-data_pub',) ordering = ('-data_pub',)
verbose_name, verbose_name_plural = _('Anexo'), _('Anexos') verbose_name = _('Anexo')
verbose_name_plural =_('Anexos')
def __unicode__(self): def __str__(self):
return "%(arquivo_name)s: %(descricao)s" % {'arquivo_name': self.arquivo.name, 'descricao': self.descricao} return _(f"{self.arquivo.name}: {self.descricao}")

9
sigi/settings/base.py

@ -20,14 +20,15 @@ BASE_DIR = Path(__file__).resolve().parent.parent
# Application definition # Application definition
INSTALLED_APPS = [ INSTALLED_APPS = [
'sigi.apps.servidores',
'sigi.apps.contatos',
'sigi.apps.utils',
'sigi.apps.casas', 'sigi.apps.casas',
'sigi.apps.contatos',
'sigi.apps.convenios', 'sigi.apps.convenios',
'sigi.apps.eventos',
'sigi.apps.inventario', 'sigi.apps.inventario',
'sigi.apps.ocorrencias',
'sigi.apps.servicos', 'sigi.apps.servicos',
'sigi.apps.eventos', 'sigi.apps.servidores',
'sigi.apps.utils',
'localflavor', 'localflavor',
'import_export', 'import_export',
'tinymce', 'tinymce',

Loading…
Cancel
Save