def add_user_work(request): """ Add a record for User Work Experience """ user = request.user fullname = user.get_full_name() form = AddWorkForm(request.POST) if (form.is_valid() and (form.cleaned_data["end_date"] is None or form.cleaned_data["end_date"] > form.cleaned_data["start_date"])): user_company = form.cleaned_data["company"] company = Company.objects.filter(company=user_company) if (len(company) == 0): company = Company() company.company = user_company company.save() user_company = company else: user_company = company[0] user_position = form.cleaned_data["position"] user_description = form.cleaned_data["description"] user_work = Work(user=user) user_work.company = user_company user_work.position = user_position user_work.description = user_description user_work.start_date = form.cleaned_data["start_date"] user_work.end_date = form.cleaned_data["end_date"] user_work.save() info = True info_message = "Added Work Experience !" parameters = {'info': info, 'info_message': info_message} else: error = True error_list = True error_message = [] if form.cleaned_data["start_date"] is None: error_message.append("Start Date is required") if form.cleaned_data["company"] is None: error_message.append("Company is required") if form.cleaned_data["position"] is None: error_message.append("Position is required") if (form.cleaned_data["end_date"] is not None and (form.cleaned_data["end_date"] < form.cleaned_data["start_date"])): error_message.append("End Date has to be later than Start Date") parameters = { 'error': error, 'error_list': error_list, 'error_message': error_message } user_profile = UserProfile.objects.filter(user=user) if len(user_profile) != 0: profile_exists = True current_user_profile = user_profile[0] user_profile_dictionary = json.loads(current_user_profile.toJson()) parameters.update(user_profile_dictionary) else: profile_exists = False default_image = "/static/elearning_academy/img/default/user.jpg" parameters.update({ 'user_name': fullname, 'default_image': default_image, 'profile_exists': profile_exists }) form = get_update_form(user) parameters.update(form) return render(request, 'user_profile/profile.html', parameters)
def add_user_work(request): """ Add a record for User Work Experience """ user = request.user fullname = user.get_full_name() form = AddWorkForm(request.POST) if (form.is_valid() and (form.cleaned_data["end_date"] is None or form.cleaned_data["end_date"] > form.cleaned_data["start_date"])): user_company = form.cleaned_data["company"] company = Company.objects.filter(company=user_company) if (len(company) == 0): company = Company() company.company = user_company company.save() user_company = company else: user_company = company[0] user_position = form.cleaned_data["position"] user_description = form.cleaned_data["description"] user_work = Work(user=user) user_work.company = user_company user_work.position = user_position user_work.description = user_description user_work.start_date = form.cleaned_data["start_date"] user_work.end_date = form.cleaned_data["end_date"] user_work.save() info = True info_message = "Added Work Experience !" parameters = {'info': info, 'info_message': info_message} else: error = True error_list = True error_message = [] if form.cleaned_data["start_date"] is None: error_message.append("Start Date is required") if form.cleaned_data["company"] is None: error_message.append("Company is required") if form.cleaned_data["position"] is None: error_message.append("Position is required") if (form.cleaned_data["end_date"] is not None and (form.cleaned_data["end_date"] < form.cleaned_data["start_date"])): error_message.append("End Date has to be later than Start Date") parameters = {'error': error, 'error_list': error_list, 'error_message': error_message} user_profile = UserProfile.objects.filter(user=user) if len(user_profile) != 0: profile_exists = True current_user_profile = user_profile[0] user_profile_dictionary = json.loads(current_user_profile.toJson()) parameters.update(user_profile_dictionary) else: profile_exists = False default_image = "/static/elearning_academy/img/default/user.jpg" parameters.update({'user_name': fullname, 'default_image': default_image, 'profile_exists': profile_exists}) form = get_update_form(user) parameters.update(form) return render(request, 'user_profile/profile.html', parameters)