Exemple #1
0
def add_appointment(request, work_schedule_id):
    if (request.is_ajax() or True) and request.method == 'POST':
        ws = get_object_or_404(WorkSchedule, id=work_schedule_id)
        form = SimpleAppointmentForm(request.POST)
        if form.is_valid():
            ap = Appointment()
            ap.work_schedule = ws
            ap.name = form.cleaned_data['name']
            ap.phone = form.cleaned_data['phone']
            ap.starttime = form.cleaned_data['start']
            ap.endtime = form.cleaned_data['end']
            ap.save()
            if ap.phone.startswith('+3712') or (len(ap.phone)==8 and ap.phone.startswith('2')):
                if len(ap.phone) ==8:
                    ap.phone = '+371'+ap.phone
                msg = u'Henry will be waiting for you at Alexandra Beauty on %s at %s' % (
                                    ap.starttime.strftime(u'%Y-%m-%d'),
                                    ap.starttime.strftime(u'%H:%M'),
                                    )
                
                data = send_sms(ap.phone, msg)
                ap.confirmation_sent = True
            ap.save()
        mimetype = 'application/javascript'        
        return HttpResponse('OK',mimetype)
    return HttpResponse(status=400)
Exemple #2
0
def add_appointment_noschedule(request, business, employee_id):
    if (request.is_ajax() or True) and request.method == 'POST':
        
        emp = get_object_or_404(BusinessEmployee, id=int(employee_id))
        form = SimpleAppointmentForm(request.POST)
        if form.is_valid():
            start = datetime.datetime.fromtimestamp(int(form.cleaned_data['start']))
            end = datetime.datetime.fromtimestamp(int(form.cleaned_data['end']))
            ws = get_object_or_404(WorkSchedule, employee__id=employee_id,
                                   starttime__lte=start,
                                   endtime__gte=end)
            #ap = Appointment(work_schedule)
            ap = Appointment()
            ap.work_schedule = ws
            ap.name = form.cleaned_data['name']
            ap.phone = form.cleaned_data['phone']
            ap.starttime = start
            ap.endtime = end
            ap.save()
            if ap.phone.startswith('+3712') or (len(ap.phone)==8 and ap.phone.startswith('2')):
                if len(ap.phone) ==8:
                    ap.phone = '+371'+ap.phone
                msg = u'Henry will be waiting for you at Alexandra Beauty on %s at %s' % (
                                    ap.starttime.strftime(u'%Y-%m-%d'),
                                    ap.starttime.strftime(u'%H:%M'),
                                    )
                
                data = send_sms(ap.phone, msg)
                ap.confirmation_sent = True
            ap.save()
            mimetype = 'application/javascript'
            return HttpResponse('OK',mimetype)
        mimetype = 'application/javascript'        
        return HttpResponse('ERROR',mimetype)
    return HttpResponse(status=400)
Exemple #3
0
def send_sms_event(telephone):
    send_sms(telephone)