class tutorsForm(forms.Form): grup = forms.CharField(widget=forms.TextInput(attrs={'readonly': True})) tutor1 = ModelChoiceField(widget=ModelSelect2Widget( queryset=Professor.objects.all(), search_fields=( 'last_name__icontains', 'first_name__icontains', ), attrs={'style': "'width': '100%'"}), queryset=Professor.objects.all(), required=False) tutor2 = ModelChoiceField(widget=ModelSelect2Widget( queryset=Professor.objects.all(), search_fields=( 'last_name__icontains', 'first_name__icontains', ), attrs={'style': "'width': '100%'"}), queryset=Professor.objects.all(), required=False) tutor3 = ModelChoiceField(widget=ModelSelect2Widget( queryset=Professor.objects.all(), search_fields=( 'last_name__icontains', 'first_name__icontains', ), attrs={'style': "'width': '100%'"}), queryset=Professor.objects.all(), required=False)
class triaAlumneSelect2Form(forms.Form): alumne = ModelChoiceField( widget=ModelSelect2Widget( queryset=AlumneGrup.objects.all(), search_fields = ['cognoms__icontains','nom__icontains', 'grup__descripcio_grup__icontains' ], attrs={'style':"'width': '100%'"} ), queryset=AlumneGrup.objects.all(), required=True)
class triaUsuariForm(forms.Form): professor = forms.ModelChoiceField( queryset=Professor.objects.all(), required=True, help_text=u'Tria en quin usuari et vols convertir.', widget=ModelSelect2Widget( queryset=Professor.objects.all(), search_fields=['last_name__icontains', 'first_name__icontains'], attrs={'style': "'width': '100%'"}), )
class triaProfessorSelect2Form(forms.Form): professor = ModelChoiceField(widget=ModelSelect2Widget( queryset=Professor.objects.all(), search_fields=( 'last_name__icontains', 'first_name__icontains', ), attrs={'style': "'width': '100%'"}), queryset=Professor.objects.all(), required=True)
class complementFormulariTriaForm(forms.Form): dia = forms.DateField(label=u'Data Baixa', initial=datetime.today(), required=True, help_text=u'Data de la baixa', widget=DateTextImput()) professor = ModelChoiceField(widget=ModelSelect2Widget( queryset=Professor.objects.all(), search_fields=( 'last_name__icontains', 'first_name__icontains', ), attrs={'style': "'width': '100%'"}), queryset=Professor.objects.all(), required=True)
class Meta: model = Expulsio fields = ( 'professor', ) widgets = { 'professor':ModelSelect2Widget( queryset=Professor.objects.all(), search_fields=('last_name__icontains', 'first_name__icontains',), attrs={'style': "'width': '100%'"} ) }
class disponibilitatAulaPerAulaForm(forms.Form): aula = ModelChoiceField(widget=ModelSelect2Widget( queryset=Aula.objects.filter(reservable=True), search_fields=['nom_aula__icontains', 'descripcio_aula__icontains'], attrs={'style': "'width': '100%'"}, ), queryset=Aula.objects.all(), required=True, help_text="Aula a consultar") data = forms.DateField(help_text="Data a consultar", initial=datetime.today(), required=True, widget=DateTextImput())
class afegeixGuardiaForm(forms.Form): professor = ModelChoiceField( widget=ModelSelect2Widget(queryset=Professor.objects.all(), search_fields=( 'last_name__icontains', 'first_name__icontains', ), attrs={'style': "'width': '100%'"}), queryset=Professor.objects.all(), required=True, help_text=u'Tria a quin professor fas la guardia.') franges = forms.ModelMultipleChoiceField( queryset=FranjaHoraria.objects.all(), required=True, help_text=u'Tria en quines franges horàries fas guardia.', )
class reservaAulaForm(ModelForm): mou_alumnes= forms.ChoiceField( label=u"És un canvi d'aula?", help_text= """Pots fer un canvi d'aula o bé pots fer una nova reserva. Canvi d'aula vol dir que deixes lliure la teva aula i portes els alumnes a l'aula que estàs reservant.""", initial="C", required=True, choices=[('C',u"Canvi d'aula"),('N','Nova reserva')], widget=forms.RadioSelect()) aula = ModelChoiceField( widget=ModelSelect2Widget( queryset=Aula.objects.all(), search_fields = ['nom_aula__icontains','descripcio_aula__icontains' ], attrs={'style':"'width': '100%'"}, ), queryset=Aula.objects.all(), required=True, help_text="Aula a reservar") def clean_hora(self): franja = self.cleaned_data['hora'] data = self.cleaned_data['dia_reserva'] franges_del_dia = (FranjaHoraria .objects .filter(horari__impartir__dia_impartir=data) .order_by('hora_inici') ) primera_franja = franges_del_dia.first() darrera_franja = franges_del_dia.last() if franja.hora_inici < primera_franja.hora_inici or franja.hora_fi > darrera_franja.hora_fi: raise forms.ValidationError(u"En aquesta franja i dia no hi ha docència") return franja class Meta: model = ReservaAula labels = { "motiu": "Propòsit" } fields = ['aula','dia_reserva','hora','motiu'] widgets = { 'motiu': forms.Textarea, 'dia_reserva' : DateTextImput() }
class reservaMassivaRecursForm(ModelForm): def __init__(self, *args, **kwargs): super(reservaMassivaRecursForm, self).__init__(*args, **kwargs) self.fields['hora'].disabled = True self.fields['recurs'].disabled = True self.fields["usuari"].queryset = Professor.objects.all() recurs = ModelChoiceField( widget=ModelSelect2Widget( queryset=Recurs.objects.all(), search_fields = ['nom_recurs__icontains','descripcio_recurs__icontains' ], attrs={'style':"'width': '100%'"}, ), queryset=Recurs.objects.all(), required=True, help_text="Material a reservar",) usuari = triaProfessorSelect2Form() def clean_hora(self): franja = self.cleaned_data['hora'] data = self.cleaned_data['dia_reserva'] franges_del_dia = (FranjaHoraria .objects .filter(horari__impartir__dia_impartir=data) .order_by('hora_inici') ) primera_franja = franges_del_dia.first() darrera_franja = franges_del_dia.last() if franja.hora_inici < primera_franja.hora_inici or franja.hora_fi > darrera_franja.hora_fi: raise forms.ValidationError(u"En aquesta franja i dia no hi ha docència") return franja class Meta: model = ReservaRecurs labels = { "motiu": "Propòsit" } fields = ['recurs', 'dia_reserva', 'hora', 'motiu', 'usuari'] widgets = { 'motiu': forms.Textarea, 'dia_reserva': forms.HiddenInput }
class reservaRecursForm(ModelForm): recurs = ModelChoiceField( widget=ModelSelect2Widget( queryset=Recurs.objects.all(), search_fields = ['nom_recurs__icontains','descripcio_recurs__icontains' ], attrs={'style':"'width': '100%'"}, ), queryset=Recurs.objects.all(), required=True, help_text="Material a reservar") def clean_hora(self): franja = self.cleaned_data['hora'] data = self.cleaned_data['dia_reserva'] franges_del_dia = (FranjaHoraria .objects .filter(horari__impartir__dia_impartir=data) .order_by('hora_inici') ) primera_franja = franges_del_dia.first() darrera_franja = franges_del_dia.last() if franja.hora_inici < primera_franja.hora_inici or franja.hora_fi > darrera_franja.hora_fi: raise forms.ValidationError(u"En aquesta franja i dia no hi ha docència") return franja class Meta: model = ReservaRecurs labels = { "motiu": "Propòsit" } fields = ['recurs','dia_reserva','hora','motiu'] widgets = { 'motiu': forms.Textarea, 'dia_reserva' : DateTextImput() }
def complementFormulariOmple(request, pk_professor, dia, mes, year): credentials = tools.getImpersonateUser(request) (user, _) = credentials professor = User2Professor(user) data = date(int(year), int(mes), int(dia)) head = u"Feina professor absent {0} {1}".format(professor, data) imparticions = Impartir.objects.filter(dia_impartir=data, horari__professor__pk=pk_professor) formsetFac = modelformset_factory( model=Feina, extra=0, can_delete=False, fields=( 'professor_fa_guardia', 'feina_a_fer', 'comentaris_per_al_professor_guardia', ), widgets={ 'professor_fa_guardia': ModelSelect2Widget(queryset=Professor.objects.all(), search_fields=( 'last_name__icontains', 'first_name__icontains', ), attrs={'style': "'width': '100%'"}) }) if request.method == "POST": formset = formsetFac( request.POST, queryset=Feina.objects.filter(impartir__in=imparticions)) if formset.is_valid(): formset.save() for form in formset: if (form.instance.professor_fa_guardia): form.instance.impartir.professor_guardia = form.instance.professor_fa_guardia form.instance.impartir.save() return HttpResponseRedirect(r'/') else: #crear els que no existeixin: for i in imparticions: feina, _ = Feina.objects.get_or_create( impartir=i, defaults={ 'professor_darrera_modificacio': professor, }) if bool(i.professor_guardia): feina.professor_fa_guardia = i.professor_guardia feina.save() formset = formsetFac(queryset=Feina.objects.filter( impartir__in=imparticions)) for form in formset: instance = form.instance form.formSetDelimited = True guardies = Impartir.objects.filter( horari__assignatura__nom_assignatura='G', horari__hora=instance.impartir.horari.hora, dia_impartir=instance.impartir.dia_impartir).distinct() form.infoForm = ((u'Hora', instance.impartir.horari.hora), (u'Assignatura', instance.impartir.horari.assignatura), (u'Grup', instance.impartir.horari.grup), (u'Aula', instance.impartir.horari.nom_aula), (u'Professors de Guardia', u', '.join([ unicode(p) for p in Professor.objects.filter( horari__impartir__in=guardies).distinct() ]))) return render( request, 'formset.html', { 'formset': formset, 'head': head }, )