Browse Source

Fix #1273

pull/1333/head
LeandroRoberto 8 years ago
parent
commit
b437f1e497
  1. 20
      sapl/base/forms.py

20
sapl/base/forms.py

@ -1,4 +1,3 @@
import django_filters
from crispy_forms.bootstrap import FieldWithButtons, InlineRadios, StrictButton from crispy_forms.bootstrap import FieldWithButtons, InlineRadios, StrictButton
from crispy_forms.helper import FormHelper from crispy_forms.helper import FormHelper
from crispy_forms.layout import HTML, Button, Div, Field, Fieldset, Layout, Row from crispy_forms.layout import HTML, Button, Div, Field, Fieldset, Layout, Row
@ -13,8 +12,9 @@ from django.contrib.contenttypes.models import ContentType
from django.core.exceptions import ValidationError from django.core.exceptions import ValidationError
from django.db import models, transaction from django.db import models, transaction
from django.forms import ModelForm from django.forms import ModelForm
from django.utils.translation import ugettext_lazy as _
from django.utils.translation import string_concat from django.utils.translation import string_concat
from django.utils.translation import ugettext_lazy as _
import django_filters
from sapl.base.models import Autor, TipoAutor from sapl.base.models import Autor, TipoAutor
from sapl.crispy_layout_mixin import (SaplFormLayout, form_actions, to_column, from sapl.crispy_layout_mixin import (SaplFormLayout, form_actions, to_column,
@ -28,6 +28,7 @@ from sapl.utils import (RANGE_ANOS, ChoiceWithoutValidationField,
from .models import AppConfig, CasaLegislativa from .models import AppConfig, CasaLegislativa
ACTION_CREATE_USERS_AUTOR_CHOICE = [ ACTION_CREATE_USERS_AUTOR_CHOICE = [
('C', _('Criar novo Usuário')), ('C', _('Criar novo Usuário')),
('A', _('Associar um usuário existente')), ('A', _('Associar um usuário existente')),
@ -336,8 +337,11 @@ class AutorForm(ModelForm):
_('O Registro definido (%s-%s) não está na base de %s.' _('O Registro definido (%s-%s) não está na base de %s.'
) % (cd['autor_related'], cd['q'], tipo.descricao)) ) % (cd['autor_related'], cd['q'], tipo.descricao))
if qs_autor.filter(object_id=cd['autor_related']).exists(): qs_autor_selected = qs_autor.filter(
autor = qs_autor.filter(object_id=cd['autor_related']).first() object_id=cd['autor_related'],
content_type_id=cd['tipo'].content_type_id)
if qs_autor_selected.exists():
autor = qs_autor_selected.first()
raise ValidationError( raise ValidationError(
_('Já existe um autor Cadastrado para %s' _('Já existe um autor Cadastrado para %s'
) % autor.autor_related) ) % autor.autor_related)
@ -714,6 +718,7 @@ class ConfiguracoesAppForm(ModelForm):
class RecuperarSenhaForm(PasswordResetForm): class RecuperarSenhaForm(PasswordResetForm):
def __init__(self, *args, **kwargs): def __init__(self, *args, **kwargs):
row1 = to_row( row1 = to_row(
[('email', 12)]) [('email', 12)])
@ -728,7 +733,7 @@ class RecuperarSenhaForm(PasswordResetForm):
def clean(self): def clean(self):
super(RecuperarSenhaForm, self).clean() super(RecuperarSenhaForm, self).clean()
email_existente = User.objects.filter( email_existente = User.objects.filter(
email=self.data['email']).exists() email=self.data['email']).exists()
@ -740,6 +745,7 @@ class RecuperarSenhaForm(PasswordResetForm):
class NovaSenhaForm(SetPasswordForm): class NovaSenhaForm(SetPasswordForm):
def __init__(self, user, *args, **kwargs): def __init__(self, user, *args, **kwargs):
self.user = user self.user = user
super(NovaSenhaForm, self).__init__(user, *args, **kwargs) super(NovaSenhaForm, self).__init__(user, *args, **kwargs)
@ -750,5 +756,5 @@ class NovaSenhaForm(SetPasswordForm):
self.helper = FormHelper() self.helper = FormHelper()
self.helper.layout = Layout( self.helper.layout = Layout(
row1, row1,
form_actions(save_label='Enviar')) form_actions(save_label='Enviar'))

Loading…
Cancel
Save