diff --git a/sapl/norma/views.py b/sapl/norma/views.py index 9c98e783e..b364e95bd 100644 --- a/sapl/norma/views.py +++ b/sapl/norma/views.py @@ -1,4 +1,5 @@ +import re import weasyprint from django.contrib.auth.mixins import PermissionRequiredMixin from django.core.exceptions import ObjectDoesNotExist @@ -201,14 +202,12 @@ def recuperar_norma(request): def recuperar_numero_norma(request): tipo = TipoNormaJuridica.objects.get(pk=request.GET['tipo']) ano = request.GET.get('ano', '') - param = {'tipo': tipo} param['ano'] = ano if ano else timezone.now().year - norma = NormaJuridica.objects.filter(**param).extra( - {'numero_id': "CAST(numero as INTEGER)"}).order_by( - 'tipo', 'ano','numero_id').values_list('numero', 'ano').last() + norma = NormaJuridica.objects.filter(**param).order_by( + 'tipo', 'ano').values_list('numero', 'ano').last() if norma: - response = JsonResponse({'numero': int(norma[0]) + 1, + response = JsonResponse({'numero': int(re.sub("[^0-9].*", '', norma[0])) + 1, 'ano': norma[1]}) else: response = JsonResponse(