Add new user tab listing only reviews and comments

This commit is contained in:
Christof Dorner 2022-12-10 16:55:45 +01:00
parent 0452731d02
commit fbd8e22b97
6 changed files with 106 additions and 1 deletions

View file

@ -66,6 +66,10 @@
<li{% if url == request.path or url == request.path|add:'/' %} class="is-active"{% endif %}>
<a href="{{ url }}">{% trans "Activity" %}</a>
</li>
{% url 'user-reviews-comments' user|username as url %}
<li{% if url == request.path or url == request.path|add:'/' %} class="is-active"{% endif %}>
<a href="{{ url }}">{% trans "Reviews and Comments" %}</a>
</li>
{% if is_self or user.goal.exists %}
{% now 'Y' as year %}
{% url 'user-goal' user|username year as url %}

View file

@ -0,0 +1,30 @@
{% extends 'user/layout.html' %}
{% load i18n %}
{% load utilities %}
{% block title %}{{ user.display_name }}{% endblock %}
{% block header %}
<div class="columns is-mobile">
<div class="column">
<h1 class="title">{% trans "Reviews and Comments" %}</h1>
</div>
</div>
{% endblock %}
{% block panel %}
<div>
{% for activity in activities %}
<div class="block" id="feed_{{ activity.id }}">
{% include 'snippets/status/status.html' with status=activity %}
</div>
{% endfor %}
{% if not activities %}
<div class="block">
<p>{% trans "No reviews or comments yet!" %}</p>
</div>
{% endif %}
{% include 'snippets/pagination.html' with page=activities path=path %}
</div>
{% endblock %}

View file

@ -233,3 +233,19 @@ class UserViews(TestCase):
result = views.user_redirect(request, "mouse")
self.assertEqual(result.status_code, 302)
def test_reviews_comments_page(self):
"""there are so many views, this just makes sure it LOADS"""
view = views.UserReviewsComments.as_view()
request = self.factory.get("")
request.user = self.local_user
result = view(request, "mouse")
self.assertIsInstance(result, TemplateResponse)
validate_html(result.render())
self.assertEqual(result.status_code, 200)
request.user = self.anonymous_user
result = view(request, "mouse")
self.assertIsInstance(result, TemplateResponse)
validate_html(result.render())
self.assertEqual(result.status_code, 200)

View file

@ -410,6 +410,11 @@ urlpatterns = [
name="user-relationships",
),
re_path(r"^hide-suggestions/?$", views.hide_suggestions, name="hide-suggestions"),
re_path(
rf"{USER_PATH}/reviews-comments",
views.UserReviewsComments.as_view(),
name="user-reviews-comments",
),
# groups
re_path(rf"{USER_PATH}/groups/?$", views.UserGroups.as_view(), name="user-groups"),
re_path(

View file

@ -137,7 +137,13 @@ from .setup import InstanceConfig, CreateAdmin
from .status import CreateStatus, EditStatus, DeleteStatus, update_progress
from .status import edit_readthrough
from .updates import get_notification_count, get_unread_status_string
from .user import User, hide_suggestions, user_redirect, toggle_guided_tour
from .user import (
User,
UserReviewsComments,
hide_suggestions,
user_redirect,
toggle_guided_tour,
)
from .relationships import Relationships
from .wellknown import *
from .annual_summary import (

View file

@ -1,6 +1,7 @@
""" The user profile """
from django.contrib.auth.decorators import login_required
from django.core.paginator import Paginator
from django.db.models import Q
from django.http import Http404
from django.shortcuts import redirect
from django.template.response import TemplateResponse
@ -100,6 +101,49 @@ class User(View):
return TemplateResponse(request, "user/user.html", data)
class UserReviewsComments(View):
"""user's activity filtered by reviews and comments"""
def get(self, request, username):
"""user's activity filtered by reviews and comments"""
user = get_user_from_username(request.user, username)
is_self = request.user.id == user.id
activities = (
models.Status.privacy_filter(
request.user,
)
.filter(
Q(review__isnull=False) | Q(comment__isnull=False),
user=user,
)
.exclude(
privacy="direct",
)
.select_related(
"user",
"reply_parent",
"review__book",
"comment__book",
"quotation__book",
)
.prefetch_related(
"mention_books",
"mention_users",
"attachments",
)
)
paginated = Paginator(activities, PAGE_LENGTH)
data = {
"user": user,
"is_self": is_self,
"activities": paginated.get_page(request.GET.get("page", 1)),
}
return TemplateResponse(request, "user/reviews_comments.html", data)
@require_POST
@login_required
def hide_suggestions(request):