def summary(request): calendars = Calendar.objects.all() summary_tuples = [] for i in calendars: events = Calendar.objects.get(pk=i.id).event_set.all() total = 0 wr = 0 ac = 0 de = 0 te = 0 for j in events: # event response counting total += 1 status = BelongsTo.Status( BelongsTo.objects.get(event=j, calendar=i).status) if status == "WR": wr += 1 elif status == "AC": ac += 1 elif status == "DE": de += 1 elif status == "TE": te += 1 summary_tuples.append((i.title, wr, ac, de, te, total)) context = {'summary_tuples': summary_tuples} return render(request, 'mycalendar/summary.html', context)
def eventindex(request, event_id): event = Event.objects.get(pk=event_id) statuses = [(c.title, BelongsTo.Status( BelongsTo.objects.get(event=event, calendar=c).status)) for c in event.calendars.all()] context = {'event': event, 'statuses': statuses} return render(request, 'mycalendar/eventindex.html', context)
def submitcreateevent(request, user_id): chosen_calendars = [ c for c in Calendar.objects.all() if request.POST["answer{}".format(c.id)] == "true" ] e = Event(title=request.POST["title"], start_time=request.POST["start_time"], end_time=request.POST["end_time"], created_by=User.objects.get(pk=user_id)) e.save() for c in chosen_calendars: bt = BelongsTo(event=e, calendar=c, status=BelongsTo.Status.WAITING_RESPONSE) bt.save() return HttpResponseRedirect(reverse('createdevent', args=( user_id, e.id, )))
def submitmodifyevent(request, event_id): invites = [] cals = Calendar.objects.all() for c in cals: if request.POST["answer{}".format(c.id)] == "true": invites.append(c) event = Event.objects.get(pk=event_id) event.title, event.start_time, event.end_time = request.POST[ "title"], request.POST["start_time"], request.POST["end_time"] event.save() print(BelongsTo.objects.filter(event=event_id)) bt = BelongsTo.objects.filter(event=event_id).delete() print(BelongsTo.objects.filter(event=event_id)) for i in invites: bt = BelongsTo(event=event, calendar=i, status=BelongsTo.Status.WAITING_RESPONSE) bt.save() return HttpResponseRedirect(reverse('modifiedevent', args=(event.id, )))
def submitmodifyevent(request, event_id): event = Event.objects.get(pk=event_id) chosen_calendars = [ c for c in Calendar.objects.all() if request.POST["answer{}".format(c.id)] == "true" ] all_calendars = Calendar.objects.all() e = Event(id=event_id, title=request.POST["title"], start_time=request.POST["start_time"], end_time=request.POST["end_time"], created_by=event.created_by) e.save() for c in all_calendars: # remove old event from all calendars BelongsTo.objects.filter(event=event, calendar=c).delete() for c in chosen_calendars: # post new status to all calendars bt = BelongsTo(event=e, calendar=c, status=BelongsTo.Status.WAITING_RESPONSE) bt.save() return HttpResponseRedirect(reverse('modifiedevent', args=(e.id, )))
def submitwaiting(request, user_id, calendar_id): cal = Calendar.objects.get(pk=calendar_id) events = cal.event_set.all() waiting = [ w for w in events if BelongsTo.Status( BelongsTo.objects.get(event=w, calendar=cal).status) == "WR" ] for w in waiting: BelongsTo.objects.filter(event=w, calendar=cal).delete() for w in waiting: resp = request.POST["r{}".format(w.id)] match = BelongsTo.Status.WAITING_RESPONSE if resp == "AC": match = BelongsTo.Status.ACCEPTED elif resp == "DE": match = BelongsTo.Status.DECLINED elif resp == "TE": match = BelongsTo.TENTATIVE bt = BelongsTo(event=w, calendar=cal, status=match) bt.save() context = {'waiting': waiting} return HttpResponseRedirect( reverse('submitedwaiting', args=(calendar_id, )))
def waiting(request, user_id, calendar_id): print(calendar_id) cal = Calendar.objects.get(pk=calendar_id) events = cal.event_set.all() waiting = [ w for w in events if BelongsTo.Status( BelongsTo.objects.get(event=w, calendar=cal).status) == "WR" ] context = { 'waiting': waiting, 'user_id': user_id, 'calendar_id': calendar_id } return render(request, 'mycalendar/waiting.html', context)
def summary(request): count = dict() calendar = Calendar.objects.all() for c in calendar: event_list = Calendar.objects.get(pk=c.id).event_set.all() count[c] = [0, 0, 0, 0, 0] for e in event_list: if BelongsTo.Status( BelongsTo.objects.get(event=e, calendar=c).status ) is BelongsTo.Status.WAITING_RESPONSE: count[c][0] += 1 elif BelongsTo.Status( BelongsTo.objects.get( event=e, calendar=c).status) is BelongsTo.Status.ACCEPTED: count[c][1] += 1 elif BelongsTo.Status( BelongsTo.objects.get( event=e, calendar=c).status) is BelongsTo.Status.DECLINED: count[c][2] += 1 elif BelongsTo.Status( BelongsTo.objects.get( event=e, calendar=c).status) is BelongsTo.Status.TENTATIVE: count[c][3] += 1 count[c][4] += 1 summary_tuples = [] for k, v in count.items(): tuple = (k, v[0], v[1], v[2], v[3], v[4]) summary_tuples.append(tuple) context = {'summary_tuples': summary_tuples} return render(request, 'mycalendar/summary.html', context)
def waiting(request, user_id, calendar_id): event = Calendar.objects.get(pk=calendar_id).event_set.all() event_filtered = [] for e in event: c = Calendar.objects.get(pk=calendar_id) if BelongsTo.Status(BelongsTo.objects.get( event=e, calendar=c).status) is BelongsTo.Status.WAITING_RESPONSE: event_filtered.append(e) context = { 'event_list': event_filtered, 'calendar': Calendar.objects.get(pk=calendar_id), 'user': User.objects.get(pk=user_id) } return render(request, 'mycalendar/waiting.html', context)
def submitwaiting(request, user_id, calendar_id, event_id): e = Event.objects.get(pk=event_id) c = Calendar.objects.get(pk=calendar_id) BelongsTo.objects.get(event=e, calendar=c).delete() if request.POST["answer{}".format(c.id)] is "Wait": bt = BelongsTo(event=e, calendar=c, status=BelongsTo.Status.WAITING_RESPONSE) bt.save() elif request.POST["answer{}".format(c.id)] is "Accept": bt = BelongsTo(event=e, calendar=c, status=BelongsTo.Status.ACCEPTED) bt.save() elif request.POST["answer{}".format(c.id)] is "Decline": bt = BelongsTo(event=e, calendar=c, status=BelongsTo.Status.DECLINED) bt.save() elif request.POST["answer{}".format(c.id)] is "Tentative": bt = BelongsTo(event=e, calendar=c, status=BelongsTo.Status.TENTATIVE) bt.save() return HttpResponseRedirect(reverse('waiting', args=(user_id, calendar_id)))