|
@ -2,16 +2,19 @@ from django.contrib import messages |
|
|
from django.contrib.auth.mixins import PermissionRequiredMixin |
|
|
from django.contrib.auth.mixins import PermissionRequiredMixin |
|
|
from django.contrib.auth.models import Permission |
|
|
from django.contrib.auth.models import Permission |
|
|
from django.contrib.contenttypes.models import ContentType |
|
|
from django.contrib.contenttypes.models import ContentType |
|
|
from django.core.urlresolvers import reverse_lazy |
|
|
from django.core.exceptions import ObjectDoesNotExist |
|
|
|
|
|
from django.core.urlresolvers import reverse, reverse_lazy |
|
|
from django.shortcuts import redirect |
|
|
from django.shortcuts import redirect |
|
|
from django.utils.datastructures import MultiValueDictKeyError |
|
|
from django.utils.datastructures import MultiValueDictKeyError |
|
|
from django.utils.translation import ugettext_lazy as _ |
|
|
from django.utils.translation import ugettext_lazy as _ |
|
|
from django.views.generic import FormView |
|
|
from django.views.generic import FormView |
|
|
|
|
|
|
|
|
|
|
|
from sapl.comissoes.models import Participacao |
|
|
from sapl.crud.base import (Crud, CrudBaseMixin, CrudCreateView, |
|
|
from sapl.crud.base import (Crud, CrudBaseMixin, CrudCreateView, |
|
|
CrudDeleteView, CrudDetailView, CrudListView, |
|
|
CrudDeleteView, CrudDetailView, CrudListView, |
|
|
CrudUpdateView) |
|
|
CrudUpdateView) |
|
|
from sapl.crud.masterdetail import MasterDetailCrud |
|
|
from sapl.crud.masterdetail import MasterDetailCrud |
|
|
|
|
|
from sapl.materia.models import Proposicao, Relatoria |
|
|
from sapl.utils import permissao_tb_aux, permissoes_parlamentares |
|
|
from sapl.utils import permissao_tb_aux, permissoes_parlamentares |
|
|
|
|
|
|
|
|
from .forms import (ComposicaoColigacaoForm, FiliacaoForm, LegislaturaForm, |
|
|
from .forms import (ComposicaoColigacaoForm, FiliacaoForm, LegislaturaForm, |
|
@ -22,6 +25,93 @@ from .models import (CargoMesa, Coligacao, ComposicaoColigacao, ComposicaoMesa, |
|
|
SituacaoMilitar, TipoAfastamento, TipoDependente) |
|
|
SituacaoMilitar, TipoAfastamento, TipoDependente) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class RelatoriaParlamentarCrud(MasterDetailCrud): |
|
|
|
|
|
model = Relatoria |
|
|
|
|
|
parent_field = 'parlamentar' |
|
|
|
|
|
help_path = '' |
|
|
|
|
|
|
|
|
|
|
|
class ListView(MasterDetailCrud.ListView): |
|
|
|
|
|
permission_required = permissoes_parlamentares() |
|
|
|
|
|
|
|
|
|
|
|
class CreateView(PermissionRequiredMixin, MasterDetailCrud.CreateView): |
|
|
|
|
|
permission_required = permissoes_parlamentares() |
|
|
|
|
|
|
|
|
|
|
|
class UpdateView(PermissionRequiredMixin, MasterDetailCrud.UpdateView): |
|
|
|
|
|
permission_required = permissoes_parlamentares() |
|
|
|
|
|
|
|
|
|
|
|
class DeleteView(PermissionRequiredMixin, MasterDetailCrud.DeleteView): |
|
|
|
|
|
permission_required = permissoes_parlamentares() |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class ProposicaoParlamentarCrud(MasterDetailCrud): |
|
|
|
|
|
model = Proposicao |
|
|
|
|
|
parent_field = 'autor__parlamentar' |
|
|
|
|
|
help_path = '' |
|
|
|
|
|
|
|
|
|
|
|
class BaseMixin(CrudBaseMixin): |
|
|
|
|
|
list_field_names = ['tipo', 'descricao'] |
|
|
|
|
|
|
|
|
|
|
|
class ListView(MasterDetailCrud.ListView): |
|
|
|
|
|
permission_required = permissoes_parlamentares() |
|
|
|
|
|
|
|
|
|
|
|
def get_queryset(self): |
|
|
|
|
|
try: |
|
|
|
|
|
proposicoes = Proposicao.objects.filter( |
|
|
|
|
|
autor__parlamentar_id=self.kwargs['pk'], |
|
|
|
|
|
data_envio__isnull=False) |
|
|
|
|
|
except ObjectDoesNotExist: |
|
|
|
|
|
return [] |
|
|
|
|
|
else: |
|
|
|
|
|
return proposicoes |
|
|
|
|
|
|
|
|
|
|
|
class CreateView(PermissionRequiredMixin, MasterDetailCrud.CreateView): |
|
|
|
|
|
permission_required = permissoes_parlamentares() |
|
|
|
|
|
|
|
|
|
|
|
class UpdateView(PermissionRequiredMixin, MasterDetailCrud.UpdateView): |
|
|
|
|
|
permission_required = permissoes_parlamentares() |
|
|
|
|
|
|
|
|
|
|
|
class DeleteView(PermissionRequiredMixin, MasterDetailCrud.DeleteView): |
|
|
|
|
|
permission_required = permissoes_parlamentares() |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class ParticipacaoParlamentarCrud(MasterDetailCrud): |
|
|
|
|
|
model = Participacao |
|
|
|
|
|
parent_field = 'parlamentar' |
|
|
|
|
|
help_path = '' |
|
|
|
|
|
|
|
|
|
|
|
class ListView(MasterDetailCrud.ListView): |
|
|
|
|
|
ordering = ('-composicao__periodo') |
|
|
|
|
|
|
|
|
|
|
|
def get_rows(self, object_list): |
|
|
|
|
|
comissoes = [] |
|
|
|
|
|
for p in object_list: |
|
|
|
|
|
if p.cargo.nome != 'Relator': |
|
|
|
|
|
comissao = [ |
|
|
|
|
|
(p.composicao.comissao.nome, reverse( |
|
|
|
|
|
'sapl.comissoes:comissao_detail', kwargs={ |
|
|
|
|
|
'pk': p.composicao.comissao.pk})), |
|
|
|
|
|
(p.cargo.nome, None), |
|
|
|
|
|
(p.composicao.periodo.data_inicio.strftime( |
|
|
|
|
|
"%d/%m/%Y") + ' a ' + |
|
|
|
|
|
p.composicao.periodo.data_fim.strftime("%d/%m/%Y"), |
|
|
|
|
|
None) |
|
|
|
|
|
] |
|
|
|
|
|
comissoes.append(comissao) |
|
|
|
|
|
return comissoes |
|
|
|
|
|
|
|
|
|
|
|
def get_headers(self): |
|
|
|
|
|
return ['Comissão', 'Cargo', 'Período'] |
|
|
|
|
|
|
|
|
|
|
|
class CreateView(PermissionRequiredMixin, MasterDetailCrud.CreateView): |
|
|
|
|
|
permission_required = permissoes_parlamentares() |
|
|
|
|
|
|
|
|
|
|
|
class UpdateView(PermissionRequiredMixin, MasterDetailCrud.UpdateView): |
|
|
|
|
|
permission_required = permissoes_parlamentares() |
|
|
|
|
|
|
|
|
|
|
|
class DeleteView(PermissionRequiredMixin, MasterDetailCrud.DeleteView): |
|
|
|
|
|
permission_required = permissoes_parlamentares() |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class CargoMesaCrud(Crud): |
|
|
class CargoMesaCrud(Crud): |
|
|
model = CargoMesa |
|
|
model = CargoMesa |
|
|
help_path = 'cargo_mesa' |
|
|
help_path = 'cargo_mesa' |
|
|