def experience_page_post(client_instance, request): # TeamRome """" views.py ClientEditExperience(TemplateView) POST method. """ arr = pars_exp_request(request.POST) # list of dictionaries if any(arr): """ Delete old data for this client. Bug fix for duplicate date save. """ Experience.objects.filter(client_exp=client_instance).delete() for dic in arr: if any(dic.values()): """ If this dictionary hes any values? than take them and save to Exp. instance. """ experiences = Experience( client_exp=client_instance, name=dic['name'], position=dic['position'], start_date=dic['start_date'], end_date=dic['end_date'], duties=dic['duties'], ) experiences.save() if dic['sphere']: for s in dic['sphere']: if s: """ Save ManyToManyField 'sphere' """ sp = Sphere.objects.get(id=s) # type(s) == str !!! sp.save() experiences.sphere.add(sp) # print("\tExperience Form - OK:\n\t", organisation, spheres, position, start_date, end_date, duties) else: print('\tExperience Form is Empty') else: print('\tExperience Parser is Empty')
def experience_page_post(client_instance, request): """" views.py ClientEditExperience(TemplateView) POST method. """ print("experience_page_post()") time_0 = perf_counter() arr = pars_exp_request(request.POST) # list of dictionaries if any(arr): Experience.objects.all().delete() for dic in arr: organisation = dic['experience_1'] position = dic['experience_3'] start_date = dic['exp_date_start'] end_date = dic['exp_date_end'] duties = dic['experience_4'] if any(dic.values()): experiences = Experience( client_exp=client_instance, name=organisation, position=position, start_date=start_date if start_date else None, end_date=end_date if end_date else None, duties=duties if duties else None) experiences.save() spheres = dic['experience_2'] for s in spheres: if s: """ Save ManyToManyField 'sphere' """ sp = Sphere(sphere_word=s) sp.save() experiences.sphere.add(sp) # print("Experience Form - OK\n", organisation, spheres, position, start_date if start_date else None, # end_date if end_date else None, duties if duties else None) else: print('Experience Form is Empty') print('experience_page_post() - OK; TIME: %s' % (perf_counter() - time_0))
def recruit_experience_page_post(recruit_instance, request): # TeamRome """" views.py ClientEditExperience(TemplateView) POST method. """ arr = pars_exp_request(request.POST) # list of dictionaries if any(arr): """ Delete old data for this recruit. Bug fix for duplicate date save. """ RecruitExperience.objects.filter(recruit_exp=recruit_instance).delete() for dic in arr: if any(dic.values()): """ If this dictionary hes any values? than take them and save to Exp. instance. """ organisation = dic['experience_1'] position = dic['experience_3'] start_date = dic['exp_date_start'] end_date = dic['exp_date_end'] duties = dic['experience_4'] experiences = RecruitExperience( recruit_exp=recruit_instance, name=organisation, position=position, start_date=start_date, end_date=end_date, duties=duties, ) experiences.save() spheres = dic['experience_2'] for s in spheres: if s: """ Save ManyToManyField 'sphere' """ sp = Sphere.objects.get(id=s) sp.save() experiences.sphere.add(sp) else: print('\tExperience Form is Empty') else: print('\tExperience Parser is Empty')