示例#1
0
class AssessmentSignupForm(SignupForm):
    required_css_class = 'required'
    error_css_class = 'error'

    assessment_uuid = forms.CharField(
        widget=forms.HiddenInput(),
    )
    email = forms.EmailField(
        label='',
        widget=forms.TextInput(
            attrs={
                'placeholder': _('Your email'),
                'class': 'input-lg',
            },
        ),
    )
    password1 = forms.CharField(
        label='',
        widget=forms.PasswordInput(
            attrs={
                'placeholder': _('Choose password'),
                'class': 'input-lg',
            },
        ),
    )

    def __init__(self, *args, **kwargs):
        super(AssessmentSignupForm, self).__init__(*args, **kwargs)
        # The label attribute in the field definition
        # does not work, probably bc there is some magic
        # going on due to email/username options.
        self.fields['email'].label = ''
示例#2
0
class UserForm(forms.ModelForm):
    username = forms.CharField(help_text="Please enter a username.")
    email = forms.CharField(help_text="Please enter your email.")
    password = forms.CharField(widget=forms.PasswordInput(), help_text="Please enter a password.")

    class Meta:
        model = User
        fields = ('username', 'email', 'password')
示例#3
0
class LoginForm(forms.Form):
    """Form for user to log in."""
    class Meta:
        """Meta of the form."""
        fields = ['email', 'password']

    email = forms.EmailField(widget=forms.EmailInput(
        attrs={
            'class': 'form-control',
            'placeholder': '*****@*****.**'
        }))
    password = forms.CharField(widget=forms.PasswordInput(
        attrs={
            'class': 'form-control',
            'placeholder': 'Your s3cr3T password'
        }))
示例#4
0
class RegisterForm(ModelForm):
    password = forms.CharField(widget=forms.PasswordInput())

    class Meta:
        model = User
        fields = ('first_name', 'last_name', 'country', 'email', 'password')

    def clean_email(self):
        email = self.cleaned_data['email']

        if User.objects.filter(email=email).exists():
            raise forms.ValidationError(_("Email has already been registered"))

        return email

    def save(self, commit=True):
        new_user = User.objects.create_user(
            email=self.cleaned_data['email'],
            password=self.cleaned_data['password'],
            username=self.cleaned_data['email'],
            first_name=self.cleaned_data['first_name'],
            last_name=self.cleaned_data['last_name'],
            country=self.cleaned_data['country'])
        return new_user
示例#5
0
class EmpleadoForm(forms.Form):

    cedula = forms.CharField(required=False, label=u'Cédula')
    nombres = forms.CharField(max_length=250,
                              widget=forms.TextInput(attrs={'size': '30'}))
    apellido_paterno = forms.CharField(
        max_length=250, widget=forms.TextInput(attrs={'size': '30'}))
    apellido_materno = forms.CharField(
        max_length=250,
        widget=forms.TextInput(attrs={'size': '30'}),
        required=False)

    pais = forms.ModelChoiceField(
        queryset=Pais.objects.all(),
        empty_label="Escoger un pais",
        widget=forms.Select(attrs={
            'placeholder': 'País',
            'onChange': "getProvincias(this.value)"
        }))
    provincia = forms.ModelChoiceField(
        queryset=Provincia.objects.none(),
        empty_label="Escoger una provincia",
        widget=forms.Select(
            attrs={
                'placeholder': 'Provincia o estado',
                'onChange': "getCiudades(this.value)"
            }))
    ciudad = forms.ModelChoiceField(
        queryset=Ciudad.objects.none(),
        empty_label="Escoger una ciudad",
        widget=forms.Select(attrs={'placeholder': 'Ciudad o Cantón'}))

    sexo = forms.ChoiceField(choices=PersonaNatural.SEXO_CHOICES,
                             required=True)
    fecha_nacimiento = forms.DateField(required=False)
    observaciones = forms.CharField(widget=forms.Textarea())
    usuario = forms.CharField(max_length=13,
                              widget=forms.TextInput(attrs={'size': '30'}))
    contrasenia = forms.CharField(
        max_length=13, widget=forms.PasswordInput(attrs={'size': '30'}))
    email = forms.EmailField(max_length=25,
                             widget=forms.TextInput(attrs={'size': '30'}))
    plazas_trabajo = forms.ModelMultipleChoiceField(
        queryset=PlazaTrabajo.objects.all(), widget=forms.SelectMultiple)
    foto = forms.ImageField(required=False)

    def modificarQuerySet(self, pais_id, provincia_id):
        if pais_id not in ('', None):
            self.fields['provincia'].queryset = Provincia.objects.filter(
                pais__id=pais_id)

        if provincia_id not in ('', None):
            self.fields['ciudad'].queryset = Ciudad.objects.filter(
                provincia__id=provincia_id)

    def save(self, empleado=None):
        cleaned_data = super(EmpleadoForm, self).clean()

        if empleado is None:
            persona = Persona()
            persona.tipo = Persona.TIPO_PERSONA_NATURAL
            persona.observaciones = cleaned_data["observaciones"]
            persona.ruc = cleaned_data["cedula"]
            persona.nombre_comercial = ""
            persona.save()

            usuario = User()
            usuario.username = cleaned_data["usuario"]
            usuario.set_password(cleaned_data["contrasenia"])
            usuario.email = cleaned_data["email"]
            usuario.save()

            persona_natural = PersonaNatural()
            persona_natural.ciudad_nacimiento = cleaned_data['ciudad']
            persona_natural.cedula = cleaned_data["cedula"]
            persona_natural.nombres = cleaned_data["nombres"]
            persona_natural.apellido_paterno = cleaned_data["apellido_paterno"]
            persona_natural.apellido_materno = cleaned_data["apellido_materno"]
            persona_natural.persona = persona
            persona_natural.sexo = cleaned_data["sexo"]
            persona_natural.fecha_nacimiento = cleaned_data["fecha_nacimiento"]
            persona_natural.save()

            empleado = Empleado()
            empleado.persona = persona_natural
            empleado.usuario = usuario
            empleado.foto = cleaned_data["foto"]
            empleado.observaciones = cleaned_data["observaciones"]
            empleado.save()
            empleado.plazas_trabajo = cleaned_data["plazas_trabajo"]
            empleado.save()
        else:
            empleado.persona.nombres = cleaned_data["nombres"]
            empleado.persona.apellido_paterno = cleaned_data[
                "apellido_paterno"]
            empleado.persona.apellido_materno = cleaned_data[
                "apellido_materno"]
            empleado.persona.sexo = cleaned_data["sexo"]
            empleado.persona.cedula = cleaned_data["cedula"]
            empleado.persona.ciudad_nacimiento = cleaned_data["ciudad"]
            empleado.persona.save()

            empleado.usuario.email = cleaned_data["email"]
            empleado.usuario.save()

            empleado.foto = cleaned_data["foto"]
            empleado.observaciones = cleaned_data["observaciones"]
            empleado.save()

            empleado.plazas_trabajo = cleaned_data["plazas_trabajo"]
            empleado.save()

        return empleado

    def clean_usuario(self):
        if self.cleaned_data['usuario']:
            p = User.objects.filter(username=self.cleaned_data['usuario'])
            if len(p) > 0:
                raise forms.ValidationError(
                    _("Ya esxiste un usuario con este username"))
        return self.cleaned_data['usuario']
示例#6
0
 def __init__(self, *args, **kwargs):
     kwargs.setdefault("widget", forms.PasswordInput(render_value=False))
     self.strip = kwargs.pop("strip", True)
     super(PasswordField, self).__init__(*args, **kwargs)
示例#7
0
 class Meta:
     model = User
     fields = ['name', 'email', 'password']
     widgets = {
         'password': forms.PasswordInput(),
     }
示例#8
0
class LoginForm(forms.Form):
    username = forms.CharField(label='Nazwa użytkownika')
    password = forms.CharField(label='Hasło', widget=forms.PasswordInput())
示例#9
0
class RegistrationForm(forms.ModelForm):
    """Form for user model."""
    name = forms.CharField(
        required=True,
        label='Your name',
        widget=forms.TextInput(
            attrs={'placeholder': 'John Doe'})
    )
    email = forms.EmailField(
        required=True,
        label='Your email',
        widget=forms.EmailInput(
            attrs={
                'placeholder': '*****@*****.**'})
    )
    password = forms.CharField(
        required=True,
        label='Your password',
        widget=forms.PasswordInput()
    )
    password2 = forms.CharField(
        required=True,
        label='Your password (again)',
        widget=forms.PasswordInput()
    )
    website = forms.URLField(
        required=False,
        label='Your website',
        widget=forms.URLInput(
            attrs={'placeholder': 'http://john.doe.com'})
    )
    location = forms.PointField(
        label='Click your location on the map',
        widget=LeafletWidget())
    role = forms.ModelChoiceField(
        label='Your role',
        queryset=Role.objects.filter(sort_number__gte=1),
        initial=1)
    email_updates = forms.BooleanField(
        required=False,
        label='Receive project news and updates')

    class Meta:
        """Association between models and this form."""
        model = User
        fields = ['name', 'email', 'password', 'password2', 'website', 'role',
                  'location', 'email_updates']

    def clean(self):
        """Verifies that the values entered into the password fields match."""
        cleaned_data = super(RegistrationForm, self).clean()
        if 'password' in cleaned_data and 'password2' in cleaned_data:
            if cleaned_data['password'] != cleaned_data['password2']:
                raise forms.ValidationError(
                    "Passwords don't match. Please enter both fields again.")
        return cleaned_data

    def save(self, commit=True):
        """Save form.

        :param commit: Whether committed to db or not.
        :type commit: bool
        """
        user = super(RegistrationForm, self).save(commit=False)
        user.set_password(self.cleaned_data['password'])
        if commit:
            user.save()
        return user
示例#10
0
class RegistrationForm(forms.ModelForm):
    """Form for user model."""
    name = forms.CharField(
        required=True,
        label='Name',
        widget=forms.TextInput(attrs={'placeholder': 'John Doe'}))
    email = forms.EmailField(
        required=True,
        label='Email',
        widget=forms.EmailInput(attrs={'placeholder': '*****@*****.**'}))
    image = forms.ImageField(required=False, widget=CustomClearableFileInput())
    password = forms.CharField(required=True,
                               label='Password',
                               widget=forms.PasswordInput())
    password2 = forms.CharField(required=True,
                                label='Password (again)',
                                widget=forms.PasswordInput())
    website = forms.URLField(
        required=False,
        label='Website',
        widget=forms.URLInput(attrs={'placeholder': 'http://john.doe.com'}))
    inasafe_roles = forms.ModelMultipleChoiceField(
        required=True,
        label='Your InaSAFE role(s)',
        queryset=InasafeRole.objects.all(),
        widget=forms.CheckboxSelectMultiple)
    osm_roles = forms.ModelMultipleChoiceField(
        required=False,
        label='Your OSM role(s)',
        queryset=OsmRole.objects.all(),
        widget=forms.CheckboxSelectMultiple)
    osm_username = forms.CharField(
        required=False,
        label='OSM Username',
        widget=forms.TextInput(attrs={'placeholder': 'johndoe'}))
    location = forms.PointField(
        label='Draw a marker as your location on the map',
        widget=LeafletWidget())
    email_updates = forms.BooleanField(
        required=False, label='Receive project news and updates')

    class Meta:
        """Association between models and this form."""
        model = User
        fields = [
            'name', 'email', 'image', 'password', 'password2', 'website',
            'inasafe_roles', 'osm_roles', 'osm_username', 'location',
            'email_updates'
        ]

    def clean(self):
        """Verifies that the values entered into the password fields match."""
        cleaned_data = super(RegistrationForm, self).clean()
        if 'password' in cleaned_data and 'password2' in cleaned_data:
            if cleaned_data['password'] != cleaned_data['password2']:
                raise forms.ValidationError(
                    "Passwords don't match. Please enter both fields again.")
        return cleaned_data

    def save(self, commit=True):
        """Save form.

        :param commit: Whether committed to db or not.
        :type commit: bool
        """
        user = super(RegistrationForm, self).save(commit=False)
        user.set_password(self.cleaned_data['password'])
        if commit:
            user.save()
        return user