From f3a3ba5f0105ec7f5ab84b19edc75bb3d3ead7ff Mon Sep 17 00:00:00 2001 From: Hugh Rundle Date: Sun, 26 Sep 2021 15:56:02 +1000 Subject: [PATCH] pass group value to list views and vice-versa --- bookwyrm/views/group.py | 4 ++-- bookwyrm/views/list.py | 11 +++++++++++ 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/bookwyrm/views/group.py b/bookwyrm/views/group.py index 4214908a..0ad0bd31 100644 --- a/bookwyrm/views/group.py +++ b/bookwyrm/views/group.py @@ -26,10 +26,11 @@ class Group(View): # groups = privacy_filter( # request.user, groups, privacy_levels=["public", "followers"] # ) - + lists = models.List.objects.filter(group=group).order_by("-updated_date") data = { "group": group, + "lists": lists, "list_form": forms.GroupForm(), "path": "/group", } @@ -129,7 +130,6 @@ def add_member(request): ) except IntegrityError: - print("no integrity") pass return redirect(user.local_path) diff --git a/bookwyrm/views/list.py b/bookwyrm/views/list.py index 69530204..9ef02753 100644 --- a/bookwyrm/views/list.py +++ b/bookwyrm/views/list.py @@ -46,9 +46,12 @@ class Lists(View): request.user, lists, privacy_levels=["public", "followers"] ) + user_groups = models.Group.objects.filter(members=request.user).order_by("-updated_date") + paginated = Paginator(lists, 12) data = { "lists": paginated.get_page(request.GET.get("page")), + "user_groups": user_groups, "list_form": forms.ListForm(), "path": "/list", } @@ -59,6 +62,10 @@ class Lists(View): def post(self, request): """create a book_list""" form = forms.ListForm(request.POST) + # TODO: here we need to take the value of the group (the group.id) + # and fetch the actual group to add to the DB + # but only if curation type is 'group' other wise the value of + # group is None if not form.is_valid(): return redirect("lists") book_list = form.save() @@ -93,12 +100,14 @@ class UserLists(View): user = get_user_from_username(request.user, username) lists = models.List.objects.filter(user=user) lists = privacy_filter(request.user, lists) + user_groups = models.Group.objects.filter(members=request.user).order_by("-updated_date") paginated = Paginator(lists, 12) data = { "user": user, "is_self": request.user.id == user.id, "lists": paginated.get_page(request.GET.get("page")), + "user_groups": user_groups, "list_form": forms.ListForm(), "path": user.local_path + "/lists", } @@ -171,6 +180,7 @@ class List(View): ).order_by("-updated_date") ][: 5 - len(suggestions)] + user_groups = models.Group.objects.filter(members=request.user).order_by("-updated_date") page = paginated.get_page(request.GET.get("page")) data = { "list": book_list, @@ -185,6 +195,7 @@ class List(View): "sort_form": forms.SortListForm( {"direction": direction, "sort_by": sort_by} ), + "user_groups": user_groups } return TemplateResponse(request, "lists/list.html", data)