Browse Source

HOT-FIX: falha na unicidade das configurações da app

havia possibilidade de um POST criar mais um registro do model
base.models.AppConfig. Em uma base de teste especifica foi identifica
'n' registros, possivelmente causados por clique duplo no botão de
salvar (problema já resolvido tb)...
pull/1607/head
LeandroRoberto 7 years ago
parent
commit
caebc86da9
  1. 7
      sapl/base/models.py
  2. 15
      sapl/base/views.py

7
sapl/base/models.py

@ -1,17 +1,18 @@
import reversion
from django.contrib.contenttypes.fields import GenericForeignKey from django.contrib.contenttypes.fields import GenericForeignKey
from django.contrib.contenttypes.models import ContentType from django.contrib.contenttypes.models import ContentType
from django.db import models from django.db import models
from django.db.models.signals import post_migrate from django.db.models.signals import post_migrate
from django.db.utils import DEFAULT_DB_ALIAS from django.db.utils import DEFAULT_DB_ALIAS
from django.utils.translation import ugettext_lazy as _ from django.utils.translation import ugettext_lazy as _
import reversion
from sapl.utils import ( from sapl.utils import (
UF, UF,
YES_NO_CHOICES, YES_NO_CHOICES,
get_settings_auth_user_model, get_settings_auth_user_model,
models_with_gr_for_model models_with_gr_for_model
) )
TIPO_DOCUMENTO_ADMINISTRATIVO = (('O', _('Ostensivo')), TIPO_DOCUMENTO_ADMINISTRATIVO = (('O', _('Ostensivo')),
('R', _('Restritivo'))) ('R', _('Restritivo')))
@ -176,6 +177,7 @@ class AppConfig(models.Model):
('menu_sistemas', _('Renderizar Menu Sistemas')), ('menu_sistemas', _('Renderizar Menu Sistemas')),
('view_tabelas_auxiliares', _('Visualizar Tabelas Auxiliares')), ('view_tabelas_auxiliares', _('Visualizar Tabelas Auxiliares')),
) )
ordering = ('-id',)
@classmethod @classmethod
def attr(cls, attr): def attr(cls, attr):
@ -289,4 +291,5 @@ def cria_models_tipo_autor(app_config, verbosity=2, interactive=True,
# Disconecta função para evitar a chamada repetidas vezes. # Disconecta função para evitar a chamada repetidas vezes.
post_migrate.disconnect(receiver=cria_models_tipo_autor) post_migrate.disconnect(receiver=cria_models_tipo_autor)
post_migrate.connect(receiver=cria_models_tipo_autor) post_migrate.connect(receiver=cria_models_tipo_autor)

15
sapl/base/views.py

@ -521,15 +521,18 @@ class AppConfigCrud(CrudAux):
class CreateView(CrudAux.CreateView): class CreateView(CrudAux.CreateView):
def get(self, request, *args, **kwargs): def get(self, request, *args, **kwargs):
app_config = AppConfig.objects.last() app_config = AppConfig.objects.first()
if app_config:
if not app_config:
app_config = AppConfig()
app_config.save()
return HttpResponseRedirect( return HttpResponseRedirect(
reverse('sapl.base:appconfig_update', reverse('sapl.base:appconfig_update',
kwargs={'pk': app_config.pk})) kwargs={'pk': app_config.pk}))
else:
self.object = None def post(self, request, *args, **kwargs):
return super(CrudAux.CreateView, self).get( return self.get(request, *args, **kwargs)
request, *args, **kwargs)
class ListView(CrudAux.ListView): class ListView(CrudAux.ListView):

Loading…
Cancel
Save