Exemplo n.º 1
0
class DefinitionForm(forms.ModelForm):
    term = ModelChoiceFieldAsText(
        queryset=models.Term.objects.all(),
        field='value',
        label='Término',
        to_field_name='value',
    )
    value = forms.CharField(label='Definición', widget=forms.Textarea())
    tags = forms.CharField(
        label='Etiquetas',
        required=False,
        widget=forms.TextInput(attrs={'data-role': 'tagsinput'}),
    )

    captcha = fields.ReCaptchaField()

    class Meta:
        model = models.Definition
        exclude = ('user', 'active')

    def clean(self):
        super().clean()
        if not self.is_valid() and 'term' in self.cleaned_data:
            term = self.cleaned_data['term']
            if term.definitions.count() == 0:
                term.active = False
                term.save()
                self.cleaned_data.pop('term')
            if 'captcha' in self.errors:
                raise exceptions.ValidationError(
                    'Google ReCaptcha has failed!')
Exemplo n.º 2
0
class CustomAuthenticationForm(auth_forms.AuthenticationForm):
    username = auth_forms.UsernameField(
        label='Usuario',
        widget=forms.TextInput(attrs={'autofocus': True}),
    )
    password = forms.CharField(
        label="Contraseña",
        strip=False,
        widget=forms.PasswordInput(attrs={'autocomplete': 'current-password'}),
    )
    captcha = fields.ReCaptchaField()
Exemplo n.º 3
0
class DefinitionForm(forms.ModelForm):
    term = ModelChoiceFieldAsText(
        queryset=models.Term.objects.all(),
        field='value',
        label='Término',
        to_field_name='value',
    )
    value = forms.CharField(label='Definición', widget=forms.Textarea())

    captcha = fields.ReCaptchaField()

    class Meta:
        model = models.Definition
        exclude = ('user', 'active')
Exemplo n.º 4
0
class CustomUserCreationForm(auth_forms.UserCreationForm):
    password1 = forms.CharField(
        label='Password',
        strip=False,
        widget=forms.PasswordInput(attrs={'autocomplete': 'new-password'}),
    )
    password2 = forms.CharField(
        label='Password confirmation',
        strip=False,
        widget=forms.PasswordInput(attrs={'autocomplete': 'new-password'}),
    )
    email = forms.EmailField()

    captcha = fields.ReCaptchaField()

    class Meta:
        model = auth.get_user_model()
        fields = ('username', 'password1', 'password2', 'email')
        field_classes = {'username': auth_forms.UsernameField}
Exemplo n.º 5
0
class CustomAuthenticationForm(auth_forms.AuthenticationForm):
    captcha = fields.ReCaptchaField()