Browse Source

Move business rule to correct place

producao
Sesostris Vieira 10 years ago
parent
commit
88ed299e56
  1. 8
      sigi/apps/ocorrencias/admin.py
  2. 11
      sigi/apps/ocorrencias/models.py

8
sigi/apps/ocorrencias/admin.py

@ -26,7 +26,7 @@ class ComentarioInline(admin.StackedInline):
fieldsets = ((None, {'fields': (('novo_status', 'encaminhar_setor',), 'descricao', )}),) fieldsets = ((None, {'fields': (('novo_status', 'encaminhar_setor',), 'descricao', )}),)
def get_queryset(self, queryset): def get_queryset(self, queryset):
return self.model.objects.get_query_set() return self.model.objects.none()
class AnexosInline(admin.TabularInline): class AnexosInline(admin.TabularInline):
@ -105,12 +105,6 @@ class OcorrenciaAdmin(BaseModelAdmin):
for instance in instances: for instance in instances:
if isinstance(instance, Comentario): if isinstance(instance, Comentario):
instance.usuario = servidor instance.usuario = servidor
if instance.encaminhar_setor and (instance.encaminhar_setor != instance.ocorrencia.setor_responsavel):
instance.ocorrencia.setor_responsavel = instance.encaminhar_setor
instance.ocorrencia.save()
if instance.novo_status and (instance.novo_status != instance.ocorrencia.status):
instance.ocorrencia.status = instance.novo_status
instance.ocorrencia.save()
instance.save() instance.save()
super(OcorrenciaAdmin, self).save_formset(request, form, formset, change) super(OcorrenciaAdmin, self).save_formset(request, form, formset, change)

11
sigi/apps/ocorrencias/models.py

@ -68,13 +68,22 @@ class Ocorrencia(models.Model):
class Comentario(models.Model): class Comentario(models.Model):
ocorrencia = models.ForeignKey(Ocorrencia, verbose_name=_(u'Ocorrência')) ocorrencia = models.ForeignKey(Ocorrencia, verbose_name=_(u'Ocorrência'), related_name='comentarios')
data_criacao = models.DateTimeField(_(u'Data de criação'), null=True, blank=True, auto_now_add=True) data_criacao = models.DateTimeField(_(u'Data de criação'), null=True, blank=True, auto_now_add=True)
descricao = models.TextField(_(u'Descrição'), blank=True, null=True) descricao = models.TextField(_(u'Descrição'), blank=True, null=True)
usuario = models.ForeignKey('servidores.Servidor', verbose_name=_(u'Usuário')) usuario = models.ForeignKey('servidores.Servidor', verbose_name=_(u'Usuário'))
novo_status = models.IntegerField(_(u'Novo status'), choices=Ocorrencia.STATUS_CHOICES, blank=True, null=True) novo_status = models.IntegerField(_(u'Novo status'), choices=Ocorrencia.STATUS_CHOICES, blank=True, null=True)
encaminhar_setor = models.ForeignKey('servidores.Servico', verbose_name=_(u'Encaminhar para setor'), blank=True, null=True) encaminhar_setor = models.ForeignKey('servidores.Servico', verbose_name=_(u'Encaminhar para setor'), blank=True, null=True)
def save(self, *args, **kwargs):
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):
self.ocorrencia.status = self.novo_status
self.ocorrencia.save()
super(Comentario, self).save(*args, **kwargs)
class Anexo(models.Model): class Anexo(models.Model):
ocorrencia = models.ForeignKey(Ocorrencia, verbose_name=_(u'ocorrência')) ocorrencia = models.ForeignKey(Ocorrencia, verbose_name=_(u'ocorrência'))

Loading…
Cancel
Save