From 1bbf473e6e9f590a2c3d3bd0995954094f51453b Mon Sep 17 00:00:00 2001 From: Leandro Roberto Date: Wed, 20 Oct 2021 16:39:17 -0300 Subject: [PATCH] HOT-FIX: Corrige constr de contexto na anex de mat MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Remove a analise de vínculos cíclicos na construção inicial do form do filterset. - O item anterior deve resolver o timeout causado na abertura da anexação em lote, no entanto os timeouts do nginx e gunicorn foram aumentados. --- docker/config/nginx/nginx.conf | 6 +++- docker/docker-compose.yml | 9 ++--- docker/gunicorn_start.sh | 2 +- sapl/materia/forms.py | 3 ++ sapl/materia/views.py | 63 ++++++++++++++++++---------------- 5 files changed, 47 insertions(+), 36 deletions(-) diff --git a/docker/config/nginx/nginx.conf b/docker/config/nginx/nginx.conf index 3037f3080..29b9e805c 100644 --- a/docker/config/nginx/nginx.conf +++ b/docker/config/nginx/nginx.conf @@ -23,7 +23,11 @@ http { sendfile off; #tcp_nopush on; - keepalive_timeout 65; + keepalive_timeout 300; + + proxy_connect_timeout 75s; + proxy_read_timeout 300s; + gzip on; gzip_disable "MSIE [1-6]\\.(?!.*SV1)"; diff --git a/docker/docker-compose.yml b/docker/docker-compose.yml index ac8c0f719..2d935ce67 100644 --- a/docker/docker-compose.yml +++ b/docker/docker-compose.yml @@ -32,15 +32,16 @@ services: networks: - sapl-net sapl: - image: interlegis/sapl:3.1.162-RC11 -# build: -# context: ../ -# dockerfile: ./docker/Dockerfile + #image: interlegis/sapl:3.1.162-RC11 + build: + context: ../ + dockerfile: ./docker/Dockerfile container_name: sapl labels: NAME: "sapl" restart: always environment: + LOGGING_CONSOLE_VERBOSE: 'True' ADMIN_PASSWORD: interlegis ADMIN_EMAIL: email@dominio.net DEBUG: 'False' diff --git a/docker/gunicorn_start.sh b/docker/gunicorn_start.sh index 3f46a5f8f..9ef4b7982 100755 --- a/docker/gunicorn_start.sh +++ b/docker/gunicorn_start.sh @@ -25,7 +25,7 @@ USER=`whoami` # the user to run as (*) GROUP=`whoami` # the group to run as (*) NUM_WORKERS=3 # how many worker processes should Gunicorn spawn (*) # NUM_WORKERS = 2 * CPUS + 1 -TIMEOUT=60 +TIMEOUT=300 MAX_REQUESTS=100 # number of requests before restarting worker DJANGO_SETTINGS_MODULE=sapl.settings # which settings file should Django use (*) DJANGO_WSGI_MODULE=sapl.wsgi # WSGI module name (*) diff --git a/sapl/materia/forms.py b/sapl/materia/forms.py index 03b8f5d82..23280c436 100644 --- a/sapl/materia/forms.py +++ b/sapl/materia/forms.py @@ -1416,6 +1416,9 @@ class AnexadaEmLoteFilterSet(django_filters.FilterSet): self.filters['tipo'].label = 'Tipo de Matéria' self.filters['data_apresentacao'].label = 'Data (Inicial - Final)' + self.form.fields['tipo'].required = True + self.form.fields['data_apresentacao'].required = True + row1 = to_row([('tipo', 12)]) row2 = to_row([('data_apresentacao', 12)]) diff --git a/sapl/materia/views.py b/sapl/materia/views.py index a964e6070..7dc1f90be 100644 --- a/sapl/materia/views.py +++ b/sapl/materia/views.py @@ -104,10 +104,10 @@ def proposicao_texto(request, pk): if proposicao.texto_original: if (not proposicao.data_recebimento and - not proposicao.autor.operadores.filter( + not proposicao.autor.operadores.filter( id=request.user.id ).exists() - ): + ): logger.error("user=" + username + ". Usuário ({}) não tem permissão para acessar o texto original." .format(request.user.id)) messages.error(request, _( @@ -2385,39 +2385,42 @@ class MateriaAnexadaEmLoteView(PermissionRequiredMixin, FilterView): return context qr = self.request.GET.copy() - context['object_list'] = context['object_list'].order_by( - 'numero', '-ano') - principal = MateriaLegislativa.objects.get(pk=self.kwargs['pk']) - not_list = [self.kwargs['pk']] + \ - [m for m in principal.materia_principal_set.all( - ).values_list('materia_anexada_id', flat=True)] - context['object_list'] = context['object_list'].exclude( - pk__in=not_list) - - context['temp_object_list'] = context['object_list'] - context['object_list'] = [] - for obj in context['temp_object_list']: - materia_anexada = obj - ciclico = False - anexadas_anexada = Anexada.objects.filter( - materia_principal=materia_anexada - ) + if not len(qr): + context['object_list'] = [] + else: + context['object_list'] = context['object_list'].order_by( + 'numero', '-ano') + principal = MateriaLegislativa.objects.get(pk=self.kwargs['pk']) + not_list = [self.kwargs['pk']] + \ + [m for m in principal.materia_principal_set.all( + ).values_list('materia_anexada_id', flat=True)] + context['object_list'] = context['object_list'].exclude( + pk__in=not_list) + + context['temp_object_list'] = context['object_list'] + context['object_list'] = [] + for obj in context['temp_object_list']: + materia_anexada = obj + ciclico = False + anexadas_anexada = Anexada.objects.filter( + materia_principal=materia_anexada + ) - while anexadas_anexada and not ciclico: - anexadas = [] + while anexadas_anexada and not ciclico: + anexadas = [] - for anexa in anexadas_anexada: + for anexa in anexadas_anexada: - if principal == anexa.materia_anexada: - ciclico = True - else: - for a in Anexada.objects.filter(materia_principal=anexa.materia_anexada): - anexadas.append(a) + if principal == anexa.materia_anexada: + ciclico = True + else: + for a in Anexada.objects.filter(materia_principal=anexa.materia_anexada): + anexadas.append(a) - anexadas_anexada = anexadas + anexadas_anexada = anexadas - if not ciclico: - context['object_list'].append(obj) + if not ciclico: + context['object_list'].append(obj) context['numero_res'] = len(context['object_list'])