Esempio n. 1
0
def get_doctor_shedule(request):
    """
    send json with busy sheduler for doctor
    events = [
    {
        title: 'busy',
        start: '2015-09-16T14:00',
        end: '2015-09-16T15:00',
        color: 'yellow',
    },
    {
        title: 'busy',
        start: '2015-09-17T11:00',
        end: '2015-09-17T12:00',
        color: 'yellow',
    }]
    """
    if request.method != 'GET':
        raise http.Http404

    doctor_id = request.GET.get('doctor_id')
    if doctor_id:
        doctor = Doctor.objects.get(id=doctor_id)

        # today
        today = datetime.today()
        # first monday of this week
        this_week_moday = today + timedelta(days=0 - today.weekday())

        # date grater than today week monday
        appointments = Appointment.objects.filter(doctor=doctor, datetime__gt=this_week_moday)

        dt = timedelta(hours=1)

        events = []
        for a in appointments:
            end = a.datetime + dt
            event = {
                'id': a.datetime.strftime("%Y-%m-%dT%H:%M"),
                'title': 'busy',
                'start': a.datetime.strftime("%Y-%m-%dT%H:%M"),
                'end': end.strftime("%Y-%m-%dT%H:%M"),
                'color': 'yellow',
            }
            events.append(event)

        events_json = json.dumps(events)
    else:
        return jsonSimpleAns(error='error')

    return jsonSimpleAns(info={'events_json': events_json})
Esempio n. 2
0
def save_appointment(request):
    """
    """
    if request.method != 'POST':
        raise http.Http404

    appointment_form = AppointmentForm(request.POST)

    if appointment_form.is_valid():
        try:
            appointment = appointment_form.save(commit=False)
            form_dt = request.POST.get('datetime')
            # Tue Sep 15 2015 11:00:00 GMT+0000
            dt_obj = datetime.strptime(form_dt, "%a %b %d %Y %H:%M:%S GMT+0000")
            appointment.datetime = dt_obj
            appointment.save()

        except IntegrityError:
            return jsonSimpleAns(error='error')

    else:
        return jsonSimpleAns(error=appointment_form.errors)

    return render_to_response('success.html')