From ad110ab24c65d55ca90d260a51fb29b16e204b59 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=C3=A3o=20Pedro=20Sconetto?= Date: Mon, 9 Oct 2017 13:58:34 -0300 Subject: [PATCH] =?UTF-8?q?Fix=20#1502=20ordem=20alfab=C3=A9tica=20no=20pa?= =?UTF-8?q?inel=20(#1509)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * Corrige #1502 para listar em ordem alfabética no painel * Reordena a lista de parlamentares #1502 * Move a função para utils onde pode ser utilizada em diversas parte do sistema --- sapl/painel/views.py | 5 ++++- sapl/utils.py | 12 ++++++++++++ 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/sapl/painel/views.py b/sapl/painel/views.py index 3f31e430d..4be056640 100644 --- a/sapl/painel/views.py +++ b/sapl/painel/views.py @@ -1,4 +1,3 @@ - from django.contrib import messages from django.contrib.auth.decorators import user_passes_test from django.core.exceptions import ObjectDoesNotExist @@ -8,6 +7,8 @@ from django.http import HttpResponse, JsonResponse from django.http.response import Http404, HttpResponseRedirect from django.shortcuts import render from django.utils.translation import ugettext_lazy as _ +from operator import itemgetter +from sapl.utils import sort_lista_chave from sapl.crud.base import Crud from sapl.painel.apps import AppConfig @@ -292,6 +293,8 @@ def get_presentes(pk, response, materia): elif materia.tipo_votacao == 3: tipo_votacao = 'Secreta' + presentes_list = sort_lista_chave(presentes_list, 'nome') + response.update({ 'presentes': presentes_list, 'num_presentes': num_presentes, diff --git a/sapl/utils.py b/sapl/utils.py index 7afa00d1a..37e5711d3 100644 --- a/sapl/utils.py +++ b/sapl/utils.py @@ -4,6 +4,7 @@ import os import re from functools import wraps from unicodedata import normalize as unicodedata_normalize +from operator import itemgetter import django_filters import magic @@ -651,3 +652,14 @@ def show_results_filter_set(qr): return False return True + + +def sort_lista_chave(lista, chave): + """ + :param lista: Uma list a ser ordenada . + :param chave: Algum atributo (chave) que está presente na lista e qual deve ser usado para a ordenação da nova + lista. + :return: A lista ordenada pela chave passada. + """ + lista_ordenada = sorted(lista, key=itemgetter(chave)) + return lista_ordenada