Beispiel #1
0
def update_phone(request):
    id = request.POST.get('pk')
    client = get_object_or_404(Client, pk=id)
    client.phone = request.POST.get('value')
    client.save()
    messages.success(request, "Successfully updated client phone number")
    return render(request, "client_detail.html")
Beispiel #2
0
def update_c_notes(request):
    id = request.POST.get('pk')
    client = get_object_or_404(Client, pk=id)
    client.notes = request.POST.get('value')
    client.save()
    messages.success(request, "Successfully updated client notes")
    return render(request, "client_detail.html")
Beispiel #3
0
    def form_valid(self, form):
        print ('in form valid')
        client_form = CreateClientForm(self.request.POST)
        appt_form = AppointmentForm(self.request.POST)
        if client_form.is_valid() and appt_form.is_valid():
            email = client_form.cleaned_data['email']
            print (email)
            if Client.objects.filter(email=email).exists():
                print ('client exists')
                client = Client.objects.get(email=email)
            else:
                print ('create client', client_form['email'])
                client = client_form.save(commit=False)
                client.save()


            if appt_form.cleaned_data['date'] != None and \
               Appointment.objects.filter(client=client, date=appt_form.cleaned_data['date']).exists():
                appt_form.add_error('date', 'You already have an appointment for that date, please send an email via the link below if you have any questions.')
                return super(AppointmentCreateView, self).form_invalid(appt_form)


            if form.instance.time != None:
                slot = TimeSlots.objects.get(pk=form.instance.time.pk)
                if slot.available == "O":
                    appt = appt_form.save(commit=False)
                    appt.client=client
                    appt.save()

                    slot.available = "R"
                    #slot.assigned_to = client.coverage
                    slot.save()
                    notes = Notes()
                    notes.appointment = appt
                    notes.save()
            else:
                appt = appt_form.save(commit=False)
                appt.client=client
                appt.save()

            mail_sub = "SS web form submitted: " + str(form.instance.date) + str(client.name)
            mail_from = "From: "+ client.name
            mail_email = "   Email: " + client.email
            mail_msg = "   Message:  " + form.instance.comments
            mail_date =  "  Date: " +  str(form.instance.date)
            mail_slot = "  Slot:  " + str(form.instance.time)

            mail_content = (mail_from +
                             mail_email +
                             mail_date +
                             mail_slot +
                             mail_msg )

            mail_recipients = ['*****@*****.**'],['*****@*****.**'], ['*****@*****.**']
            if settings.DEBUG == False:
                send_mail(mail_sub, mail_content, 'steppingstonetk.gmail.com', mail_recipients)  #add fail silently

            print (appt.pk)

            return HttpResponseRedirect(reverse_lazy('ss_app:thanks', args=[appt.pk]))

        else:
            print ('these form errors', client_form.errors, appt_form.errors)
            return render (self.request, 'ss_app/appointment_form.html', {'days': Days.objects.filter(closed=True),
                                                                'client': client_form,
                                                                'form': appt_form,
                                                                'errors': appt_form.errors
                                                                        })
Beispiel #4
0
def update_prev_pregs(request):
    id = request.POST.get('pk')
    client = get_object_or_404(Client, pk=id)
    client.prev_pregs = request.POST.get('value')
    client.save()
    return render(request, "client_detail.html")
Beispiel #5
0
def update_hosp_num(request):
    id = request.POST.get('pk')
    client = get_object_or_404(Client, pk=id)
    client.hospital_num = request.POST.get('value')
    client.save()
    return render(request, "client_detail.html")
Beispiel #6
0
def update_haemo(request):
    id = request.POST.get('pk')
    client = get_object_or_404(Client, pk=id)
    client.haemoglobin = request.POST.get('value')
    client.save()
    return render(request, "client_detail.html")
Beispiel #7
0
def update_bt(request):
    id = request.POST.get('pk')
    client = get_object_or_404(Client, pk=id)
    client.blood_type = request.POST.get('value')
    client.save()
    return render(request, "client_detail.html")