Beispiel #1
0
def timeslots(request):

    if request.method == 'GET':
        slots = TimeSlot.objects.order_by("-date", "-start_time")
        # If the method is get, then just display the suggestion page
        return render(request, 'professor_view/add_time_slots.html', {
            'title': 'Add time slot',
            "timeslots": slots
        })
    else:
        # slots = json.loads(request.POST.get("slots", ""))
        startTimes = request.POST.getlist("startTimes[]")
        endTimes = request.POST.getlist("endTimes[]")
        professor_email = request.POST.get("professor_email")
        prof = None
        try:
            prof = Professor.objects.get(email=professor_email)
        except Professor.DoesNotExist:
            return JsonResponse({'result': "Erro"})
        date = request.POST.get("date")
        professor_name = request.user.first_name + " " + request.user.last_name
        if prof != None:
            professor_name = prof.title + " " + professor_name
        for i in range(len(startTimes)):
            start = startTimes[i]
            end = endTimes[i]
            timeslot = TimeSlot()
            timeslot.save_data(professor_name, professor_email, start, end,
                               date)
            timeslot.save()

        return JsonResponse({'result': 'Ok'})
Beispiel #2
0
def delete_appointment(request, id):

    app = Appointment.objects.get(id=id)
    app.delete()
    slot = TimeSlot()
    slot.save_data(app.professor_name, app.professor_email, app.start_time,
                   app.end_time, app.date)
    slot.save()

    return redirect('/all_appointments/')