def notecard_list(request, section_id): # Look up the section or raise 404 try: cache_key = str(section_id) + 'single_section_cache_key' section = cache.get(cache_key) if not section: section = Section.objects.get(id__iexact = section_id) cache.set(cache_key, section, cache_time) except Section.DoesNotExist: raise Http404 cache_key_2 = str(section.semester.id) + 'single_semester_cache_key' semester = cache.get(cache_key_2) if not semester: # create semester variable to test if owned by user semester = Semester.objects.get(section__id__iexact = section_id) cache.set(cache_key_2, semester, cache_time) # check if user owns the related semester - if not, returns to semester_list if semester.user == request.user: cache_key_3 = str(section_id) + 'users_notecard_list_cache_key' notecard = cache.get(cache_key_3) if not notecard: # get all notecards related to the section of the semester owned by the user notecard = section.notecard_set.all().filter(section__semester__user=request.user) cache.set(cache_key_3, notecard, cache_time) # pagination notecard_list, paginator = paginate_me(request, notecard, 6) context = RequestContext(request) return render_to_response('notecards/notecard_list.html', {"section": section, "notecard_list": notecard_list, "paginator": paginator,}, context_instance=context) else: url = reverse('semester_list') return HttpResponseRedirect(url)
def section_list(request, semester_id): # Get chosen semester try: cache_key = str(semester_id) + 'single_semester_cache_key' semester = cache.get(cache_key) if not semester: semester = Semester.objects.get(id__iexact=semester_id) cache.set(cache_key, semester, cache_time) except Semester.DoesNotExist: raise Http404 # check if user owns the related semester - if not, returns to semester_list if semester.user == request.user: # get all sections related to the semester owned by the user cache_key_2 = str(semester_id) + 'users_section_list_cache_key' section = cache.get(cache_key_2) if not section: section = semester.section_set.all().filter(semester__user=request.user) cache.set(cache_key_2, section, cache_time) # pagination section_list, paginator = paginate_me(request, section, 6) context = RequestContext(request) return render_to_response('notecards/section_list.html', {"section_list": section_list, "semester": semester, "paginator": paginator,}, context_instance=context) else: url = reverse('semester_list') return HttpResponseRedirect(url)
def semester_list(request): # Find all of user's semesters or 404 cache_key = str(request.user) + 'users_semester_list_cache_key' semester = cache.get(cache_key) if not semester: semester = Semester.objects.filter(user=request.user) cache.set(cache_key, semester, cache_time) ## paginate each semester semester_list, paginator = paginate_me(request, semester, 6) context = RequestContext(request) return render_to_response('notecards/semester_list.html', {"semester_list": semester_list, "paginator": paginator,}, context_instance=context)
def unknown_list(request, section_id): try: section = Section.objects.get(id__iexact = section_id) except Section.DoesNotExist: raise Http404 cache_key = str(section_id) + 'unknown_list_cache_key' unknown_list = cache.get(cache_key) if not unknown_list: unknown_list = section.notecard_set.all().filter(known=0).filter(section__semester__user=request.user) cache.set(cache_key, unknown_list, cache_time) semester = Semester.objects.get(section__id__iexact = section_id) # check if known list is populated and user owns the related semester - if not, returns to notecard_list if unknown_list and semester.user == request.user: unknown, paginator = paginate_me(request, unknown_list, 1) context = RequestContext(request) return render_to_response('notecards/unknown.html', {"unknown": unknown, "section": section, "paginator": paginator,}, context_instance=context) else: url = reverse('notecard_list', kwargs={'section_id': section_id}) return HttpResponseRedirect(url)