lib.itmens/social/views.py

73 lines
1.8 KiB
Python
Raw Normal View History

2022-12-21 14:34:36 -05:00
import logging
from django.conf import settings
2022-12-21 14:34:36 -05:00
from django.contrib.auth.decorators import login_required, permission_required
2023-02-04 11:54:15 -05:00
from django.core.exceptions import BadRequest
from django.shortcuts import render
from django.utils.translation import gettext_lazy as _
2022-12-13 06:44:29 +00:00
from catalog.models import *
from journal.models import *
from .models import *
2022-12-21 14:34:36 -05:00
2023-02-04 11:54:15 -05:00
_logger = logging.getLogger(__name__)
2022-12-21 14:34:36 -05:00
PAGE_SIZE = 10
@login_required
def feed(request):
2022-12-29 23:57:02 -05:00
if request.method != "GET":
2023-02-04 11:54:15 -05:00
raise BadRequest()
user = request.user
podcast_ids = [
p.item_id
for p in user.shelf_manager.get_latest_members(
ShelfType.PROGRESS, ItemCategory.Podcast
)
]
recent_podcast_episodes = PodcastEpisode.objects.filter(
program_id__in=podcast_ids
).order_by("-pub_date")[:10]
books_in_progress = Edition.objects.filter(
id__in=[
p.item_id
for p in user.shelf_manager.get_latest_members(
ShelfType.PROGRESS, ItemCategory.Book
)[:10]
]
)
tvshows_in_progress = Item.objects.filter(
id__in=[
p.item_id
for p in user.shelf_manager.get_latest_members(
ShelfType.PROGRESS, ItemCategory.TV
)[:10]
]
)
2022-12-21 14:34:36 -05:00
return render(
request,
2022-12-29 23:57:02 -05:00
"feed.html",
2022-12-21 14:34:36 -05:00
{
"recent_podcast_episodes": recent_podcast_episodes,
"books_in_progress": books_in_progress,
"tvshows_in_progress": tvshows_in_progress,
2022-12-29 23:57:02 -05:00
},
2022-12-21 14:34:36 -05:00
)
@login_required
def data(request):
2022-12-29 23:57:02 -05:00
if request.method != "GET":
2023-02-04 11:54:15 -05:00
raise BadRequest()
2022-12-21 14:34:36 -05:00
return render(
request,
2022-12-29 23:57:02 -05:00
"feed_data.html",
2022-12-21 14:34:36 -05:00
{
2022-12-29 23:57:02 -05:00
"activities": ActivityManager(request.user).get_timeline(
before_time=request.GET.get("last")
)[:PAGE_SIZE],
},
2022-12-21 14:34:36 -05:00
)