]> git.p6c8.net - pcdenotes.git/blob - notes/views.py
793f9ed49649edfa89ddb36ee1d8a72d143e73a2
[pcdenotes.git] / notes / views.py
1 from django.shortcuts import render, get_object_or_404
2 from django.core.paginator import Paginator
3
4 from pcdenotes.settings import NOTES_PER_PAGE
5 from .models import Note
6
7 # Create your views here.
8
9 def note_list(request):
10 notes = Note.objects.filter(status=1)
11 notes_count = Note.objects.filter(status=1).count()
12 paginator = Paginator(notes, NOTES_PER_PAGE)
13
14 page_number = 1
15
16 try:
17 page_number = int(request.GET.get('page'))
18 except:
19 pass
20
21 page_count = paginator.num_pages
22
23 notes_page = paginator.get_page(page_number)
24
25 return render(request, 'note_list.html', {'notes_page': notes_page, 'notes_count': notes_count, 'pages': paginator, 'page_number': page_number, 'page_count': page_count})
26
27 def note_detail(request, note_slug):
28 note = get_object_or_404(Note, slug=note_slug, status=1)
29 return render(request, 'note_detail.html', {'note': note})

patrick-canterino.de