]> git.p6c8.net - pcdenotes.git/blob - notes/views.py
Updated Bootstrap to 5.3.3
[pcdenotes.git] / notes / views.py
1 from django.shortcuts import render, get_object_or_404, redirect
2 from django.core.paginator import Paginator
3 from django.db.models.functions import ExtractYear, ExtractMonth
4
5 from pcdenotes.settings import NOTES_PER_PAGE
6 from .models import Note
7
8 # Create your views here.
9
10 def note_list(request):
11 notes = Note.objects.all() if request.user.is_staff else Note.objects.all_published()
12
13 notes_count = notes.count()
14 paginator = Paginator(notes, NOTES_PER_PAGE)
15
16 page_number = 1
17
18 try:
19 page_number = int(request.GET.get('page'))
20 except:
21 pass
22
23 page_count = paginator.num_pages
24
25 notes_page = paginator.get_page(page_number)
26
27 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
29 def note_redirect(request):
30 return redirect('notes:note_list', permanent=True)
31
32 def note_detail(request, note_slug):
33 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)
34 return render(request, 'note_detail.html', {'note': note})
35
36 def archive_main(request):
37 notes_years = Note.objects.years_with_total()
38 return render(request, 'archive_main.html', {'years': notes_years})
39
40 def archive_year(request, archive_year):
41 notes_months = Note.objects.months_with_total(archive_year)
42 return render(request, 'archive_year.html', {'year': archive_year, 'months': notes_months})
43
44 def archive_month(request, archive_year, archive_month):
45 notes = Note.objects.per_month(archive_year, archive_month)
46 return render(request, 'archive_month.html', {'year': archive_year, 'month': archive_month, 'notes': notes})

patrick-canterino.de