def gestionaAlumnesTutor( request , pk ): credentials = tools.getImpersonateUser(request) (user, _ ) = credentials professor = Professor.objects.get( pk = int(pk) ) head=u'Tutors Individualitzats' infoForm = [] formset = [] if request.method == 'POST': totBe = True nous_alumnes_tutor = [] for grup in Grup.objects.filter( alumne__isnull = False ).distinct(): #http://www.ibm.com/developerworks/opensource/library/os-django-models/index.html?S_TACT=105AGX44&S_CMP=EDU form=triaMultiplesAlumnesForm( request.POST, prefix=str( grup.pk ), queryset = grup.alumne_set.all() , etiqueta = unicode( grup ) ) formset.append( form ) if form.is_valid(): for alumne in form.cleaned_data['alumnes']: nous_alumnes_tutor.append( alumne ) else: totBe = False if totBe: professor.tutorindividualitzat_set.all().delete() for alumne in nous_alumnes_tutor: ti = TutorIndividualitzat( professor = professor, alumne = alumne ) ti.credentials = credentials ti.save() return HttpResponseRedirect( '/alumnes/llistaTutorsIndividualitzats/' ) else: for grup in Grup.objects.filter( alumne__isnull = False ).distinct(): #http://www.ibm.com/developerworks/opensource/library/os-django-models/index.html?S_TACT=105AGX44&S_CMP=EDU inicial= [c.pk for c in grup.alumne_set.filter( tutorindividualitzat__professor = professor ) ] form=triaMultiplesAlumnesForm( prefix=str( grup.pk ), queryset = grup.alumne_set.all() , etiqueta = unicode( grup ) , initial = {'alumnes': inicial } ) formset.append( form ) return render( request, "formset.html", {"formset": formset, "head": head, "formSetDelimited": True, } )
def gestionaAlumnesTutor( request , pk ): credentials = tools.getImpersonateUser(request) (user, _ ) = credentials professor = Professor.objects.get( pk = int(pk) ) head=u'Tutors Individualitzats' infoForm = [] formset = [] if request.method == 'POST': totBe = True nous_alumnes_tutor = [] for grup in Grup.objects.filter( alumne__isnull = False ).distinct().order_by('descripcio_grup'): #http://www.ibm.com/developerworks/opensource/library/os-django-models/index.html?S_TACT=105AGX44&S_CMP=EDU form=triaMultiplesAlumnesForm( request.POST, prefix=str( grup.pk ), queryset = grup.alumne_set.all() , etiqueta = unicode( grup ) ) formset.append( form ) if form.is_valid(): for alumne in form.cleaned_data['alumnes']: nous_alumnes_tutor.append( alumne ) else: totBe = False if totBe: professor.tutorindividualitzat_set.all().delete() for alumne in nous_alumnes_tutor: ti = TutorIndividualitzat( professor = professor, alumne = alumne ) ti.credentials = credentials ti.save() return HttpResponseRedirect( '/alumnes/llistaTutorsIndividualitzats/' ) else: for grup in Grup.objects.filter( alumne__isnull = False ).distinct().order_by('descripcio_grup'): #http://www.ibm.com/developerworks/opensource/library/os-django-models/index.html?S_TACT=105AGX44&S_CMP=EDU inicial= [c.pk for c in grup.alumne_set.filter( tutorindividualitzat__professor = professor ) ] form=triaMultiplesAlumnesForm( prefix=str( grup.pk ), queryset = grup.alumne_set.all() , etiqueta = unicode( grup ) , initial = {'alumnes': inicial } ) formset.append( form ) return render( request, "formset.html", {"formset": formset, "head": head, "formSetDelimited": True, } )