diff --git a/sigi/apps/metas/admin.py b/sigi/apps/metas/admin.py index bea6408..b422ea7 100644 --- a/sigi/apps/metas/admin.py +++ b/sigi/apps/metas/admin.py @@ -8,7 +8,39 @@ class MetaAdmin(admin.ModelAdmin): list_filter = ('projeto',) class PlanoDiretorAdmin(admin.ModelAdmin): - list_display = ('projeto', 'casa_legislativa', 'status', 'data_entrega', 'data_implantacao',) + list_display = ('projeto', 'casa_legislativa', 'get_uf', 'status', 'data_entrega', 'data_implantacao',) fields = ('projeto', 'casa_legislativa', 'status', 'data_entrega', 'data_implantacao',) raw_id_fields = ('casa_legislativa',) - list_filter = ('projeto', 'status',) \ No newline at end of file + list_filter = ('projeto', 'status', 'casa_legislativa', ) + + def get_uf(self, obj): + return obj.casa_legislativa.municipio.uf.nome + get_uf.short_description = u"UF" + get_uf.admin_order_field = 'casa_legislativa__municipio__uf__nome' + + def lookup_allowed(self, lookup, value): + return super(PlanoDiretorAdmin, self).lookup_allowed(lookup, value) or \ + lookup in ['casa_legislativa__municipio__uf__codigo_ibge__exact'] + + def changelist_view(self, request, extra_context=None): + import re + request.GET._mutable=True + if 'data_entrega__gte' in request.GET: + value = request.GET.get('data_entrega__gte','') + if value == '': + del request.GET['data_entrega__gte'] + elif re.match('^\d*$', value): # Year only + request.GET['data_entrega__gte'] = "%s-01-01" % value #Complete with january 1st + elif re.match('^\d*\D\d*$', value): # Year and month + request.GET['data_entrega__gte'] = '%s-01' % value #Complete with 1st day of month + if 'data_entrega__lte' in request.GET: + value = request.GET.get('data_entrega__lte','') + if value == '': + del request.GET['data_entrega__lte'] + elif re.match('^\d*$', value): # Year only + request.GET['data_entrega__lte'] = "%s-01-01" % value #Complete with january 1st + elif re.match('^\d*\D\d*$', value): # Year and month + request.GET['data_entrega__lte'] = '%s-01' % value #Complete with 1st day of month + request.GET._mutable=False + + return super(PlanoDiretorAdmin, self).changelist_view(request, extra_context) \ No newline at end of file diff --git a/sigi/apps/metas/models.py b/sigi/apps/metas/models.py index 86bfcad..66aa116 100644 --- a/sigi/apps/metas/models.py +++ b/sigi/apps/metas/models.py @@ -114,6 +114,7 @@ class PlanoDiretor(models.Model): ) projeto = models.ForeignKey(Projeto, verbose_name=u'Projeto') casa_legislativa = models.ForeignKey(CasaLegislativa, verbose_name=u'Casa legislativa') + casa_legislativa.casa_uf_filter = True status = models.CharField(u'Status', max_length=1, choices=STATUS_CHOICE, default='E') data_entrega = models.DateField(u'Data de entrega', blank=True, null=True) data_implantacao = models.DateField(u'Data de implantação', blank=True, null=True) diff --git a/sigi/templates/admin/metas/planodiretor/change_list.html b/sigi/templates/admin/metas/planodiretor/change_list.html new file mode 100644 index 0000000..0ffd93f --- /dev/null +++ b/sigi/templates/admin/metas/planodiretor/change_list.html @@ -0,0 +1,19 @@ +{% extends "admin/change_list.html" %} +{% load i18n reporting_tags admin_list %} + +{% block search %} +
+ +
+{% endblock %}