#encoding:utf-8 #from tkinter import MULTIPLE from django import forms from django.forms import ModelForm from bienes.models import * from django.db import models from django.forms.extras.widgets import * from django.contrib.admin import widgets from django.contrib.auth.models import Group, User import datetime class AutoridadForm(forms.ModelForm): class Meta: model = Autoridad class PersonaForm(forms.ModelForm): class Meta: exclude = ('estatus',) model = Persona class CalidadBienForm(forms.ModelForm): class Meta: model = CalidadBien class TipoBienForm(forms.ModelForm): class Meta: model = TipoBien class FotosBienesForm(forms.ModelForm): class Meta: model = FotosBienes class BienesForm(forms.ModelForm): no_inventario = forms.CharField(label="Número de Inventario", required=True, widget=forms.TextInput(attrs={"class":"span2"})) class Meta: model = Bienes exclude = ('oficio','estatus','fecha_devolucion', 'devuelto') widgets = { 'descripcion' : forms.Textarea(attrs={"class":"span6"}), 'observaciones' : forms.Textarea(attrs={"class":"span6"}), 'diligencias' : forms.Textarea(attrs={"class":"span6"}), #'foto': forms.FileInput(attrs={"class":"span6","id":"id_multiple","multiple":"True"}) } # fields = ('calidad_bien','tipo_bien','enlace','descripcion','situacion_juridica','observaciones','fecha_devolucion','devuelto','diligencias','foto') class OficioForm(forms.ModelForm): numero_averiguacion = forms.CharField(required=False) autoridad = forms.ModelChoiceField(label='Autoridad:',queryset=Autoridad.objects.all(),required=False), persona_entrega = forms.ModelChoiceField(label='Persona que Entrega:',queryset= Persona.objects.filter(estatus= True), empty_label="Seleccione una Persona", required=False) class Meta: model = Oficios widgets = { 'numero_oficio': forms.TextInput(attrs={"class": "required span2"}), 'identificacion': forms.Textarea(attrs={"class": "span4"}) } class RecepcionForm(forms.ModelForm): envia = forms.ModelChoiceField(queryset=Persona.objects.filter(estatus= True),label='Persona que envía') recibe = forms.ModelChoiceField(queryset=Persona.objects.filter(estatus= True),label='Persona que recibe') capturo = forms.ModelChoiceField(queryset=Persona.objects.filter(estatus= True),label='Persona que capturó') reviso = forms.ModelChoiceField(queryset=Persona.objects.filter(estatus= True),label='Persona que revisó') class Meta: model = Recepcion exclude = ('bien','estatus',) widgets ={ 'numero_acta': forms.TextInput(attrs={"class":"required span8"}), 'fecha': forms.TextInput(attrs={"class":"required span8"}), 'hora': forms.TextInput(attrs={"class":"required span8"}), 'expedienteacta': forms.Select(attrs={"class":"required span8"}), 'envia': forms.Select(attrs={"class":"required span12"}), 'recibe': forms.Select(attrs={"class":"required span12"}), 'capturo': forms.Select(attrs={"class":"required span12"}), 'reviso': forms.Select(attrs={"class":"required span12"}), 'testigo1': forms.TextInput(attrs={"class":"required span8"}), 'testigo2': forms.TextInput(attrs={"class":"required span8"}) } def __init__(self, *args, **kwargs): super(RecepcionForm, self).__init__(*args, **kwargs) self.fields['envia'].label_from_instance = self.label_from_instance self.fields['recibe'].label_from_instance = self.label_from_instance self.fields['capturo'].label_from_instance = self.label_from_instance self.fields['reviso'].label_from_instance = self.label_from_instance @staticmethod def label_from_instance(obj): return "{0} {1} {2} - {3}".format(obj.nombre.encode('utf-8'),obj.apellidopaterno.encode('utf-8'),obj.apellidomaterno.encode('utf-8'),obj.cargo.encode('utf-8')) class DevolucionForm(forms.ModelForm): # bien = forms.ModelChoiceField(queryset=Bienes.objects.all().values_list('descripcion')) class Meta: model = Devolucion exclude = ('estatus', 'director',) widgets ={ 'recepcion': forms.Select(attrs={"class":"span8"}), 'numero_acta' : forms.TextInput(attrs={"class":"span8"}), 'propietario' : forms.TextInput(attrs={"class":"span8"}), 'numero_oficio' : forms.TextInput(attrs={"class":"span8"}), 'fecha_oficio' : forms.TextInput(attrs={"class":"span8"}), 'folio' : forms.TextInput(attrs={"class":"span8"}), 'horacierre' : forms.TextInput(attrs={"class":"span8"}), 'numero_expedienteacta' : forms.TextInput(attrs={"class":"span8"}), 'fecha_recepcion_oficio' : forms.TextInput(attrs={"class":"span8"}), 'tipopropietario' : forms.Select(attrs={"class":"span5"}), 'expedienteacta' : forms.Select(attrs={"class":"span5"}), 'fechahora' : forms.Textarea(attrs={"class":"span12"}), 'observaciones' : forms.Textarea(attrs={"class":"span12"}), 'cantidad' : forms.Textarea(attrs={"class":"span12"}), 'identificacion' : forms.Textarea(attrs={"class":"span12"}), 'testigo1': forms.TextInput(attrs={"class":"required span12"}), 'testigo2': forms.TextInput(attrs={"class":"required span12"}), 'reviso': forms.Select(attrs={"class":"required span12"}), } def __init__(self, *args, **kwargs): super(DevolucionForm, self).__init__(*args, **kwargs) self.fields['signado'].label_from_instance = self.label_from_instance self.fields['autoriza'].label_from_instance = self.label_from_instance self.fields['capturo'].label_from_instance = self.label_from_instance self.fields['reviso'].label_from_instance = self.label_from_instance @staticmethod def label_from_instance(obj): return "{0} {1} {2} - {3}".format(obj.nombre.encode('utf-8'), obj.apellidopaterno.encode('utf-8'), obj.apellidomaterno.encode('utf-8'), obj.cargo.encode('utf-8')) class DireccionForm(forms.ModelForm): texto = forms.CharField(label='Dirección', widget=(forms.TextInput(attrs={'class':'required span10'}))) class Meta: model = Enlace widgets ={ # 'texto': forms.TextInput(attrs={'class':'required span10'}), 'tipo_bien': forms.Select(attrs={'class':'required span10'}) } class UsuarioForm(forms.ModelForm): # error_messages = { # 'duplicate_username':("El usuario ya existe. Debe ingresar otro usuario"), # } group = forms.ModelChoiceField(label="Rol", empty_label="Seleccione un rol:", queryset=Group.objects.all(), widget= forms.Select(attrs={"class":"span8"})) username = forms.CharField(label="Nombre Usuario", widget= forms.TextInput(attrs={"class":"span8"})) first_name = forms.CharField(label="Nombre(s)", widget= forms.TextInput(attrs={"class":"span8"})) last_name = forms.CharField(label="Apellidos", widget= forms.TextInput(attrs={"class":"span8"})) password1 = forms.CharField(label="Contraseña", widget = forms.PasswordInput(attrs={"class":"span8"})) password2 = forms.CharField(label="Confirmar Contraseña", widget = forms.PasswordInput(attrs={"class":"span8"})) class Meta: model = User fields =[ 'group', 'username', 'first_name', 'last_name', 'password1', 'password2', ] def clean_username(self): username = self.cleaned_data["username"] try: User._default_manager.get(username=username) except User.DoesNotExist: return username raise forms.ValidationError("El Usuario ya existe.") def clean_password2(self): # Check that the two password entries match password1 = self.cleaned_data.get("password1") password2 = self.cleaned_data.get("password2") if len(password1 and password2) < 8: raise forms.ValidationError("La contraseña es muy corta.") if password1 and password2 and password1 != password2: raise forms.ValidationError("Las contraseñas son diferentes.") return password2 def save(self, commit=True): # Save the provided password in hashed format user = super(UsuarioForm, self).save(commit=False) user.set_password(self.cleaned_data["password1"]) if commit: user.save() return user class UpdateUsuario(forms.ModelForm): username = forms.CharField(label="Nombre Usuario", widget= forms.TextInput(attrs={"class":"span8"})) first_name = forms.CharField(label="Nombre(s)", widget= forms.TextInput(attrs={"class":"span8"})) last_name = forms.CharField(label="Apellidos", widget= forms.TextInput(attrs={"class":"span8"})) class Meta: model = User fields =[ 'username', 'first_name', 'last_name', ] class FiltroForm(forms.Form): fecha_de = forms.DateField(widget=(forms.DateInput(format=('%dd-%mm-%Y'), attrs={'class': 'required myDateClass', 'placeholder': 'Selecione una Fecha'})), required=True ) fecha_a = forms.DateField(widget=(forms.DateInput(format=('%dd-%mm-%Y'), attrs={'class': 'required myDateClass', 'placeholder': 'Selecione una Fecha'})), required=True ) # cantidad = forms.IntegerField(initial=10, label="Cantidad de Resultados" ) class EditarRecepcionForm(forms.ModelForm): class Meta: model = Recepcion exclude = ('oficio','bien','estatus',) widgets ={ 'numero_acta': forms.TextInput(attrs={"class":"required span8"}), 'fecha': forms.TextInput(attrs={"class":"required span8"}), 'hora': forms.TextInput(attrs={"class":"required span8"}), 'expedienteacta': forms.Select(attrs={"class":"required span8"}), 'envia': forms.Select(attrs={"class":"required span8"}), 'recibe': forms.Select(attrs={"class":"required span8"}), 'capturo': forms.Select(attrs={"class":"required span8"}), 'reviso': forms.Select(attrs={"class":"required span8"}), 'testigo1': forms.TextInput(attrs={"class":"required span8"}), 'testigo2': forms.TextInput(attrs={"class":"required span8"}) } def __init__(self, *args, **kwargs): super(EditarRecepcionForm, self).__init__(*args, **kwargs) self.fields['envia'].label_from_instance = self.label_from_instance self.fields['recibe'].label_from_instance = self.label_from_instance self.fields['capturo'].label_from_instance = self.label_from_instance self.fields['reviso'].label_from_instance = self.label_from_instance @staticmethod def label_from_instance(obj): return "{0} {1} {2} - {3}".format(obj.nombre.encode('utf-8'),obj.apellidopaterno.encode('utf-8'),obj.apellidomaterno.encode('utf-8'),obj.cargo.encode('utf-8')) class EditarDevolucionForm(forms.ModelForm): class Meta: # bien = forms.ModelChoiceField(label='Autoridad:',queryset=Bienes.objects.filter(devolucion__pk=self.pk)), model = Devolucion # exclude = ('recepcion',) exclude = ('estatus','director',) widgets ={ 'recepcion': forms.Select(attrs={"class":"span8"}), 'bien': forms.Select(attrs={"class":"span12"}), 'numero_acta' : forms.TextInput(attrs={"class":"span8"}), 'propietario' : forms.TextInput(attrs={"class":"span8"}), 'numero_oficio' : forms.TextInput(attrs={"class":"span8"}), 'fecha_oficio' : forms.TextInput(attrs={"class":"span8"}), 'folio' : forms.TextInput(attrs={"class":"span8"}), 'horacierre' : forms.TextInput(attrs={"class":"span8"}), 'numero_expedienteacta' : forms.TextInput(attrs={"class":"span8"}), 'fecha_recepcion_oficio' : forms.TextInput(attrs={"class":"span8"}), 'tipopropietario' : forms.Select(attrs={"class":"span5"}), 'expedienteacta' : forms.Select(attrs={"class":"span5"}), 'fechahora' : forms.Textarea(attrs={"class":"span12"}), 'observaciones' : forms.Textarea(attrs={"class":"span12"}), 'cantidad' : forms.Textarea(attrs={"class":"span12"}), 'identificacion' : forms.Textarea(attrs={"class":"span12"}), 'testigo1': forms.TextInput(attrs={"class":"required span12"}), 'testigo2': forms.TextInput(attrs={"class":"required span12"}), 'reviso': forms.Select(attrs={"class":"required span12"}), } def __init__(self, *args, **kwargs): super(EditarDevolucionForm, self).__init__(*args, **kwargs) self.fields['signado'].label_from_instance = self.label_from_instance self.fields['autoriza'].label_from_instance = self.label_from_instance self.fields['capturo'].label_from_instance = self.label_from_instance self.fields['reviso'].label_from_instance = self.label_from_instance @staticmethod def label_from_instance(obj): return "{0} {1} {2} - {3}".format(obj.nombre.encode('utf-8'), obj.apellidopaterno.encode('utf-8'), obj.apellidomaterno.encode('utf-8'), obj.cargo.encode('utf-8')) class DirectorForm(forms.ModelForm): class Meta: model = Director exclude = ('fecha_baja','estatus') widgets = { 'titulo': forms.TextInput(attrs={"class": "required span4"}), 'nombre': forms.TextInput(attrs={"class": "required span4"}), 'apellidopaterno': forms.TextInput(attrs={"class": "required span4"}), 'apellidomaterno': forms.TextInput(attrs={"class": "required span4"}), 'cargo': forms.TextInput(attrs={"class": "required span4"}), 'fecha_nombramiento': forms.DateInput(format=('%Y-%m-%d'), attrs={'class': 'myDateClass', 'placeholder': 'Selecione una Fecha'}), } class EditarDirectorForm(forms.ModelForm): class Meta: model = Director exclude = ('estatus','fecha_nombramiento','fecha_baja') widgets = { 'titulo': forms.TextInput(attrs={"class": "required span4"}), 'nombre': forms.TextInput(attrs={"class": "required span4"}), 'apellidopaterno': forms.TextInput(attrs={"class": "required span4"}), 'apellidomaterno': forms.TextInput(attrs={"class": "required span4"}), 'cargo': forms.TextInput(attrs={"class": "required span4"}), # 'fecha_nombramiento': forms.DateInput(format=('%Y-%m-%d'),attrs={'class':'myDateClass','placeholder':'Selecione una Fecha'}), # 'fecha_baja': forms.DateInput(format=('%Y-%m-%d'),attrs={'class':'myDateClass','placeholder':'Selecione una Fecha'}) } class EditarDirectorFormActivo(forms.ModelForm): class Meta: model = Director exclude = ('estatus','fecha_baja') widgets = { 'titulo': forms.TextInput(attrs={"class": "required span4"}), 'nombre': forms.TextInput(attrs={"class": "required span4"}), 'apellidopaterno': forms.TextInput(attrs={"class": "required span4"}), 'apellidomaterno': forms.TextInput(attrs={"class": "required span4"}), 'cargo': forms.TextInput(attrs={"class": "required span4"}), 'fecha_nombramiento': forms.DateInput(format=('%Y-%m-%d'),attrs={'class':'myDateClass span4','placeholder':'Selecione una Fecha'}), # 'fecha_baja': forms.DateInput(format=('%Y-%m-%d'),attrs={'class':'myDateClass','placeholder':'Selecione una Fecha'}) } class BajaDirectorForm(forms.ModelForm): fecha_baja = forms.DateField(widget=(forms.DateInput(format=('%Y-%m-%d'), attrs={'class': 'required myDateClass', 'placeholder': 'Selecione una Fecha'})), required=True ) class Meta: model = Director exclude = ('titulo','nombre','apellidopaterno','apellidomaterno','fecha_nombramiento','cargo','estatus') class validarfirmaForm(forms.ModelForm): envia = forms.ModelChoiceField(queryset=Persona.objects.filter(estatus= True),label='Persona que envía') recibe = forms.ModelChoiceField(queryset=Persona.objects.filter(estatus= True),label='Persona que recibe') capturo = forms.ModelChoiceField(queryset=Persona.objects.filter(estatus= True),label='Persona que capturó') reviso = forms.ModelChoiceField(queryset=Persona.objects.filter(estatus= True),label='Persona que revisó') class Meta: model = Recepcion exclude = ('oficio','bien','numero_acta','fecha','hora','expedienteacta','fechaoficio','testigo1','testigo2','estatus') widgets = { 'envia': forms.Select(attrs={"class": "required span12"}), 'recibe': forms.Select(attrs={"class": "required span12"}), 'capturo': forms.Select(attrs={"class": "required span12"}), 'reviso': forms.Select(attrs={"class": "required span12"}) } def __init__(self, *args, **kwargs): super(validarfirmaForm, self).__init__(*args, **kwargs) self.fields['envia'].label_from_instance = self.label_from_instance self.fields['recibe'].label_from_instance = self.label_from_instance self.fields['capturo'].label_from_instance = self.label_from_instance self.fields['reviso'].label_from_instance = self.label_from_instance @staticmethod def label_from_instance(obj): return "{0} {1} {2} - {3}".format(obj.nombre.encode('utf-8'), obj.apellidopaterno.encode('utf-8'), obj.apellidomaterno.encode('utf-8'), obj.cargo.encode('utf-8'))