Browse Source

Evita erro em migrate com BD vazio

pull/3630/head
Edward Ribeiro 2 years ago
parent
commit
cae71bcd59
  1. 32
      sapl/base/forms.py

32
sapl/base/forms.py

@ -44,13 +44,11 @@ from sapl.utils import (autor_label, autor_modal, ChoiceWithoutValidationField,
from .models import AppConfig, CasaLegislativa from .models import AppConfig, CasaLegislativa
ACTION_CREATE_USERS_AUTOR_CHOICE = [ ACTION_CREATE_USERS_AUTOR_CHOICE = [
('A', _('Associar um usuário existente')), ('A', _('Associar um usuário existente')),
('N', _('Autor sem Usuário de Acesso ao Sapl')), ('N', _('Autor sem Usuário de Acesso ao Sapl')),
] ]
STATUS_USER_CHOICE = [ STATUS_USER_CHOICE = [
('R', _('Apenas retirar Perfil de Autor do Usuário que está sendo' ('R', _('Apenas retirar Perfil de Autor do Usuário que está sendo'
' desvinculado')), ' desvinculado')),
@ -61,7 +59,6 @@ STATUS_USER_CHOICE = [
class UserAdminForm(ModelForm): class UserAdminForm(ModelForm):
is_active = forms.TypedChoiceField(label=_('Usuário Ativo'), is_active = forms.TypedChoiceField(label=_('Usuário Ativo'),
choices=YES_NO_CHOICES, choices=YES_NO_CHOICES,
coerce=lambda x: x == 'True') coerce=lambda x: x == 'True')
@ -476,7 +473,6 @@ class SessaoLegislativaForm(FileFieldCheckMixin, ModelForm):
class TipoAutorForm(ModelForm): class TipoAutorForm(ModelForm):
class Meta: class Meta:
model = TipoAutor model = TipoAutor
fields = ['descricao'] fields = ['descricao']
@ -742,11 +738,16 @@ class AutorFilterSet(django_filters.FilterSet):
def get_username(): def get_username():
return [(u, u) for u in get_user_model().objects.all().order_by('username').values_list('username', flat=True)] try:
return [(u, u) for u in
get_user_model().objects.all().order_by('username').values_list('username', flat=True)]
except:
return []
def get_models(): def get_models():
return [(m, m) for m in AuditLog.objects.distinct('model_name').order_by('model_name').values_list('model_name', flat=True)] return [(m, m) for m in
AuditLog.objects.distinct('model_name').order_by('model_name').values_list('model_name', flat=True)]
class AuditLogFilterSet(django_filters.FilterSet): class AuditLogFilterSet(django_filters.FilterSet):
@ -784,13 +785,11 @@ class AuditLogFilterSet(django_filters.FilterSet):
class OperadorAutorForm(ModelForm): class OperadorAutorForm(ModelForm):
class Meta: class Meta:
model = OperadorAutor model = OperadorAutor
fields = ['user', ] fields = ['user', ]
def __init__(self, *args, **kwargs): def __init__(self, *args, **kwargs):
row = to_row([('user', 12)]) row = to_row([('user', 12)])
self.helper = SaplFormHelper() self.helper = SaplFormHelper()
@ -827,7 +826,6 @@ class RelatorioDocumentosAcessoriosFilterSet(django_filters.FilterSet):
fields = ['tipo', 'materia__tipo', 'data'] fields = ['tipo', 'materia__tipo', 'data']
def __init__(self, *args, **kwargs): def __init__(self, *args, **kwargs):
super( super(
RelatorioDocumentosAcessoriosFilterSet, self RelatorioDocumentosAcessoriosFilterSet, self
).__init__(*args, **kwargs) ).__init__(*args, **kwargs)
@ -867,7 +865,6 @@ class RelatorioDocumentosAcessoriosFilterSet(django_filters.FilterSet):
class RelatorioAtasFilterSet(django_filters.FilterSet): class RelatorioAtasFilterSet(django_filters.FilterSet):
class Meta(FilterOverridesMetaMixin): class Meta(FilterOverridesMetaMixin):
model = SessaoPlenaria model = SessaoPlenaria
fields = ['data_inicio'] fields = ['data_inicio']
@ -918,7 +915,6 @@ def ultimo_ano_com_norma():
class RelatorioNormasMesFilterSet(django_filters.FilterSet): class RelatorioNormasMesFilterSet(django_filters.FilterSet):
ano = django_filters.ChoiceFilter(required=True, ano = django_filters.ChoiceFilter(required=True,
label='Ano da Norma', label='Ano da Norma',
choices=choice_anos_com_normas, choices=choice_anos_com_normas,
@ -970,7 +966,6 @@ class RelatorioNormasMesFilterSet(django_filters.FilterSet):
class EstatisticasAcessoNormasForm(Form): class EstatisticasAcessoNormasForm(Form):
ano = forms.ChoiceField(required=True, ano = forms.ChoiceField(required=True,
label='Ano de acesso', label='Ano de acesso',
choices=RANGE_ANOS, choices=RANGE_ANOS,
@ -1034,7 +1029,6 @@ class EstatisticasAcessoNormasForm(Form):
class RelatorioNormasVigenciaFilterSet(django_filters.FilterSet): class RelatorioNormasVigenciaFilterSet(django_filters.FilterSet):
ano = django_filters.ChoiceFilter(required=True, ano = django_filters.ChoiceFilter(required=True,
label='Ano da Norma', label='Ano da Norma',
choices=choice_anos_com_normas, choices=choice_anos_com_normas,
@ -1091,7 +1085,6 @@ class RelatorioNormasVigenciaFilterSet(django_filters.FilterSet):
class RelatorioPresencaSessaoFilterSet(django_filters.FilterSet): class RelatorioPresencaSessaoFilterSet(django_filters.FilterSet):
class Meta(FilterOverridesMetaMixin): class Meta(FilterOverridesMetaMixin):
model = SessaoPlenaria model = SessaoPlenaria
fields = ['data_inicio', fields = ['data_inicio',
@ -1158,7 +1151,6 @@ class RelatorioPresencaSessaoFilterSet(django_filters.FilterSet):
class RelatorioHistoricoTramitacaoFilterSet(django_filters.FilterSet): class RelatorioHistoricoTramitacaoFilterSet(django_filters.FilterSet):
autoria__autor = django_filters.CharFilter(widget=forms.HiddenInput()) autoria__autor = django_filters.CharFilter(widget=forms.HiddenInput())
@property @property
@ -1225,7 +1217,6 @@ class RelatorioHistoricoTramitacaoFilterSet(django_filters.FilterSet):
class RelatorioDataFimPrazoTramitacaoFilterSet(django_filters.FilterSet): class RelatorioDataFimPrazoTramitacaoFilterSet(django_filters.FilterSet):
ano = django_filters.ChoiceFilter(required=False, ano = django_filters.ChoiceFilter(required=False,
label='Ano da Matéria', label='Ano da Matéria',
choices=choice_anos_com_materias) choices=choice_anos_com_materias)
@ -1372,7 +1363,6 @@ class RelatorioAudienciaFilterSet(django_filters.FilterSet):
class RelatorioMateriasTramitacaoFilterSet(django_filters.FilterSet): class RelatorioMateriasTramitacaoFilterSet(django_filters.FilterSet):
materia__ano = django_filters.ChoiceFilter(required=True, materia__ano = django_filters.ChoiceFilter(required=True,
label='Ano da Matéria', label='Ano da Matéria',
choices=choice_anos_com_materias) choices=choice_anos_com_materias)
@ -1438,7 +1428,6 @@ class RelatorioMateriasTramitacaoFilterSet(django_filters.FilterSet):
class RelatorioMateriasPorAnoAutorTipoFilterSet(django_filters.FilterSet): class RelatorioMateriasPorAnoAutorTipoFilterSet(django_filters.FilterSet):
ano = django_filters.ChoiceFilter(required=True, ano = django_filters.ChoiceFilter(required=True,
label='Ano da Matéria', label='Ano da Matéria',
choices=choice_anos_com_materias) choices=choice_anos_com_materias)
@ -1478,7 +1467,6 @@ class RelatorioMateriasPorAnoAutorTipoFilterSet(django_filters.FilterSet):
class RelatorioMateriasPorAutorFilterSet(django_filters.FilterSet): class RelatorioMateriasPorAutorFilterSet(django_filters.FilterSet):
autoria__autor = django_filters.CharFilter(widget=forms.HiddenInput()) autoria__autor = django_filters.CharFilter(widget=forms.HiddenInput())
@property @property
@ -1535,7 +1523,6 @@ class RelatorioMateriasPorAutorFilterSet(django_filters.FilterSet):
class CasaLegislativaForm(FileFieldCheckMixin, ModelForm): class CasaLegislativaForm(FileFieldCheckMixin, ModelForm):
class Meta: class Meta:
model = CasaLegislativa model = CasaLegislativa
@ -1690,18 +1677,15 @@ class ConfiguracoesAppForm(ModelForm):
class RecuperarSenhaForm(GoogleRecapthaMixin, PasswordResetForm): class RecuperarSenhaForm(GoogleRecapthaMixin, PasswordResetForm):
logger = logging.getLogger(__name__) logger = logging.getLogger(__name__)
def __init__(self, *args, **kwargs): def __init__(self, *args, **kwargs):
kwargs['title_label'] = _('Insira o e-mail cadastrado com a sua conta') kwargs['title_label'] = _('Insira o e-mail cadastrado com a sua conta')
kwargs['action_label'] = _('Enviar') kwargs['action_label'] = _('Enviar')
super().__init__(*args, **kwargs) super().__init__(*args, **kwargs)
def clean(self): def clean(self):
super(RecuperarSenhaForm, self).clean() super(RecuperarSenhaForm, self).clean()
email_existente = get_user_model().objects.filter( email_existente = get_user_model().objects.filter(
@ -1825,7 +1809,6 @@ class AlterarSenhaForm(Form):
class PartidoForm(FileFieldCheckMixin, ModelForm): class PartidoForm(FileFieldCheckMixin, ModelForm):
class Meta: class Meta:
model = Partido model = Partido
exclude = [] exclude = []
@ -1924,7 +1907,6 @@ class RelatorioHistoricoTramitacaoAdmFilterSet(django_filters.FilterSet):
class RelatorioNormasPorAutorFilterSet(django_filters.FilterSet): class RelatorioNormasPorAutorFilterSet(django_filters.FilterSet):
autorianorma__autor = django_filters.CharFilter(widget=forms.HiddenInput()) autorianorma__autor = django_filters.CharFilter(widget=forms.HiddenInput())
@property @property

Loading…
Cancel
Save