2023-12-22 23:59:48 -05:00
|
|
|
import datetime
|
|
|
|
|
2023-08-10 14:56:38 -04:00
|
|
|
from django.contrib.auth.decorators import login_required
|
|
|
|
from django.core.exceptions import BadRequest, ObjectDoesNotExist, PermissionDenied
|
|
|
|
from django.http import Http404, HttpResponse, HttpResponseRedirect
|
|
|
|
from django.shortcuts import get_object_or_404, redirect, render
|
|
|
|
from django.utils.translation import gettext_lazy as _
|
2023-12-25 11:05:09 -05:00
|
|
|
from django.views.decorators.http import require_http_methods
|
2023-08-10 14:56:38 -04:00
|
|
|
from user_messages import api as msg
|
|
|
|
|
|
|
|
from catalog.models import *
|
2023-07-20 21:59:49 -04:00
|
|
|
from common.utils import AuthedHttpRequest
|
|
|
|
from users.models import APIdentity, User
|
2023-08-10 14:56:38 -04:00
|
|
|
from users.views import render_user_blocked, render_user_not_found
|
|
|
|
|
|
|
|
from ..forms import *
|
|
|
|
from ..models import *
|
2023-07-20 21:59:49 -04:00
|
|
|
from .common import render_list, target_identity_required
|
2023-08-10 14:56:38 -04:00
|
|
|
|
|
|
|
|
2023-12-25 11:05:09 -05:00
|
|
|
@require_http_methods(["GET"])
|
2023-07-20 21:59:49 -04:00
|
|
|
@target_identity_required
|
|
|
|
def profile(request: AuthedHttpRequest, user_name):
|
|
|
|
target = request.target_identity
|
|
|
|
# if user.mastodon_acct != user_name and user.username != user_name:
|
|
|
|
# return redirect(user.url)
|
2023-12-29 02:11:36 -05:00
|
|
|
if not request.user.is_authenticated and not target.anonymous_viewable:
|
2023-07-20 21:59:49 -04:00
|
|
|
return render(request, "users/home_anonymous.html", {"user": target.user})
|
|
|
|
me = target.user == request.user
|
2023-08-10 14:56:38 -04:00
|
|
|
|
2023-07-20 21:59:49 -04:00
|
|
|
qv = q_owned_piece_visible_to_user(request.user, target)
|
2023-08-10 14:56:38 -04:00
|
|
|
shelf_list = {}
|
|
|
|
visbile_categories = [
|
|
|
|
ItemCategory.Book,
|
|
|
|
ItemCategory.Movie,
|
|
|
|
ItemCategory.TV,
|
|
|
|
ItemCategory.Music,
|
|
|
|
ItemCategory.Podcast,
|
|
|
|
ItemCategory.Game,
|
|
|
|
ItemCategory.Performance,
|
|
|
|
]
|
|
|
|
for category in visbile_categories:
|
|
|
|
shelf_list[category] = {}
|
|
|
|
for shelf_type in ShelfType:
|
2024-01-20 22:52:08 -05:00
|
|
|
if shelf_type == ShelfType.DROPPED:
|
|
|
|
continue
|
2023-07-20 21:59:49 -04:00
|
|
|
label = target.shelf_manager.get_label(shelf_type, category)
|
2023-08-10 14:56:38 -04:00
|
|
|
if label is not None:
|
2023-07-20 21:59:49 -04:00
|
|
|
members = target.shelf_manager.get_latest_members(
|
2023-08-10 14:56:38 -04:00
|
|
|
shelf_type, category
|
|
|
|
).filter(qv)
|
|
|
|
shelf_list[category][shelf_type] = {
|
|
|
|
"title": label,
|
|
|
|
"count": members.count(),
|
|
|
|
"members": members[:10].prefetch_related("item"),
|
|
|
|
}
|
2023-12-02 15:24:07 -05:00
|
|
|
reviews = (
|
|
|
|
Review.objects.filter(q_item_in_category(category))
|
|
|
|
.filter(qv)
|
|
|
|
.order_by("-created_time")
|
2023-08-10 14:56:38 -04:00
|
|
|
)
|
|
|
|
shelf_list[category]["reviewed"] = {
|
|
|
|
"title": "评论过的" + category.label,
|
|
|
|
"count": reviews.count(),
|
|
|
|
"members": reviews[:10].prefetch_related("item"),
|
|
|
|
}
|
2023-07-20 21:59:49 -04:00
|
|
|
collections = Collection.objects.filter(qv).order_by("-created_time")
|
2023-12-27 16:23:46 -05:00
|
|
|
liked_collections = Collection.objects.filter(
|
|
|
|
interactions__identity=target,
|
|
|
|
interactions__interaction_type="like",
|
|
|
|
interactions__target_type="Collection",
|
|
|
|
).order_by("-edited_time")
|
2023-07-20 21:59:49 -04:00
|
|
|
if not me:
|
|
|
|
liked_collections = liked_collections.filter(
|
|
|
|
q_piece_visible_to_user(request.user)
|
|
|
|
)
|
|
|
|
top_tags = target.tag_manager.public_tags[:10]
|
2023-12-22 23:59:48 -05:00
|
|
|
year = None
|
2023-08-10 14:56:38 -04:00
|
|
|
else:
|
2023-07-20 21:59:49 -04:00
|
|
|
top_tags = target.tag_manager.all_tags[:10]
|
2023-12-22 23:59:48 -05:00
|
|
|
today = datetime.date.today()
|
|
|
|
if today.month > 11:
|
|
|
|
year = today.year
|
|
|
|
elif today.month < 2:
|
|
|
|
year = today.year - 1
|
|
|
|
else:
|
|
|
|
year = None
|
2023-08-10 14:56:38 -04:00
|
|
|
return render(
|
|
|
|
request,
|
|
|
|
"profile.html",
|
|
|
|
{
|
2023-07-20 21:59:49 -04:00
|
|
|
"user": target.user,
|
2023-08-13 18:00:10 -04:00
|
|
|
"identity": target,
|
2023-08-10 14:56:38 -04:00
|
|
|
"top_tags": top_tags,
|
|
|
|
"shelf_list": shelf_list,
|
|
|
|
"collections": collections[:10],
|
|
|
|
"collections_count": collections.count(),
|
2023-12-27 16:23:46 -05:00
|
|
|
"liked_collections": liked_collections[:10],
|
2023-08-10 14:56:38 -04:00
|
|
|
"liked_collections_count": liked_collections.count(),
|
2023-07-20 21:59:49 -04:00
|
|
|
"layout": target.preference.profile_layout,
|
2023-12-22 23:59:48 -05:00
|
|
|
"year": year,
|
2023-08-10 14:56:38 -04:00
|
|
|
},
|
|
|
|
)
|
|
|
|
|
|
|
|
|
2023-12-25 17:27:31 -05:00
|
|
|
@require_http_methods(["GET"])
|
|
|
|
@login_required
|
|
|
|
@target_identity_required
|
2023-08-10 14:56:38 -04:00
|
|
|
def user_calendar_data(request, user_name):
|
2023-12-25 17:27:31 -05:00
|
|
|
target = request.target_identity
|
2023-08-13 18:00:10 -04:00
|
|
|
max_visiblity = max_visiblity_to_user(request.user, target)
|
|
|
|
calendar_data = target.shelf_manager.get_calendar_data(max_visiblity)
|
2023-08-10 14:56:38 -04:00
|
|
|
return render(
|
|
|
|
request,
|
|
|
|
"calendar_data.html",
|
|
|
|
{
|
|
|
|
"calendar_data": calendar_data,
|
|
|
|
},
|
|
|
|
)
|