moviewyrm/bookwyrm/views/landing.py

53 lines
1.5 KiB
Python
Raw Normal View History

2021-03-08 16:49:10 +00:00
""" non-interactive pages """
2021-02-24 19:59:21 +00:00
from django.db.models import Max
2021-01-12 18:44:17 +00:00
from django.template.response import TemplateResponse
from django.views import View
from bookwyrm import forms, models
2021-01-29 18:25:31 +00:00
from .feed import Feed
2021-01-12 18:44:17 +00:00
# pylint: disable= no-self-use
class About(View):
2021-03-08 16:49:10 +00:00
""" create invites """
2021-01-12 18:44:17 +00:00
def get(self, request):
2021-03-08 16:49:10 +00:00
""" more information about the instance """
return TemplateResponse(request, "discover/about.html")
2021-01-12 18:44:17 +00:00
class Home(View):
2021-03-08 16:49:10 +00:00
""" discover page or home feed depending on auth """
2021-01-12 18:44:17 +00:00
def get(self, request):
2021-03-08 16:49:10 +00:00
""" this is the same as the feed on the home tab """
2021-01-12 18:44:17 +00:00
if request.user.is_authenticated:
feed_view = Feed.as_view()
2021-03-08 16:49:10 +00:00
return feed_view(request, "home")
2021-01-12 18:44:17 +00:00
discover_view = Discover.as_view()
return discover_view(request)
2021-03-08 16:49:10 +00:00
2021-01-12 18:44:17 +00:00
class Discover(View):
2021-03-08 16:49:10 +00:00
""" preview of recently reviewed books """
2021-01-12 18:44:17 +00:00
def get(self, request):
2021-03-08 16:49:10 +00:00
""" tiled book activity page """
books = (
models.Edition.objects.filter(
review__published_date__isnull=False,
review__deleted=False,
review__user__local=True,
review__privacy__in=["public", "unlisted"],
)
.exclude(cover__exact="")
.annotate(Max("review__published_date"))
.order_by("-review__published_date__max")[:6]
)
2021-01-12 18:44:17 +00:00
data = {
2021-03-08 16:49:10 +00:00
"register_form": forms.RegisterForm(),
"books": list(set(books)),
2021-01-12 18:44:17 +00:00
}
2021-03-08 16:49:10 +00:00
return TemplateResponse(request, "discover/discover.html", data)