Browse Source

Começa a implementacao da pesquisa por status

pull/282/head
Eduardo Calil 9 years ago
parent
commit
8a97f18dcc
  1. 18
      materia/forms.py
  2. 22
      materia/views.py

18
materia/forms.py

@ -2,6 +2,7 @@ from crispy_forms.helper import FormHelper
from crispy_forms.layout import HTML, Button, Column, Fieldset, Layout, Submit from crispy_forms.layout import HTML, Button, Column, Fieldset, Layout, Submit
from django import forms from django import forms
from django.core.exceptions import ValidationError from django.core.exceptions import ValidationError
from django.db.models import Max
from django_filters import FilterSet from django_filters import FilterSet
from django.forms import ModelForm from django.forms import ModelForm
from django.utils.translation import ugettext_lazy as _ from django.utils.translation import ugettext_lazy as _
@ -19,7 +20,7 @@ from parlamentares.models import Parlamentar, Partido
from .models import (AcompanhamentoMateria, Anexada, Autor, Autoria, from .models import (AcompanhamentoMateria, Anexada, Autor, Autoria,
DespachoInicial, DocumentoAcessorio, MateriaLegislativa, DespachoInicial, DocumentoAcessorio, MateriaLegislativa,
Numeracao, Origem, Proposicao, Relatoria, Numeracao, Origem, Proposicao, Relatoria,
StatusTramitacao, TipoAutor, TipoDocumento, StatusTramitacao, TipoAutor,
TipoMateriaLegislativa, Tramitacao, UnidadeTramitacao) TipoMateriaLegislativa, Tramitacao, UnidadeTramitacao)
ORDENACAO_MATERIAIS = [(1, 'Crescente'), ORDENACAO_MATERIAIS = [(1, 'Crescente'),
@ -799,11 +800,10 @@ class MateriaLegislativaPesquisaFields(FilterSet):
'autoria__partido', 'autoria__partido',
'local_origem_externa'] 'local_origem_externa']
def my_custom_filter(queryset, value): # def filter_tramitacao__status(status):
materia = MateriaLegislativa.objects.raw( # ultimas_tramitacoes = Tramitacao.objects.values(
'SELECT DISTINCT materia_id, \ # 'materia_id').annotate(data_encaminhamento=Max(
max(data_encaminhamento) as data_encaminhamento \ # 'data_encaminhamento'),
FROM materia_tramitacao \ # id=Max('id'))
GROUP BY materia_id \ # ultimas_tramitacoes = ultimas_tramitacoes.filter(status=status)
ORDER BY materia_id') # return ultimas_tramitacoes.materia
return queryset.all()

22
materia/views.py

@ -8,6 +8,7 @@ from django.contrib import messages
from django.core.exceptions import ObjectDoesNotExist from django.core.exceptions import ObjectDoesNotExist
from django.core.mail import send_mail from django.core.mail import send_mail
from django.core.urlresolvers import reverse, reverse_lazy from django.core.urlresolvers import reverse, reverse_lazy
from django.db.models import Max
from django.http.response import HttpResponseRedirect from django.http.response import HttpResponseRedirect
from django.shortcuts import redirect from django.shortcuts import redirect
from django.template import Context, loader from django.template import Context, loader
@ -1192,6 +1193,16 @@ class ProposicaoListView(ListView):
return context return context
def filter_tramitacao__status(status):
ultimas_tramitacoes = Tramitacao.objects.values(
'materia_id').annotate(data_encaminhamento=Max(
'data_encaminhamento'),
id=Max('id'))
import ipdb; ipdb.set_trace()
ultimas_tramitacoes = ultimas_tramitacoes.filter(status=status)
return ultimas_tramitacoes
class MateriaLegislativaPesquisaView(FilterView): class MateriaLegislativaPesquisaView(FilterView):
model = MateriaLegislativa model = MateriaLegislativa
filterset_class = MateriaLegislativaPesquisaFields filterset_class = MateriaLegislativaPesquisaFields
@ -1209,10 +1220,17 @@ class MateriaLegislativaPesquisaView(FilterView):
return context return context
def get(self, request, *args, **kwargs): def get(self, request, *args, **kwargs):
# import ipdb; ipdb.set_trace()
filterset_class = self.get_filterset_class() filterset_class = self.get_filterset_class()
self.filterset = self.get_filterset(filterset_class) self.filterset = self.get_filterset(filterset_class)
self.object_list = self.filterset.qs status_tramitacao = self.filterset.data.get('tramitacao__status')
if status_tramitacao and status_tramitacao != '':
status = filter_tramitacao__status(status_tramitacao)
mat_filt_ids = [ids.get('materia_id') for ids in status]
# import ipdb; ipdb.set_trace()
self.object_list = self.filterset.qs.filter(
id__in=mat_filt_ids)
else:
self.object_list = self.filterset.qs
context = self.get_context_data(filter=self.filterset, context = self.get_context_data(filter=self.filterset,
object_list=self.object_list) object_list=self.object_list)
return self.render_to_response(context) return self.render_to_response(context)

Loading…
Cancel
Save