-
Notifications
You must be signed in to change notification settings - Fork 97
Issue#3396 Obter Integrantes da mesa pela API #3415
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: 3.1.x
Are you sure you want to change the base?
Changes from 7 commits
f47f256
af02725
86ddedf
4d08daf
f678f12
7c3820d
f5c089d
fc8b61c
b08f537
03668fe
2729e38
efcb0c0
810744d
04446ac
e1acbff
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -11,6 +11,7 @@ | |
| from django.utils.decorators import classonlymethod | ||
| from django.utils.translation import ugettext_lazy as _ | ||
| from django_filters.rest_framework.backends import DjangoFilterBackend | ||
| from django.http import JsonResponse | ||
| from rest_framework import serializers as rest_serializers | ||
| from rest_framework.authtoken.models import Token | ||
| from rest_framework.decorators import action, api_view, permission_classes | ||
|
|
@@ -33,7 +34,9 @@ | |
| from sapl.protocoloadm.models import DocumentoAdministrativo,\ | ||
| DocumentoAcessorioAdministrativo, TramitacaoAdministrativo, Anexado | ||
| from sapl.sessao.models import SessaoPlenaria, ExpedienteSessao | ||
| from sapl.utils import models_with_gr_for_model, choice_anos_com_sessaoplenaria | ||
| from sapl.utils import models_with_gr_for_model, choice_anos_com_sessaoplenaria, get_base_url | ||
| from sapl.parlamentares.models import (ComposicaoMesa, SessaoLegislativa) | ||
| from sapl.parlamentares.views import (partido_parlamentar_sessao_legislativa) | ||
|
|
||
|
|
||
| @receiver(post_save, sender=settings.AUTH_USER_MODEL) | ||
|
|
@@ -50,6 +53,47 @@ def recria_token(request, pk): | |
|
|
||
| return Response({"message": "Token recriado com sucesso!", "token": token.key}) | ||
|
|
||
| def get_mesa_diretora(request): | ||
| logger = logging.getLogger(__name__) | ||
|
|
||
| kwargs = {} | ||
|
|
||
| legislatura = request.GET.get('legislatura') | ||
| if legislatura: | ||
| kwargs['legislatura_id'] = legislatura | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Coloca um else aqui: se não tiver legislatura informada pega a última ("-data_inicio") |
||
|
|
||
| sessao = request.GET.get('sessao') | ||
| if sessao: | ||
| kwargs['id'] = sessao | ||
|
|
||
| sessao_legislativa = SessaoLegislativa.objects.select_related('legislatura').filter(**kwargs).order_by('-data_inicio').first() | ||
|
|
||
| if sessao_legislativa is None: | ||
| logger.error("Sessão ou legislatura não encontrada!") | ||
| return JsonResponse({}) | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Retorna uma mensagem de erro no json. Algo como: {"error": "Sessão ou legislatura não encontrada!"} |
||
|
|
||
| composicao_mesa = ComposicaoMesa.objects.select_related('parlamentar', 'cargo').all().filter( | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Não precisa colocar o all() e o filter() ao mesmo tempo. É desnecessário. Ou um ou outro. No caso fica o filter(). |
||
| sessao_legislativa=sessao_legislativa).order_by('cargo_id') | ||
|
|
||
| if composicao_mesa is None: | ||
| logger.error("Nenhuma mesa não encontrada!") | ||
| return JsonResponse({}) | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Mesma coisa aqui: retorna uma mensagem de erro. |
||
|
|
||
|
|
||
|
|
||
| mesa_diretora = [{'legislatura_id':sessao_legislativa.legislatura.id,'legislatura':str(sessao_legislativa.legislatura), | ||
| 'sessao_legislativa_id':sessao_legislativa.id,'sessao_legislativa':str(sessao_legislativa), | ||
| 'parlamentar_id':i[0], 'parlamentar_nome':i[1], 'cargo_id':i[2], 'cargo_descricao':i[3]} | ||
| for i in composicao_mesa.values_list('parlamentar_id', 'parlamentar__nome_parlamentar', | ||
| 'cargo_id', 'cargo__descricao')] | ||
|
|
||
| for i, c in enumerate(composicao_mesa): | ||
| mesa_diretora[i]['fotografia'] = get_base_url(request) + c.parlamentar.fotografia.url | ||
|
|
||
| return JsonResponse({ | ||
| 'mesa_diretora':mesa_diretora, | ||
| }) | ||
|
|
||
|
|
||
| class BusinessRulesNotImplementedMixin: | ||
| def create(self, request, *args, **kwargs): | ||
|
|
@@ -703,4 +747,4 @@ def get(self, request): | |
| 'user': request.user.username, | ||
| 'is_authenticated': request.user.is_authenticated, | ||
| } | ||
| return Response(content) | ||
| return Response(content) | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Pq vc tá modificando essa linha? Não precisa. Reverter essa mudança. |
||
Uh oh!
There was an error while loading. Please reload this page.