Repository: interlegis/sapl

Issue:
Erro ao "Adicionar Bancadas Parlamentares"
Em tabelas auxiliares, no modulo de bancadas parlamentares, adicionar bancada parlamentar. Ao salvar mostra o seguinte erro:


Exception Type: | DoesNotExist
-- | --
TipoAutor matching query does not exist.

_____________

Environment:


Request Method: POST
Request URL: http://sapl.camarabento.rs.gov.br/sistema/bancada/create

Django Version: 1.9.13
Python Version: 3.5.2
Installed Applications:
('django_admin_bootstrapped',
 'django.contrib.admin',
 'django.contrib.auth',
 'django.contrib.contenttypes',
 'django.contrib.sessions',
 'django.contrib.messages',
 'django.contrib.staticfiles',
 'django_extensions',
 'djangobower',
 'bootstrap3',
 'crispy_forms',
 'easy_thumbnails',
 'image_cropping',
 'floppyforms',
 'haystack',
 'sass_processor',
 'rest_framework',
 'reversion',
 'whoosh',
 'speedinfo',
 'sapl.audiencia',
 'sapl.base',
 'sapl.crud',
 'sapl.parlamentares',
 'sapl.comissoes',
 'sapl.materia',
 'sapl.norma',
 'sapl.sessao',
 'sapl.lexml',
 'sapl.painel',
 'sapl.protocoloadm',
 'sapl.redireciona_urls',
 'sapl.compilacao',
 'sapl.api',
 'sapl.rules',
 'debug_toolbar',
 'rest_framework_docs')
Installed Middleware:
('debug_toolbar.middleware.DebugToolbarMiddleware',
 'reversion.middleware.RevisionMiddleware',
 'django.contrib.sessions.middleware.SessionMiddleware',
 'django.middleware.locale.LocaleMiddleware',
 'django.middleware.common.CommonMiddleware',
 'django.middleware.csrf.CsrfViewMiddleware',
 'django.contrib.auth.middleware.AuthenticationMiddleware',
 'django.contrib.auth.middleware.SessionAuthenticationMiddleware',
 'django.contrib.messages.middleware.MessageMiddleware',
 'django.middleware.clickjacking.XFrameOptionsMiddleware',
 'django.middleware.security.SecurityMiddleware')



Traceback:

File "/var/interlegis/.virtualenvs/sapl/lib/python3.5/site-packages/django/core/handlers/base.py" in get_response
  149.                     response = self.process_exception_by_middleware(e, request)

File "/var/interlegis/.virtualenvs/sapl/lib/python3.5/site-packages/django/core/handlers/base.py" in get_response
  147.                     response = wrapped_callback(request, *callback_args, **callback_kwargs)

File "/var/interlegis/.virtualenvs/sapl/lib/python3.5/site-packages/django/views/generic/base.py" in view
  68.             return self.dispatch(request, *args, **kwargs)

File "/var/interlegis/sapl/sapl/crud/base.py" in dispatch
  229.             request, *args, **kwargs)

File "/var/interlegis/.virtualenvs/sapl/lib/python3.5/site-packages/django/views/generic/base.py" in dispatch
  88.         return handler(request, *args, **kwargs)

File "/var/interlegis/.virtualenvs/sapl/lib/python3.5/site-packages/django/views/generic/edit.py" in post
  256.         return super(BaseCreateView, self).post(request, *args, **kwargs)

File "/var/interlegis/.virtualenvs/sapl/lib/python3.5/site-packages/django/views/generic/edit.py" in post
  222.             return self.form_valid(form)

File "/var/interlegis/sapl/sapl/crud/base.py" in form_valid
  659.         return super().form_valid(form)

File "/var/interlegis/.virtualenvs/sapl/lib/python3.5/site-packages/braces/views/_forms.py" in form_valid
  128.         response = super(FormValidMessageMixin, self).form_valid(form)

File "/var/interlegis/.virtualenvs/sapl/lib/python3.5/site-packages/django/views/generic/edit.py" in form_valid
  201.         self.object = form.save()

File "/usr/lib/python3.5/contextlib.py" in inner
  30.                 return func(*args, **kwds)

File "/var/interlegis/sapl/sapl/sessao/forms.py" in save
  127.         tipo = TipoAutor.objects.get(descricao='Bancada Parlamentar')

File "/var/interlegis/.virtualenvs/sapl/lib/python3.5/site-packages/django/db/models/manager.py" in manager_method
  122.                 return getattr(self.get_queryset(), name)(*args, **kwargs)

File "/var/interlegis/.virtualenvs/sapl/lib/python3.5/site-packages/django/db/models/query.py" in get
  387.                 self.model._meta.object_name

Exception Type: DoesNotExist at /sistema/bancada/create
Exception Value: TipoAutor matching query does not exist.



Discussion:

Resolving patch:
diff --git a/sapl/parlamentares/forms.py b/sapl/parlamentares/forms.py
--- a/sapl/parlamentares/forms.py
+++ b/sapl/parlamentares/forms.py
@@ -321,7 +321,7 @@ def save(self, commit=True):
         frente = super(FrenteForm, self).save(commit)
         content_type = ContentType.objects.get_for_model(Frente)
         object_id = frente.pk
-        tipo = TipoAutor.objects.get(descricao='Frente Parlamentar')
+        tipo = TipoAutor.objects.get(descricao__icontains='Frente')
         Autor.objects.create(
             content_type=content_type,
             object_id=object_id,
diff --git a/sapl/sessao/forms.py b/sapl/sessao/forms.py
--- a/sapl/sessao/forms.py
+++ b/sapl/sessao/forms.py
@@ -124,7 +124,7 @@ def save(self, commit=True):
         bancada = super(BancadaForm, self).save(commit)
         content_type = ContentType.objects.get_for_model(Bancada)
         object_id = bancada.pk
-        tipo = TipoAutor.objects.get(descricao='Bancada Parlamentar')
+        tipo = TipoAutor.objects.get(descricao__icontains='Bancada')
         Autor.objects.create(
             content_type=content_type,
             object_id=object_id,
@@ -159,7 +159,7 @@ def save(self, commit=True):
         bloco = super(BlocoForm, self).save(commit)
         content_type = ContentType.objects.get_for_model(Bloco)
         object_id = bloco.pk
-        tipo = TipoAutor.objects.get(descricao='Bloco Parlamentar')
+        tipo = TipoAutor.objects.get(descricao__icontains='Bloco')
         Autor.objects.create(
             content_type=content_type,
             object_id=object_id,


Test patch: