mirror of
https://github.com/bookwyrm-social/bookwyrm.git
synced 2024-12-03 06:46:39 +00:00
add views for groups
This commit is contained in:
parent
cfca806af8
commit
3e3c90ec03
3 changed files with 69 additions and 0 deletions
|
@ -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
|
||||
|
|
51
bookwyrm/views/group.py
Normal file
51
bookwyrm/views/group.py
Normal file
|
@ -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
|
|
@ -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
|
||||
|
|
Loading…
Reference in a new issue