def Daily(request, Date): day = int(string.split(Date, '-')[0]) month = int(string.split(Date, '-')[1]) year = int(string.split(Date, '-')[2]) actionUrl = "/kap/dayView/"+str(day)+"-"+str(month)+"-"+str(year)+"/" event_list = events.objects.filter(month=month, day=day, year=year, user=request.user.username) Workout = workouts.objects.filter(month=month, day=day, year=year, user=request.user.username) clock = [x for x in range(24)] context_dictionary = {} context_dictionary['actionUrl'] = actionUrl context_dictionary['day'] = day context_dictionary['month'] = month context_dictionary['year'] = year context_dictionary['event_list'] = event_list context_dictionary['workout'] = Workout context_dictionary['clock'] = clock if request.method == 'POST': form = event(request.POST) if form.is_valid(): object = form.save(commit=False) object.user = request.user.username object.day = day object.month = month object.year = year object.save() return HttpResponseRedirect(actionUrl) else: print form.errors else: form = event() context_dictionary['form'] = form context_dictionary['actionUrl'] = actionUrl return render(request, 'Daily.html', context_dictionary)
def Calendar (request, Date): monthNumber = int(string.split(Date, "-")[0]) year = int(string.split(Date, "-")[1]) #Once all the events have a associated username attached to them #then add request.user.username for the user filter to get that users events. event_list = events.objects.filter(month=monthNumber, year=year, user=request.user.username) workout_list = workouts.objects.filter(user=request.user.username, month=monthNumber, year=year) if(monthNumber == 13): monthNumber = 1 year += 1 if(monthNumber == 0): monthNumber = 12 year -= 1 month = getMonthProperties(str(monthNumber),year)[2] nextAddress = "/KAP/Calendar/"+str(int(monthNumber) + 1)+"-"+str(year) prevAddress = "/KAP/Calendar/"+str(int(monthNumber) - 1)+"-"+str(year) fstDayOfMonth = int(calendar.monthrange(year,int(monthNumber))[0]) secondWkSp = 7 - fstDayOfMonth daysInMonth = calendar.monthrange(year,int(monthNumber))[1] daysInMonth = range(daysInMonth + 1)[secondWkSp:] startingPoints = [secondWkSp, secondWkSp+7, secondWkSp+14, secondWkSp+21] endingPoints = [secondWkSp+6, secondWkSp+13, secondWkSp+20, secondWkSp+27] actionUrl = "/kap/Calendar/" + str(monthNumber) + "-" + str(year) +"/" json_string = make_json_string(event_list) data = json_string #data = JsonResponse(make_json_dict(data)) context_dictionary = {'monthstr':month, 'yearstr':year, 'fstDayOfMonth':range(fstDayOfMonth+1), 'daysInMonth':daysInMonth } context_dictionary['leftOver'] = range(secondWkSp)[1:] context_dictionary['startingPoints'] = startingPoints context_dictionary['endingPoints'] = endingPoints context_dictionary['next'] = nextAddress context_dictionary['prev'] = prevAddress context_dictionary['year'] = year context_dictionary['actionUrl'] = actionUrl context_dictionary['event_list'] = event_list context_dictionary['workout_list'] = workout_list context_dictionary['actionUrl'] = actionUrl context_dictionary['data'] = data context_dictionary['month'] = monthNumber context_dictionary['username'] = request.user.username if request.method == 'POST': form = event(request.POST) if form.is_valid(): object = form.save(commit=False) object.user = request.user.username object.month = monthNumber object.year = year object.save() return HttpResponseRedirect(actionUrl) else: print form.errors else: form = event() context_dictionary['form'] = form return render(request, 'calendar.html', context_dictionary)
def CalendarNp(request): currentDay = datetime.date.today().strftime("%d") year = int(datetime.date.today().strftime("%Y")) monthNumber = datetime.date.today().strftime("%m") month = getMonthProperties(monthNumber,year)[2] #When group feature is added make another list for group events and then concatenate event_list = events.objects.filter(month=monthNumber, year=year, user=request.user.username ) workout_list = workouts.objects.filter(user=request.user.username, month=monthNumber, year=year) #data = JsonResponse(make_json_dict(event_list)) nextAddress = "/KAP/Calendar/"+str((int(monthNumber) + 1))+"-"+str(year) prevAddress = "/KAP/Calendar/"+str(int(monthNumber) - 1)+"-"+str(year) fstDayOfMonth = int(calendar.monthrange(year,int(monthNumber))[0]) secondWkSp = 7 - fstDayOfMonth daysInMonth = calendar.monthrange(year,int(monthNumber))[1] daysInMonth = range(daysInMonth+1)[secondWkSp:] startingPoints = [secondWkSp, secondWkSp+7, secondWkSp+14, secondWkSp+21] endingPoints = [secondWkSp+6, secondWkSp+13, secondWkSp+20, secondWkSp+27] actionUrl = "/kap/Calendar/" + str(monthNumber) + "-" + str(year) +"/" context_dictionary = {'monthstr':month, 'yearstr':year, 'currentDay':currentDay, 'fstDayOfMonth':range(fstDayOfMonth+1), 'daysInMonth':daysInMonth} context_dictionary['leftOver'] = range(secondWkSp)[1:] context_dictionary['startingPoints'] = startingPoints context_dictionary['endingPoints'] = endingPoints context_dictionary['next'] = nextAddress context_dictionary['prev'] = prevAddress context_dictionary['event_list'] = event_list context_dictionary['workout_list'] = workout_list context_dictionary['actionUrl'] = actionUrl #context_dictionary['data'] = data context_dictionary['month'] = monthNumber context_dictionary['year'] = year context_dictionary['username'] = request.user.username if request.method == 'POST': form = event(request.POST) if form.is_valid(): object = form.save(commit=False) object.user = request.user.username object.day = int(currentDay) object.month = monthNumber object.year = int(year) object.save() return HttpResponseRedirect(actionUrl) else: print form.errors else: form = event() context_dictionary['form'] = form return render(request, 'calendar.html', context_dictionary) return render(request, 'calendar.html', context_dictionary)