]>
git.p6c8.net - pcdenotes.git/blob - notes/views.py
1 from django
.shortcuts
import render
, get_object_or_404
, redirect
2 from django
.core
.paginator
import Paginator
4 from pcdenotes
.settings
import NOTES_PER_PAGE
5 from .models
import Note
7 # Create your views here.
9 def note_list(request
):
10 notes
= Note
.objects
.all() if request
.user
.is_staff
else Note
.objects
.filter(status
=1)
12 notes_count
= Note
.objects
.filter(status
=1).count()
13 paginator
= Paginator(notes
, NOTES_PER_PAGE
)
18 page_number
= int(request
.GET
.get('page'))
22 page_count
= paginator
.num_pages
24 notes_page
= paginator
.get_page(page_number
)
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
})
28 def note_redirect(request
):
29 return redirect('notes:note_list', permanent
=True)
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