2024-10-23 11:06:57 +02:00
|
|
|
from django.http import Http404, HttpResponse
|
2017-09-24 19:11:08 +02:00
|
|
|
from django.shortcuts import get_object_or_404, redirect
|
2024-10-23 13:19:31 +02:00
|
|
|
from django.views.generic import ListView, TemplateView
|
2017-09-21 19:38:49 +02:00
|
|
|
|
2017-09-23 19:07:13 +02:00
|
|
|
from mainsite.models import Publication, PublicationYear, SiteConfiguration
|
2017-09-21 10:58:19 +02:00
|
|
|
|
2017-09-21 14:00:10 +02:00
|
|
|
|
2019-01-19 17:28:24 +01:00
|
|
|
def robots_view(request):
|
2024-10-23 11:06:57 +02:00
|
|
|
"""Robots.txt view"""
|
2022-05-22 18:37:28 +02:00
|
|
|
body = "User-Agent: *\nDisallow: /\nAllow: /$\n"
|
2019-01-19 17:28:24 +01:00
|
|
|
return HttpResponse(body, content_type="text/plain")
|
|
|
|
|
|
|
|
|
2017-09-22 13:44:36 +02:00
|
|
|
class HomeView(TemplateView):
|
2024-10-23 11:06:57 +02:00
|
|
|
"""Website's homepage"""
|
2019-01-19 17:28:24 +01:00
|
|
|
|
|
|
|
template_name = "mainsite/homepage.html"
|
2017-09-22 13:44:36 +02:00
|
|
|
|
|
|
|
|
|
|
|
class WriteArticleView(TemplateView):
|
2024-10-23 11:06:57 +02:00
|
|
|
"""Tell the readers how they can contribute to the BOcal"""
|
2019-01-19 17:28:24 +01:00
|
|
|
|
|
|
|
template_name = "mainsite/write_article.html"
|
2017-09-22 13:44:36 +02:00
|
|
|
|
|
|
|
|
2024-10-23 13:19:31 +02:00
|
|
|
class PublicationListView(ListView):
|
|
|
|
"""
|
|
|
|
Display a list of publications (generic class).
|
|
|
|
"""
|
2017-09-22 19:03:43 +02:00
|
|
|
|
2024-10-23 13:19:31 +02:00
|
|
|
model = Publication
|
|
|
|
context_object_name = "publications"
|
2019-01-19 17:28:24 +01:00
|
|
|
template_name = "mainsite/publications_list_view.html"
|
2017-09-22 19:03:43 +02:00
|
|
|
|
|
|
|
def get_context_data(self, **kwargs):
|
2024-10-23 13:19:31 +02:00
|
|
|
ctx = super().get_context_data(**kwargs)
|
2017-09-22 19:03:43 +02:00
|
|
|
|
2024-10-23 13:19:31 +02:00
|
|
|
if len(ctx["publications"]) == 0:
|
2017-09-22 19:03:43 +02:00
|
|
|
raise Http404
|
|
|
|
|
2024-10-23 13:19:31 +02:00
|
|
|
return ctx
|
2017-09-21 19:38:49 +02:00
|
|
|
|
2017-09-22 19:03:43 +02:00
|
|
|
|
|
|
|
class YearView(PublicationListView):
|
2024-10-23 11:06:57 +02:00
|
|
|
"""Display a year worth of BOcals"""
|
2017-09-23 18:48:29 +02:00
|
|
|
|
2024-10-23 13:19:31 +02:00
|
|
|
def get_queryset(self):
|
|
|
|
year: int = self.kwargs.get("year")
|
|
|
|
nYear: int = self.kwargs.get("nYear")
|
|
|
|
|
|
|
|
if nYear != year + 1:
|
2017-09-21 14:00:10 +02:00
|
|
|
raise Http404
|
|
|
|
|
2024-10-23 13:19:31 +02:00
|
|
|
self.publication_year = get_object_or_404(PublicationYear, startYear=year)
|
2017-09-21 14:00:10 +02:00
|
|
|
|
2024-10-23 13:19:31 +02:00
|
|
|
return self.publication_year.publis()
|
2017-09-23 18:48:29 +02:00
|
|
|
|
2024-10-23 13:19:31 +02:00
|
|
|
def get_context_data(self, **kwargs):
|
|
|
|
return super().get_context_data(
|
|
|
|
intro_text=self.publication_year.descr,
|
|
|
|
is_year_view=True,
|
|
|
|
year_range=self.publication_year.prettyName,
|
|
|
|
**kwargs
|
|
|
|
)
|
2017-09-22 19:03:43 +02:00
|
|
|
|
|
|
|
|
|
|
|
class SpecialPublicationsView(PublicationListView):
|
2024-10-23 11:06:57 +02:00
|
|
|
"""Display the list of special publications"""
|
2017-09-23 19:07:13 +02:00
|
|
|
|
2024-10-23 13:19:31 +02:00
|
|
|
ordering = "-date"
|
|
|
|
|
|
|
|
def get_queryset(self):
|
|
|
|
return super().get_queryset().filter(is_special=True)
|
|
|
|
|
|
|
|
def get_context_data(self, **kwargs):
|
|
|
|
return super().get_context_data(
|
|
|
|
intro_text=SiteConfiguration.get_solo().specialPublisDescr,
|
|
|
|
is_year_view=False,
|
|
|
|
list_title="Numéros spéciaux",
|
|
|
|
**kwargs
|
|
|
|
)
|
2017-09-24 19:11:08 +02:00
|
|
|
|
|
|
|
|
|
|
|
def latestPublication(req):
|
2024-10-23 11:06:57 +02:00
|
|
|
"""Redirects to the latest standard publication"""
|
2017-09-24 19:11:08 +02:00
|
|
|
latestPubli = Publication.latest()
|
|
|
|
return redirect(latestPubli.url)
|