-
Notifications
You must be signed in to change notification settings - Fork 94
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
Open
AlGouvea
wants to merge
15
commits into
3.1.x
Choose a base branch
from
issue#3396
base: 3.1.x
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
f47f256
Adicionado rota para pagina da info de mesa diretora na API
AlGouvea af02725
Arrumada a url e definida função básica da issue
AlGouvea 86ddedf
Apresentando maior parte das informacoes da mesa diretora
AlGouvea 4d08daf
Refatoração do código fonte
AlGouvea f678f12
Implementação de condicional para legislatura não informada
AlGouvea 7c3820d
Condicionais para caso de informações não disponíveis
AlGouvea f5c089d
Refatoração das condicionais de informações
AlGouvea fc8b61c
Criado o arquivo de testes
AlGouvea b08f537
Iniciada a função de teste
AlGouvea 03668fe
Alterada condicional de legislatura e adicionadas mensagens de erro
AlGouvea 2729e38
Removida redundancia de query
AlGouvea efcb0c0
Desempacotamento da tupla para melhorar legibilidade
AlGouvea 810744d
Adicionada condicional para inexistencia do arquivos de fotografia do…
AlGouvea 04446ac
Alterada a condicional para inexistencia do arquivos de fotografia do…
AlGouvea e1acbff
Inicio da configuração do arquivo de testes
AlGouvea File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,30 @@ | ||
| from model_bakery import baker | ||
| import pytest | ||
| import json | ||
| from sapl.parlamentares.models import Legislatura, ComposicaoMesa, Parlamentar,\ | ||
| SessaoLegislativa, CargoMesa | ||
| from django.urls import reverse | ||
| from sapl.api import views | ||
|
|
||
| @pytest.mark.django_db(transaction=False) | ||
| def test_get_mesa_diretora(admin_client): | ||
| #criar legislatura, sessao e parlamentares | ||
| parlamentar = baker.make(Parlamentar, nome_parlamentar='Joseph Joestar', id=8, fotografia=None) | ||
|
|
||
| legislatura = baker.make(Legislatura, id=34) | ||
|
|
||
| sessao = baker.make(SessaoLegislativa, legislatura=legislatura, id=44) | ||
|
|
||
| cargo = baker.make(CargoMesa, descricao="presidente") | ||
|
|
||
| #passar informações para a composicao_mesa | ||
| mesa = baker.make(ComposicaoMesa, parlamentar=parlamentar, | ||
| sessao_legislativa=sessao, cargo=cargo) | ||
|
|
||
| #Verifica se a mesa foi criada | ||
| mesa_diretora = ComposicaoMesa.objects.get(sessao_legislativa=sessao, parlamentar=parlamentar) | ||
|
|
||
| #Testa o POST | ||
| jresponse = admin_client.post(reverse('sapl.api:get_mesa_diretora')) | ||
| assert jresponse.status_code == 200 | ||
|
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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,56 @@ 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 not legislatura: | ||
| legislatura = Legislatura.objects.order_by('-data_inicio').first() | ||
|
|
||
| kwargs['legislatura_id'] = legislatura | ||
|
|
||
| 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({"error": "Sessão ou legislatura não encontrada!"}) | ||
|
|
||
| composicao_mesa = ComposicaoMesa.objects.select_related('parlamentar', 'cargo').filter( | ||
| sessao_legislativa=sessao_legislativa).order_by('cargo_id') | ||
|
|
||
| if composicao_mesa is None: | ||
| logger.error("Nenhuma mesa não encontrada!") | ||
| return JsonResponse({"error": "Sessão ou legislatura não encontrada!"}) | ||
|
|
||
|
|
||
|
|
||
| mesa_diretora = [{'legislatura_id':legislatura.id,'legislatura':str(legislatura), | ||
| 'sessao_legislativa_id':sessao_legislativa.id,'sessao_legislativa':str(sessao_legislativa), | ||
| 'parlamentar_id': parlamentar_id, 'parlamentar_nome': parlamentar_nome, 'cargo_id': cargo_id, | ||
| 'cargo_descricao':cargo_descricao} for (parlamentar_id, parlamentar_nome, | ||
| cargo_id, cargo_descricao) in composicao_mesa.values_list('parlamentar_id', | ||
| 'parlamentar__nome_parlamentar', 'cargo_id', 'cargo__descricao')] | ||
|
|
||
|
|
||
| for i, c in enumerate(composicao_mesa): | ||
| try: | ||
| mesa_diretora[i]['fotografia'] = get_base_url(request) + c.parlamentar.fotografia.url | ||
| except: | ||
| logger.error("Parlamentar "+mesa_diretora[i]['parlamentar_nome']+" não possui foto!") | ||
| mesa_diretora[i]['fotografia'] = "Não encontrada" | ||
|
|
||
|
|
||
| return JsonResponse({ | ||
| 'mesa_diretora':mesa_diretora, | ||
| }) | ||
|
|
||
|
|
||
| class BusinessRulesNotImplementedMixin: | ||
| def create(self, request, *args, **kwargs): | ||
|
|
@@ -703,4 +756,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. |
||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.