Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- @login_required
- def set_write_pasient(request, id, address):
- context ={}
- id_polyclinic = Polyclinic.objects.get(id = id)
- if request.method == 'POST':
- form = SetNoteForm(request.POST, initial={'address': address})
- if form.is_valid():
- fio = request.POST.get('fio')
- phone = request.POST.get('phone')
- date_of_birth = request.POST.get('date_of_birth')
- reason_for_calling = request.POST.get('reason_for_calling')
- address_form = request.POST.get('address')
- try:
- person = Patient_registration.objects.get(fio=fio,phone=phone,date_of_birth=date_of_birth,address=address_form)
- except Patient_registration.DoesNotExist:
- person = None
- if person != None:
- if person.recording_time.date() == datetime.datetime.today().date():
- messages.error(request, 'Данная запись уже существует !')
- return redirect('/new-write/%s/%s/' % (str(id),address))
- else:
- form = form.save(commit=False)
- form.polyclinic = id_polyclinic
- form.operator = request.user
- form.recording_time = get_time_to_city()
- form.save()
- from_email = settings.EMAIL_HOST_USER
- if id_polyclinic.email:
- to_email = [id_polyclinic.email]
- else:
- to_email = ['fora11@yandex.ru','fora11@yandex.ru',]
- subject = 'Запись на приём к врачу'
- entrance = request.POST.get('entrance')
- intercom_code = request.POST.get('intercom_code')
- floor = request.POST.get('floor')
- flat = request.POST.get('flat')
- SNILS = request.POST.get('SNILS')
- C_M_O_policy = request.POST.get('C_M_O_policy')
- polyclinic = request.POST.get('polyclinic')
- message = 'ФИО: %s,Год рождения: %s,Адрес проживания %s %s,Подъезд: %s, Этаж дома: %s,Код домофона: %s , Телефон: %s,Снилс: %s,Полис: %s,Причина вызова : %s' % (fio,date_of_birth,address_form,flat,entrance, intercom_code,floor,phone,SNILS,C_M_O_policy,reason_for_calling)
- send_mail(subject,message,from_email,to_email,fail_silently=False,)
- create_actions(request, Activity.CHOICES_OPTION[0][0], fio)
- return redirect('/')
- else:
- messages.error(request, 'Данная запись уже существует !')
- return redirect('/new-write/%s/%s/' % (str(id),address))
- else:
- messages.error(request, 'Не правильно заполнены поля !')
- return redirect('/new-write/%s/%s/' % (str(id),address))
- else:
- form = SetNoteForm(initial={'address': address})
- context['form'] = form
- return render(request,'registration/patient/person_set_form.html',context)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement