def save_from_form(expedient_form): expedient = Expedient() # If id is present, get the DB person and edit expedient_id = expedient_form.cleaned_data['id'] if expedient_id: expedient = Expedient.objects.get(id=expedient_id) expedient.id = expedient_form.cleaned_data['expedient_num'] expedient.description = expedient_form.cleaned_data['description'] form_creation_date = expedient_form.cleaned_data['creation_date'] form_end_date = expedient_form.cleaned_data['end_date'] or None expedient.creation_date = DateUtils.convert_date_to_datetime(form_creation_date) expedient.end_date = DateUtils.convert_date_to_datetime(form_end_date) expedient.attendant = expedient_form.cleaned_data['attendant'] form_phase = expedient_form.cleaned_data['phase'] expedient.phase = Phase.objects.get(id=form_phase) if form_phase else None expedient.state = expedient_form.cleaned_data['state'] expedient.headquarters = expedient_form.cleaned_data['headquarters'] expedient.save() # Save ExpPerRol entities save_exps(expedient_form, expedient)
def save_from_form(person_form): person = Person() # If id is present, get the DB person and edit person_id = person_form.cleaned_data['id'] if person_id: person = Person.objects.get(id=person_id) person.name = person_form.cleaned_data['name'] person.id_number = person_form.cleaned_data['id_number'] person.email = person_form.cleaned_data['email'] person.web = person_form.cleaned_data['web'] person.nationality = person_form.cleaned_data['nationality'] # Set the creation date -> we need to convert it into a datetime form_creation_date = person_form.cleaned_data['creation_date'] person.creation_date = DateUtils.convert_date_to_datetime(form_creation_date) person.save()