Coverage for website/thabloid/views.py: 64.29%

14 statements  

« prev     ^ index     » next       coverage.py v7.6.7, created at 2025-08-14 10:31 +0000

1from django.contrib.auth.decorators import login_required 

2from django.db.models import Max 

3from django.shortcuts import get_object_or_404, redirect, render 

4 

5from utils.media.services import get_media_url 

6 

7from .models import Thabloid 

8 

9 

10@login_required 

11def index(request): 

12 """Render Thabloid overview index page.""" 

13 thabloids = Thabloid.objects.all() 

14 context = { 

15 "thabloids": thabloids, 

16 "year": thabloids.aggregate(Max("year")).get("year__max"), 

17 } 

18 return render(request, "thabloid/index.html", context) 

19 

20 

21@login_required 

22def thabloid(request, year, issue): 

23 """Redirect to the Thabloid file.""" 

24 thabloid = get_object_or_404(Thabloid, year=year, issue=issue) 

25 return redirect(get_media_url(thabloid.file))