]> git.p6c8.net - pcdenotes.git/blob - notes/views.py
Redirect /notes/ to /
[pcdenotes.git] / notes / views.py
1 from django.shortcuts import render, get_object_or_404, redirect
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.all() if request.user.is_staff else Note.objects.filter(status=1)
11
12 notes_count = Note.objects.filter(status=1).count()
13 paginator = Paginator(notes, NOTES_PER_PAGE)
14
15 page_number = 1
16
17 try:
18 page_number = int(request.GET.get('page'))
19 except:
20 pass
21
22 page_count = paginator.num_pages
23
24 notes_page = paginator.get_page(page_number)
25
26 return render(request, 'note_list.html', {'notes_page': notes_page, 'notes_count': notes_count, 'pages': paginator, 'page_number': page_number, 'page_count': page_count})
27
28 def note_redirect(request):
29 return redirect('notes:note_list', permanent=True)
30
31 def note_detail(request, note_slug):
32 note = get_object_or_404(Note, slug=note_slug) if request.user.is_staff else get_object_or_404(Note, slug=note_slug, status=1)
33 return render(request, 'note_detail.html', {'note': note})

patrick-canterino.de