2022-12-21 14:34:36 -05:00
|
|
|
import logging
|
2023-08-10 11:27:31 -04:00
|
|
|
|
2023-07-20 21:59:49 -04:00
|
|
|
from django.contrib.auth.decorators import login_required
|
2023-02-04 11:54:15 -05:00
|
|
|
from django.core.exceptions import BadRequest
|
2023-08-10 11:27:31 -04:00
|
|
|
from django.shortcuts import render
|
|
|
|
from django.utils.translation import gettext_lazy as _
|
2022-12-13 06:44:29 +00:00
|
|
|
|
2023-08-10 11:27:31 -04: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()
|
2023-05-20 11:01:18 -04:00
|
|
|
user = request.user
|
|
|
|
podcast_ids = [
|
|
|
|
p.item_id
|
2023-06-02 21:54:48 -04:00
|
|
|
for p in user.shelf_manager.get_latest_members(
|
2023-05-20 11:01:18 -04:00
|
|
|
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
|
2023-06-02 21:54:48 -04:00
|
|
|
for p in user.shelf_manager.get_latest_members(
|
2023-05-20 11:01:18 -04:00
|
|
|
ShelfType.PROGRESS, ItemCategory.Book
|
2023-06-02 21:54:48 -04:00
|
|
|
)[:10]
|
2023-05-20 11:01:18 -04:00
|
|
|
]
|
|
|
|
)
|
|
|
|
tvshows_in_progress = Item.objects.filter(
|
|
|
|
id__in=[
|
|
|
|
p.item_id
|
2023-06-02 21:54:48 -04:00
|
|
|
for p in user.shelf_manager.get_latest_members(
|
2023-05-20 11:01:18 -04:00
|
|
|
ShelfType.PROGRESS, ItemCategory.TV
|
2023-06-02 21:54:48 -04:00
|
|
|
)[:10]
|
2023-05-20 11:01:18 -04:00
|
|
|
]
|
|
|
|
)
|
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
|
|
|
{
|
2023-05-20 11:01:18 -04: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
|
|
|
{
|
2023-07-20 21:59:49 -04:00
|
|
|
"activities": ActivityManager(request.user.identity).get_timeline(
|
2022-12-29 23:57:02 -05:00
|
|
|
before_time=request.GET.get("last")
|
|
|
|
)[:PAGE_SIZE],
|
|
|
|
},
|
2022-12-21 14:34:36 -05:00
|
|
|
)
|