diff --git a/sapl/materia/views.py b/sapl/materia/views.py
index ab18ff312..5c15fae38 100644
--- a/sapl/materia/views.py
+++ b/sapl/materia/views.py
@@ -1195,44 +1195,50 @@ def autores_ativos(materia, tipo=None):
return (autor_qs | autores_by_ct['others']).order_by('nome')
else:
- tipo_autor = tipo
if not tipo in autores_by_ct:
- tipo_autor = 'others'
+ return autores_by_ct['others'].filter(
+ tipo_id=tipo).order_by('nome')
- return autores_by_ct[tipo_autor].filter(tipo_id=tipo).order_by('nome')
+ return autores_by_ct[tipo].order_by('nome')
def atualizar_autores(request):
- if ('tipo_autor' in request.GET and 'materia_id' in request.GET and
- request.GET['tipo_autor'] and request.GET['materia_id']):
- tipo_autor = request.GET['tipo_autor']
+ if 'materia_id' in request.GET and request.GET['materia_id']:
materia_id = int(request.GET['materia_id'])
try:
materia = MateriaLegislativa.objects.get(id=materia_id)
except ObjectDoesNotExist:
- autores = []
+ pass
else:
- autores = autores_ativos(materia, tipo=tipo_autor)
- autores_list = [(a.id, a.__str__()) for a in autores]
+ manter_autor = False
+ if 'tipo_autor' in request.GET and request.GET['tipo_autor']:
+ tipo_autor = request.GET['tipo_autor']
+ autores = autores_ativos(materia, tipo=tipo_autor)
+
+ # Se já houver algum autor selecionado (ex: view de update)
+ # no campo correspondente e caso o TipoAutor selecionado
+ # seja o mesmo do autor que está aualmente marcado
+ # deve ser enviado um sinal (manter autor) para que o
+ # javascript mantenha este selecionado
+ if 'autor_id' in request.GET and request.GET['autor_id']:
+ try:
+ autor = Autor.objects.get(id=request.GET['autor_id'])
+ except ObjectDoesNotExist:
+ pass
+ else:
+ if autor.tipo.id == int(tipo_autor):
+ manter_autor = True
- # Se já houver algum autor selecionado (ex: view de update)
- # no campo correspondente e caso o TipoAutor selecionado
- # seja o mesmo do autor que está aualmente marcado
- # deve ser enviado um sinal (manter autor) para que o javascript
- # mantenha este selecionado
- manter_autor = False
- if 'autor_id' in request.GET and request.GET['autor_id']:
- try:
- autor = Autor.objects.get(id=request.GET['autor_id'])
- except ObjectDoesNotExist:
- pass
else:
- if autor.tipo.id == int(tipo_autor):
- manter_autor = True
+ autores = autores_ativos(materia)
+
+ autores_list = [(a.id, a.__str__()) for a in autores]
+
+ return JsonResponse({'lista_autores': autores_list,
+ 'manter_autor': manter_autor})
- return JsonResponse({'lista_autores': autores_list,
- 'manter_autor': manter_autor})
+ return JsonResponse({})
class AutoriaCrud(MasterDetailCrud):
diff --git a/sapl/templates/materia/autoria_form.html b/sapl/templates/materia/autoria_form.html
index 7a35884d8..3c1f3f587 100644
--- a/sapl/templates/materia/autoria_form.html
+++ b/sapl/templates/materia/autoria_form.html
@@ -25,11 +25,12 @@
lista_autores = data['lista_autores'];
// Atualiza a listagem de autores
- for (i = 0; i < lista_autores.length; i++) {
- $('#id_autor').append(
- '');
- }
+
+ $.each(lista_autores, function(index, value) {
+ $('#id_autor').append(
+ '');
+ });
if (data['manter_autor'] == true){
$('#id_autor').val(autor_id);