diff --git a/bookwyrm/forms.py b/bookwyrm/forms.py index 23063ff7c..ceff1b2a7 100644 --- a/bookwyrm/forms.py +++ b/bookwyrm/forms.py @@ -295,6 +295,10 @@ class ListForm(CustomForm): model = models.List fields = ["user", "name", "description", "curation", "privacy"] +class GroupForm(CustomForm): + class Meta: + model = models.Group + fields = ["name", "description", "privacy"] class ReportForm(CustomForm): class Meta: diff --git a/bookwyrm/templates/groups/create_form.html b/bookwyrm/templates/groups/create_form.html index d146a922e..b469ce00d 100644 --- a/bookwyrm/templates/groups/create_form.html +++ b/bookwyrm/templates/groups/create_form.html @@ -6,7 +6,8 @@ {% endblock %} {% block form %} -
+ {% include 'group/form.html' %}
{% endblock %} + diff --git a/bookwyrm/templates/groups/form.html b/bookwyrm/templates/groups/form.html index fb53e60fd..e640fd26b 100644 --- a/bookwyrm/templates/groups/form.html +++ b/bookwyrm/templates/groups/form.html @@ -5,16 +5,16 @@
- + {{ group_form.name }}
- + {{ group_form.description }}
-
+ diff --git a/bookwyrm/templates/user/groups.html b/bookwyrm/templates/user/groups.html index edbba8496..3a5b9c76b 100644 --- a/bookwyrm/templates/user/groups.html +++ b/bookwyrm/templates/user/groups.html @@ -34,9 +34,9 @@ {% include 'groups/form.html' %} - + {% include 'groups/group_items.html' with groups=groups %}
- + {% include 'snippets/pagination.html' with page=user_groups path=path %}
{% endblock %} diff --git a/bookwyrm/urls.py b/bookwyrm/urls.py index 759350cca..bc50bb09a 100644 --- a/bookwyrm/urls.py +++ b/bookwyrm/urls.py @@ -254,8 +254,9 @@ urlpatterns = [ # lists re_path(rf"{USER_PATH}/lists/?$", views.UserLists.as_view(), name="user-lists"), re_path(rf"{USER_PATH}/groups/?$", views.UserGroups.as_view(), name="user-groups"), - re_path(r"^group/?$", views.UserGroups.as_view(), name="groups"), - # re_path(r"^save-group/(?P\d+)/?$", views.save_group, name="group-save"), + re_path(r"^groups/?$", views.UserGroups.as_view(), name="groups"), + # re_path(r"^group/?$", views.Group.as_view(), name="group"), + re_path(r"^create-shelf/?$", views.create_shelf, name="group-create"), re_path(r"^list/?$", views.Lists.as_view(), name="lists"), re_path(r"^list/saved/?$", views.SavedLists.as_view(), name="saved-lists"), re_path(r"^list/(?P\d+)(.json)?/?$", views.List.as_view(), name="list"), diff --git a/bookwyrm/views/__init__.py b/bookwyrm/views/__init__.py index 5776106bd..50f3bf4f1 100644 --- a/bookwyrm/views/__init__.py +++ b/bookwyrm/views/__init__.py @@ -32,7 +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 .group import Group, 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 index 7be10a917..f90537b85 100644 --- a/bookwyrm/views/group.py +++ b/bookwyrm/views/group.py @@ -19,9 +19,39 @@ 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 privacy_filter from .helpers import get_user_from_username +class Group(View): + """group page""" + + def get(self, request): + """display a group""" + + groups = models.Group.objects.query(members__contains=request.user) + groups = privacy_filter( + request.user, groups, privacy_levels=["public", "followers"] + ) + + paginated = Paginator(groups, 12) + data = { + "lists": paginated.get_page(request.GET.get("page")), + "list_form": forms.GroupForm(), + "path": "/group", + } + return TemplateResponse(request, "groups/group.html", data) + + @method_decorator(login_required, name="dispatch") + # pylint: disable=unused-argument + def post(self, request): + """create a book_list""" + form = forms.ListForm(request.POST) + if not form.is_valid(): + return redirect("lists") + book_list = form.save() + + return redirect(book_list.local_path) + @method_decorator(login_required, name="dispatch") class UserGroups(View): """a user's groups page""" @@ -30,22 +60,14 @@ class UserGroups(View): """display a group""" user = get_user_from_username(request.user, username) groups = models.GroupMember.objects.filter(user=user) - # groups = privacy_filter(request.user, groups) + 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(), + "group_form": forms.GroupForm(), "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