def form_valid(self, formset, context, add_modif, act_ids): """ Called if all forms are valid. """ print "form_valid" #save validated ministers' attendances (MinAttend model) #~ instances = formset.save() for form in formset.forms: #if the form is not to be deleted if form not in formset.deleted_forms: #if the form has been changed if form.has_changed(): #update status in ImportMinAttend with same verbatim and empty status instances=ImportMinAttend.objects.filter(verbatim=form.cleaned_data["verbatim"], country=Country.objects.get(country_code=form.cleaned_data["country"]).country, status=None) for instance in instances: print "instance ImportMinAttend", instance.pk instance.status=form.cleaned_data["status"] instance.save() #add releve_ids and no_celex for extra forms not already in ImportMinAttend and save extra forms if form.empty_permitted: form.save(no_celex=act_ids.no_celex, releve_annee=act_ids.act.releve_annee, releve_mois=act_ids.act.releve_mois, no_ordre=act_ids.act.no_ordre) #save all the "normal" forms, even unchanged if not form.empty_permitted: form.save() #forms to be deleted else: ImportMinAttend.objects.get(id=form.instance.pk).delete() #validate the attendances of the act act_ids.act.validated_attendance=1 act_ids.act.save() #update dictionary (Verbatim and status models) and save attendances in MinAttend save_get_min_attend(act_ids) context["state"]="saved" context["msg"]="The act " + str(act_ids.act) + " has been validated!" context["msg_class"]="success_msg" #save in history History.objects.create(action=add_modif, form="attendance", act=act_ids.act, user=self.request.user) #empty forms context['add'] = Add() context['modif'] = Modif() return context
def handle(self, **options): #FIXME #pb duplicates: the following acts cause errors for ministers attendances -> these errors must be fixes # ReleveAnnee=2008, ReleveMois=3, NoOrdre=31 # ReleveAnnee=2008, ReleveMois=3, NoOrdre=33 # ReleveAnnee=2008, ReleveMois=7, NoOrdre=8 # ReleveAnnee=2008, ReleveMois=7, NoOrdre=9 # ReleveAnnee=2008, ReleveMois=7, NoOrdre=11 #~ #update min_attend for validated acts act_ids=ActIds.objects.filter(src="index", act__validated=2).exclude(act__releve_annee=2008, act__releve_mois=3, act__no_ordre=31).exclude(act__releve_annee=2008, act__releve_mois=3, act__no_ordre=33).exclude(act__releve_annee=2008, act__releve_mois=7, act__no_ordre=8).exclude(act__releve_annee=2008, act__releve_mois=7, act__no_ordre=9).exclude(act__releve_annee=2008, act__releve_mois=7, act__no_ordre=11) #~ act_ids=ActIds.objects.filter(src="index", act__validated=2).exclude(act__releve_annee=2008, act__releve_mois=3, act__no_ordre=31).exclude(act__releve_annee=2008, act__releve_mois=3, act__no_ordre=33) for act_id in act_ids: print act_id.act save_get_min_attend(act_id)