diff --git a/bookwyrm/views/__init__.py b/bookwyrm/views/__init__.py index 16ebb2bad..5776106bd 100644 --- a/bookwyrm/views/__init__.py +++ b/bookwyrm/views/__init__.py @@ -32,6 +32,7 @@ from .follow import follow, unfollow from .follow import accept_follow_request, delete_follow_request from .get_started import GetStartedBooks, GetStartedProfile, GetStartedUsers from .goal import Goal, hide_goal +from .group import UserGroups from .import_data import Import, ImportStatus from .inbox import Inbox from .interaction import Favorite, Unfavorite, Boost, Unboost diff --git a/bookwyrm/views/group.py b/bookwyrm/views/group.py new file mode 100644 index 000000000..7be10a917 --- /dev/null +++ b/bookwyrm/views/group.py @@ -0,0 +1,51 @@ +"""group views""" +from typing import Optional +from urllib.parse import urlencode + +from django.contrib.auth.decorators import login_required +from django.core.exceptions import PermissionDenied +from django.core.paginator import Paginator +from django.db import IntegrityError, transaction +from django.db.models import Avg, Count, DecimalField, Q, Max +from django.db.models.functions import Coalesce +from django.http import HttpResponseNotFound, HttpResponseBadRequest, HttpResponse +from django.shortcuts import get_object_or_404, redirect +from django.template.response import TemplateResponse +from django.urls import reverse +from django.utils.decorators import method_decorator +from django.views import View +from django.views.decorators.http import require_POST + +from bookwyrm import forms, models +from bookwyrm.connectors import connector_manager +from bookwyrm.settings import PAGE_LENGTH +from .helpers import is_api_request, privacy_filter +from .helpers import get_user_from_username + +@method_decorator(login_required, name="dispatch") +class UserGroups(View): + """a user's groups page""" + + def get(self, request, username): + """display a group""" + user = get_user_from_username(request.user, username) + groups = models.GroupMember.objects.filter(user=user) + # groups = privacy_filter(request.user, groups) + paginated = Paginator(groups, 12) + + data = { + "user": user, + "is_self": request.user.id == user.id, + "groups": paginated.get_page(request.GET.get("page")), + "group_form": forms.GroupsForm(), + "path": user.local_path + "/groups", + } + return TemplateResponse(request, "user/groups.html", data) + +# @require_POST +# @login_required +# def save_list(request, group_id): +# """save a group""" +# group = get_object_or_404(models.Group, id=group_id) +# request.user.saved_group.add(group) +# return redirect("user", request.user.id) # TODO: change this to group page \ No newline at end of file diff --git a/bookwyrm/views/user.py b/bookwyrm/views/user.py index ca6eb0a52..63194ceb7 100644 --- a/bookwyrm/views/user.py +++ b/bookwyrm/views/user.py @@ -1,4 +1,5 @@ """ non-interactive pages """ +from bookwyrm.models.group import GroupMember from django.contrib.auth.decorators import login_required from django.core.paginator import Paginator from django.shortcuts import redirect @@ -132,6 +133,22 @@ class Following(View): } return TemplateResponse(request, "user/relationships/following.html", data) +class Groups(View): + """list of user's groups view""" + + def get(self, request, username): + """list of groups""" + user = get_user_from_username(request.user, username) + + paginated = Paginator( + GroupMember.objects.filter(user=user) + ) + data = { + "user": user, + "is_self": request.user.id == user.id, + "group_list": paginated.get_page(request.GET.get("page")), + } + return TemplateResponse(request, "user/groups.html", data) @require_POST @login_required