]>
git.p6c8.net - pcdenotes.git/blob - notes/views.py
c6f2e26966407bb3f51b6d97367b3a19e174a42e
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
5 from pcdenotes
.settings
import NOTES_PER_PAGE
6 from .models
import Note
8 # Create your views here.
10 def note_list(request
):
11 notes
= Note
.objects
.all() if request
.user
.is_staff
else Note
.objects
.filter(status
=1)
13 notes_count
= notes
.count()
14 paginator
= Paginator(notes
, NOTES_PER_PAGE
)
19 page_number
= int(request
.GET
.get('page'))
23 page_count
= paginator
.num_pages
25 notes_page
= paginator
.get_page(page_number
)
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
})
29 def note_redirect(request
):
30 return redirect('notes:note_list', permanent
=True)
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
})
36 def archive_main(request
):
37 notes_years
= Note
.objects
.years()
38 return render(request
, 'archive_main.html', {'years': notes_years
})
40 def archive_year(request
, archive_year
):
41 notes_months
= Note
.objects
.months(archive_year
)
42 return render(request
, 'archive_year.html', {'year': archive_year
, 'months': notes_months
})
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