#encoding:utf-8 from __future__ import unicode_literals from django import * from django.forms import * from snct.models import * from django import forms from django import forms from django.forms.util import flatatt from django.template import loader from django.utils.datastructures import SortedDict from django.utils.html import format_html, format_html_join from django.utils.http import int_to_base36 from django.utils.safestring import mark_safe from django.utils.text import capfirst from django.utils.translation import ugettext, ugettext_lazy as _ from django.contrib.auth import authenticate, get_user_model from django.contrib.auth.models import User from django.contrib.auth.hashers import UNUSABLE_PASSWORD, identify_hasher from django.contrib.auth.tokens import default_token_generator from django.contrib.sites.models import get_current_site from datetime import datetime UNMASKED_DIGITS_TO_SHOW = 6 mask_password = lambda p: "%s%s" % (p[:UNMASKED_DIGITS_TO_SHOW], "*" * max(len(p) - UNMASKED_DIGITS_TO_SHOW, 0)) class RegistroInsticion(forms.Form): nombre = forms.CharField(max_length = 250, widget = forms.TextInput(attrs={'class':'required span6'})) direccion = forms.CharField(label="Dirección", max_length = 200, widget = forms.TextInput(attrs={'class':'required span6'})) poblacion = forms.CharField(label="Población", max_length = 150, required=False, widget = forms.TextInput(attrs={'class':'span6'})) municipio = forms.ModelChoiceField(empty_label="Seleccione el Municipio", queryset=cat_municipio.objects.all(), widget = forms.Select(attrs={'class':'required span6'})) codigo_postal = forms.CharField(label="Código Postal", max_length = 5, widget = forms.TextInput(attrs={'class':'required digits span6'})) telefono = forms.CharField(label="Teléfono", max_length=20, required=False, widget = forms.TextInput(attrs={'class':'number span6'})) extencion = forms.CharField(label="Extensión", max_length=6, required=False, widget = forms.TextInput(attrs={'class':'number span6'})) correo = forms.EmailField(max_length=100, widget = forms.TextInput(attrs={'class':'required email span6'})) pagina_web = forms.URLField(label="Página Web", max_length=400, required=False, widget = forms.TextInput(attrs={'class':'url span6'})) fecha_registro = forms.DateField(label="Fecha de Registro", initial=datetime.today().date(), widget = forms.TextInput(attrs={'class':'required span6'})) fax = forms.CharField(max_length=20, required=False, widget = forms.TextInput(attrs={'class':'digits span6'})) tipo_institucion = forms.ModelChoiceField(label="Tipo de Institución", empty_label="Seleccione el tipo", queryset=cat_tipo_institucion.objects.all(), widget = forms.Select(attrs={'class':'required span6'})) #usuario = forms.ModelChoiceField(queryset=User.objects.all()) class RegistroResponsable(forms.Form): participacion = forms.ModelChoiceField(label="Tipo de Participación", empty_label="Seleccione la Participación", queryset=cat_tipo_participacion.objects.all(), widget = forms.Select(attrs={'class':'required span6'})) nombre_responsable = forms.CharField(label="Nombre del Responsable", max_length=70, widget = forms.TextInput(attrs={'class':'required span6'})) telefono_responsable = forms.CharField(label="Teléfono del Responsable", max_length=15, widget = forms.TextInput(attrs={'class':'required digits span6'})) extencion_responsable = forms.CharField(label="Extensión del Responable", max_length=6, required=False, widget = forms.TextInput(attrs={'class':'number span6'})) celular = forms.CharField(max_length=15, required=False, widget = forms.TextInput(attrs={'class':'digits span6'})) correo_responsable = forms.EmailField(label="Correo", max_length=100, widget = forms.TextInput(attrs={'class':'required email span6'})) #institucion_ = forms.ModelChoiceField(queryset=institucion.objects.all()) class UserCreationForm(forms.ModelForm): """ A form that creates a user, with no privileges, from the given username and password. """ error_messages = { 'duplicate_username': _("A user with that username already exists."), 'password_mismatch': _("The two password fields didn't match."), } username = forms.RegexField(label=_("Username") ,max_length=30, regex=r'^[\w.@+-]+$', help_text=_("Required. 30 characters or fewer. Letters, digits and " "@/./+/-/_ only."), error_messages={ 'invalid': _("This value may contain only letters, numbers and " "@/./+/-/_ characters.")} ,widget = forms.TextInput(attrs={'class':'required usernameField span6'}) ) password1 = forms.CharField(label=_("Password"), widget=forms.PasswordInput(attrs={'class':'required span6'})) password2 = forms.CharField(label=_("Password confirmation"), widget=forms.PasswordInput(attrs={'class':'required span6'}), help_text=_("Enter the same password as above, for verification.")) class Meta: model = User fields = ("username",) def clean_username(self): # Since User.username is unique, this check is redundant, # but it sets a nicer error message than the ORM. See #13147. username = self.cleaned_data["username"] try: User._default_manager.get(username=username) except User.DoesNotExist: return username raise forms.ValidationError(self.error_messages['duplicate_username']) def clean_password2(self): password1 = self.cleaned_data.get("password1") password2 = self.cleaned_data.get("password2") if password1 and password2 and password1 != password2: raise forms.ValidationError( self.error_messages['password_mismatch']) return password2 def save(self, commit=True): user = super(UserCreationForm, self).save(commit=False) user.set_password(self.cleaned_data["password1"]) if commit: user.save() return user class RegistroActividad(forms.ModelForm): tipo_publico = forms.ModelMultipleChoiceField(widget=forms.CheckboxSelectMultiple, queryset=cat_tipo_publico.objects.all()) def __init__(self, *args, **kwargs): super(RegistroActividad, self).__init__(*args, **kwargs) self.fields['titulo'].label = 'Título' self.fields['tipo_actividad'].empty_label = 'Seleccione el Tipo de Actividad' self.fields['tipo_actividad'].label = 'Tipo de Actividad' self.fields['especificar_actividad'].label = 'Especifique su Actividad' self.fields['fecha'].empty_label = 'Seleccione la Fecha' self.fields['municipio'].empty_label= 'Seleccione el Municipio' self.fields['direccion'].label = 'Dirección' self.fields['tipo_publico'].label = 'Tipo de Público' self.fields['descripcion'].label = 'Descripción' class Meta: model = registro_actividad fields = ('titulo','tipo_actividad','especificar_actividad','tema','fecha','hora','lugar','municipio','direccion','tipo_publico','cupo','descripcion') widgets = { 'titulo': TextInput(attrs={'placeholder': 'Escriba el titulo de la actividad'}), 'especificar_actividad': TextInput(attrs={'placeholder': 'Especifique la actividad'}), 'tema': TextInput(attrs={'placeholder': 'Escriba el tema de la actividad'}), 'hora': TextInput(attrs={'placeholder': 'Escriba la hora. ej. 10:30 ó 18:30'}), 'lugar': TextInput(attrs={'placeholder': 'Escriba el lugar '}), 'direccion': TextInput(attrs={'placeholder': 'Escriba la dirección'}), 'descripcion': Textarea(attrs={'placeholder': 'Escriba una descripción de la actividad'}), } def clean(self): return self.cleaned_data class RegistroResponsable1(forms.ModelForm): class Meta: model = cat_personas fields = ('nombre',) widgets = { 'nombre': TextInput(attrs={'placeholder': 'Escriba el nombre completo del responsable'}), } def clean(self): return self.cleaned_data class RegistroExpositor(forms.Form): nombre = forms.CharField(max_length=70, required=True) def clean(self): return self.cleaned_data class RegistroParticipantes(ModelForm): class Meta: model = cat_personas fields = ('nombre',) widgets = { 'nombre': TextInput(attrs={'placeholder': 'Escriba el nombre completo del participante'}), } nombre = forms.RegexField(label=_("Nombre"), max_length=70, regex=r'', help_text=_(" " ""), error_messages={ 'invalid': _("This value may contain only letters, numbers and " "@/./+/-/_ characters.")}) def clean(self): return self.cleaned_data class RegistroOrganizador(ModelForm): class Meta: model = cat_personas fields = ('nombre',) widgets = { 'nombre': TextInput(attrs={'placeholder': 'Escriba el nombre completo del participante'}), } nombre = forms.RegexField(label=_("Nombre"), max_length=70, regex=r'', help_text=_(" " ""), error_messages={ 'invalid': _("This value may contain only letters, numbers and " "@/./+/-/_ characters.")}) def clean(self): return self.cleaned_data class RegistroPatrosinador(ModelForm): class Meta: model = cat_personas fields = ('nombre',) widgets = { 'nombre': TextInput(attrs={'placeholder': 'Escriba el nombre completo del participante'}), } nombre = forms.RegexField(label=_("Nombre"), max_length=70, regex=r'', help_text=_(" " ""), error_messages={ 'invalid': _("This value may contain only letters, numbers and " "@/./+/-/_ characters.")}) def clean(self): return self.cleaned_data class Permisos2Form(forms.ModelForm): error_messages = { 'duplicate_username': ("Ya existe un usuario con ese nombre de usuario."), 'password_mismatch': ("las dos contraseñas no coinciden."), } username = forms.RegexField(label=("Usuario") ,max_length=30, regex=r'^[\w.@+-]+$', help_text=("Necesario. 30 caracteres o menos. Letras, digitos y " "@/./+/-/_ solamente."), error_messages={ 'invalid': (" Este valor solo debe contener letras, numeros y los caracteres" "@/./+/-/_ ")} ,widget = forms.TextInput(attrs={'class':'required usernameField span3'}) ) password1 = forms.CharField(label=("Contraseña"), widget=forms.PasswordInput(attrs={'class':'required span3'})) password2 = forms.CharField(label=("Confirmación de contraseña"), widget=forms.PasswordInput(attrs={'class':'required span3'}), help_text=("Entre la misma contraseña del campo anterior, para verificación.")) class Meta: model = User fields = ("username","first_name","last_name",) def clean_password2(self): password1 = self.cleaned_data.get("password1") password2 = self.cleaned_data.get("password2") if password1 and password2 and password1 != password2: raise forms.ValidationError( self.error_messages['password_mismatch']) return password2 def save(self, commit=True): user = super(Permisos2Form, self).save(commit=False) user.set_password(self.cleaned_data["password1"]) if commit: user.save() return user class EditarResponsableForm(forms.Form): nombre_responsable = forms.CharField(label="Nombre del Responsable", max_length=70, widget = forms.TextInput(attrs={'class':'required span6'})) telefono_responsable = forms.CharField(label="Teléfono del Responsable", max_length=15, widget = forms.TextInput(attrs={'class':'required digits span6'})) extencion_responsable = forms.CharField(label="Extensión del Responable", max_length=6, required=False, widget = forms.TextInput(attrs={'class':'number span6'})) celular = forms.CharField(max_length=15, required=False, widget = forms.TextInput(attrs={'class':'digits span6'})) correo_responsable = forms.EmailField(label="Correo", max_length=100, widget = forms.TextInput(attrs={'class':'required email span6'})) class CorreoForm(forms.Form): correo = forms.EmailField(label="Correo", max_length=100, widget = forms.TextInput(attrs={'class':'required email span6'}))