def mandate_save(request): mandate_id = request.POST.get("mandate_id") mandate = assistant_mdl.assistant_mandate.find_mandate_by_id(mandate_id) if request.POST.get('del_rev'): mandate.assistant.supervisor = None mandate.assistant.save() elif request.POST.get('person_id'): try: substitute_supervisor = person.find_by_id(request.POST.get('person_id')) if substitute_supervisor: mandate.assistant.supervisor = substitute_supervisor mandate.assistant.save() html_template_ref = 'assistant_phd_supervisor_html' txt_template_ref = 'assistant_phd_supervisor_txt' send_message(person=substitute_supervisor, html_template_ref=html_template_ref, txt_template_ref=txt_template_ref, assistant=mandate.assistant) except ObjectDoesNotExist: pass form = MandateForm(data=request.POST, instance=mandate, prefix='mand') formset = entity_inline_formset(request.POST, request.FILES, instance=mandate, prefix='entity') if form.is_valid(): form.save() if formset.is_valid(): formset.save() return mandate_edit(request) else: return layout.render(request, "mandate_form.html", {'mandate': mandate, 'form': form, 'formset': formset}) else: return layout.render(request, "mandate_form.html", {'mandate': mandate, 'form': form, 'formset': formset})
def mandate_edit(request): mandate_id = request.POST.get("mandate_id") mandate = assistant_mdl.assistant_mandate.find_mandate_by_id(mandate_id) supervisor = mandate.assistant.supervisor form = MandateForm(initial={'comment': mandate.comment, 'renewal_type': mandate.renewal_type, 'absences': mandate.absences, 'other_status': mandate.other_status, 'contract_duration': mandate.contract_duration, 'contract_duration_fte': mandate.contract_duration_fte }, prefix="mand", instance=mandate) formset = entity_inline_formset(instance=mandate, prefix="entity") return layout.render(request, 'mandate_form.html', {'mandate': mandate, 'form': form, 'formset': formset, 'assistant_mandate_state': assistant_mandate_state, 'supervisor': supervisor})