def new_doctor_type_page(request, doctor_id): context = {} context['doctor_id'] = doctor_id context['header'] = 'Добавить тип' context['label'] = 'Тип' template_name = 'doctors/new_text_form_page.html' try: doctor = Doctor.objects.get(id=doctor_id) except Doctor.DoesNotExist: return HttpResponseRedirect(reverse('doctors_url')) if request.method == 'POST': form = TextForm(request.POST) if form.is_valid(): type = Doctors_type() type.doctor = doctor type.name = form.cleaned_data['name'] type.save() return HttpResponseRedirect( reverse('doctor_url', kwargs={'id': doctor.id})) else: context['error'] = True context['form'] = TextForm() context['error_message'] = 'Неверно заполнена форма.' return render(request, template_name, context) else: context['form'] = TextForm() return render(request, template_name, context)
def edit_certificate_page(request, doctor_id, id): context = {} context['doctor_id'] = doctor_id context['header'] = 'Изменить сертификат' context['label'] = 'Сертификат' template_name = 'doctors/new_text_form_page.html' try: doctor = Doctor.objects.get(id=doctor_id) except Doctor.DoesNotExist: return HttpResponseRedirect(reverse('doctors_url')) try: certificate = Certificate.objects.get(id=id) except Certificate.DoesNotExist: return HttpResponseRedirect( reverse('doctorr_url', kwargs={'id': doctor.id})) if request.method == 'POST': form = TextForm(request.POST) if form.is_valid(): certificate.name = form.cleaned_data['name'] certificate.save() return HttpResponseRedirect( reverse('doctor_url', kwargs={'id': doctor.id})) else: context['error'] = True context['form'] = TextForm() context['error_message'] = 'Неверно заполнена форма.' context['default_value'] = request.POST['name'] return render(request, template_name, context) else: context['form'] = TextForm() context['default_value'] = certificate.name return render(request, template_name, context)