diff --git a/sigi/apps/ocorrencias/admin.py b/sigi/apps/ocorrencias/admin.py index ee37784..502d040 100644 --- a/sigi/apps/ocorrencias/admin.py +++ b/sigi/apps/ocorrencias/admin.py @@ -1,17 +1,15 @@ # -*- coding: utf-8 -*- -from django.core.urlresolvers import reverse -from django.http import HttpResponseRedirect from django.contrib import admin from django.contrib.admin.views.main import ChangeList -from eav.admin import BaseEntityAdmin, BaseSchemaAdmin + from sigi.apps.servidores.models import Servidor from sigi.apps.ocorrencias.models import Ocorrencia, Comentario, Anexo, Categoria, TipoContato - + class ComentarioViewInline(admin.TabularInline): model = Comentario extra = 0 - max_num=0 + max_num = 0 can_delete = False verbose_name, verbose_name_plural = u"Comentário anterior", u"Comentários anteriores" fields = ('usuario', 'data_criacao', 'novo_status', 'encaminhar_setor', 'descricao', ) @@ -23,7 +21,8 @@ class ComentarioInline(admin.StackedInline): extra = 1 verbose_name, verbose_name_plural = u"Comentário novo", u"Comentários novos" fieldsets = ((None, {'fields': (('novo_status', 'encaminhar_setor',), 'descricao', )}),) - def queryset(self, request): + + def queryset(self, queryset): return self.model.objects.get_query_set() @@ -35,12 +34,14 @@ class AnexosInline(admin.TabularInline): 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) + list_max_show_all, list_editable, model_admin) + def get_query_set(self, request): tmp_params = self.params.copy() grupo = None @@ -51,9 +52,9 @@ class OcorrenciaChangeList(ChangeList): self.params = tmp_params.copy() if grupo: servidor = Servidor.objects.get(user=self.request.user) - if grupo == 'S': # Apenas do meu setor + if grupo == 'S': # Apenas do meu setor 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) return qs @@ -61,17 +62,17 @@ class OcorrenciaChangeList(ChangeList): class OcorrenciaAdmin(admin.ModelAdmin): list_display = ('data_criacao', 'casa_legislativa', 'assunto', 'prioridade', 'status', 'data_modificacao', 'setor_responsavel',) list_filter = ('categoria__nome', 'assunto', 'status', 'prioridade', 'setor_responsavel__nome', ) - search_fields = ('casa_legislativa__search_text', 'assunto', 'servidor_registro__nome', ) + search_fields = ('casa_legislativa__search_text', 'assunto', 'servidor_registro__nome_completo', ) date_hierarchy = 'data_criacao' fields = ('casa_legislativa', 'categoria', 'tipo_contato', 'assunto', 'status', 'prioridade', 'descricao', 'servidor_registro', 'setor_responsavel', 'resolucao', ) readonly_fields = ('servidor_registro', 'setor_responsavel', ) inlines = (ComentarioViewInline, ComentarioInline, AnexosInline, ) raw_id_fields = ('casa_legislativa', ) - + 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: @@ -79,22 +80,22 @@ class OcorrenciaAdmin(admin.ModelAdmin): if obj.status in [3, 4, 5]: #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', 'descricao', 'resolucao', ) else: self.fields = ('casa_legislativa', 'categoria', 'tipo_contato', 'assunto', 'status', 'prioridade', 'descricao', 'servidor_registro', 'setor_responsavel', 'resolucao', ) - + return super(OcorrenciaAdmin, self).get_fieldsets(request, obj) - + def save_model(self, request, obj, form, change): if not change: obj.servidor_registro = Servidor.objects.get(user=request.user) obj.setor_responsavel = obj.categoria.setor_responsavel obj.save() - + def save_formset(self, request, form, formset, change): servidor = Servidor.objects.get(user=request.user) instances = formset.save(commit=False) @@ -113,4 +114,4 @@ class OcorrenciaAdmin(admin.ModelAdmin): admin.site.register(Ocorrencia, OcorrenciaAdmin) admin.site.register(Categoria) -admin.site.register(TipoContato) \ No newline at end of file +admin.site.register(TipoContato) diff --git a/sigi/apps/ocorrencias/models.py b/sigi/apps/ocorrencias/models.py index 49b3f04..4d364e4 100644 --- a/sigi/apps/ocorrencias/models.py +++ b/sigi/apps/ocorrencias/models.py @@ -1,9 +1,5 @@ # -*- coding: utf-8 -*- from django.db import models -from datetime import datetime -from django.db import models -from sigi.apps.utils import SearchField -#from eav.models import BaseChoice, BaseEntity, BaseSchema, BaseAttribute class Categoria(models.Model):