diff --git a/sapl/base/models.py b/sapl/base/models.py index b1edf8b64..640616fa9 100644 --- a/sapl/base/models.py +++ b/sapl/base/models.py @@ -1,17 +1,18 @@ -import reversion from django.contrib.contenttypes.fields import GenericForeignKey from django.contrib.contenttypes.models import ContentType from django.db import models from django.db.models.signals import post_migrate from django.db.utils import DEFAULT_DB_ALIAS from django.utils.translation import ugettext_lazy as _ +import reversion from sapl.utils import ( UF, YES_NO_CHOICES, get_settings_auth_user_model, models_with_gr_for_model - ) +) + TIPO_DOCUMENTO_ADMINISTRATIVO = (('O', _('Ostensivo')), ('R', _('Restritivo'))) @@ -176,6 +177,7 @@ class AppConfig(models.Model): ('menu_sistemas', _('Renderizar Menu Sistemas')), ('view_tabelas_auxiliares', _('Visualizar Tabelas Auxiliares')), ) + ordering = ('-id',) @classmethod def attr(cls, attr): @@ -262,7 +264,7 @@ def cria_models_tipo_autor(app_config, verbosity=2, interactive=True, models = models_with_gr_for_model(Autor) print("\n\033[93m\033[1m{}\033[0m".format( - _('Atualizando registros TipoAutor do SAPL:'))) + _('Atualizando registros TipoAutor do SAPL:'))) for model in models: content_type = ContentType.objects.get_for_model(model) tipo_autor = TipoAutor.objects.filter( @@ -272,8 +274,8 @@ def cria_models_tipo_autor(app_config, verbosity=2, interactive=True, msg1 = "Carga de {} não efetuada.".format( TipoAutor._meta.verbose_name) msg2 = " Já Existe um {} {} relacionado...".format( - TipoAutor._meta.verbose_name, - model._meta.verbose_name) + TipoAutor._meta.verbose_name, + model._meta.verbose_name) msg = " {}{}".format(msg1, msg2) else: novo_autor = TipoAutor() @@ -283,10 +285,11 @@ def cria_models_tipo_autor(app_config, verbosity=2, interactive=True, msg1 = "Carga de {} efetuada.".format( TipoAutor._meta.verbose_name) msg2 = " {} {} criado...".format( - TipoAutor._meta.verbose_name, content_type.model) + TipoAutor._meta.verbose_name, content_type.model) msg = " {}{}".format(msg1, msg2) print(msg) # Disconecta função para evitar a chamada repetidas vezes. post_migrate.disconnect(receiver=cria_models_tipo_autor) + post_migrate.connect(receiver=cria_models_tipo_autor) diff --git a/sapl/base/views.py b/sapl/base/views.py index ebd22d626..4154cfe4b 100644 --- a/sapl/base/views.py +++ b/sapl/base/views.py @@ -521,15 +521,18 @@ class AppConfigCrud(CrudAux): class CreateView(CrudAux.CreateView): def get(self, request, *args, **kwargs): - app_config = AppConfig.objects.last() - if app_config: - return HttpResponseRedirect( - reverse('sapl.base:appconfig_update', - kwargs={'pk': app_config.pk})) - else: - self.object = None - return super(CrudAux.CreateView, self).get( - request, *args, **kwargs) + app_config = AppConfig.objects.first() + + if not app_config: + app_config = AppConfig() + app_config.save() + + return HttpResponseRedirect( + reverse('sapl.base:appconfig_update', + kwargs={'pk': app_config.pk})) + + def post(self, request, *args, **kwargs): + return self.get(request, *args, **kwargs) class ListView(CrudAux.ListView):