emblacken files

Wouldn't it be great if I just remembered to run Black before every commit?
This commit is contained in:
Hugh Rundle 2021-10-09 22:15:24 +11:00
parent b3cc9e5b75
commit 252ff0d689
4 changed files with 22 additions and 10 deletions

View file

@ -7,6 +7,7 @@ from .base_model import BookWyrmModel
from . import fields from . import fields
from .relationship import UserBlocks from .relationship import UserBlocks
class Group(BookWyrmModel): class Group(BookWyrmModel):
"""A group of users""" """A group of users"""
@ -36,6 +37,7 @@ class Group(BookWyrmModel):
return queryset.exclude(~Q(memberships__user=viewer), privacy="direct") return queryset.exclude(~Q(memberships__user=viewer), privacy="direct")
class GroupMember(models.Model): class GroupMember(models.Model):
"""Users who are members of a group""" """Users who are members of a group"""

View file

@ -79,7 +79,9 @@ class List(OrderedCollectionMixin, BookWyrmModel):
return queryset.exclude( return queryset.exclude(
~Q( # user isn't following and it isn't their own status and they are not a group member ~Q( # user isn't following and it isn't their own status and they are not a group member
Q(user__followers=viewer) | Q(user=viewer) | Q(group__memberships__user=viewer) Q(user__followers=viewer)
| Q(user=viewer)
| Q(group__memberships__user=viewer)
), ),
privacy="followers", # and the status (of the list) is followers only privacy="followers", # and the status (of the list) is followers only
) )
@ -89,10 +91,10 @@ class List(OrderedCollectionMixin, BookWyrmModel):
"""Override filter for "direct" privacy level to allow group members to see the existence of group lists""" """Override filter for "direct" privacy level to allow group members to see the existence of group lists"""
return queryset.exclude( return queryset.exclude(
~Q( # user not self and not in the group if this is a group list ~Q( # user not self and not in the group if this is a group list
Q(user=viewer) | Q(group__memberships__user=viewer) Q(user=viewer) | Q(group__memberships__user=viewer)
), ),
privacy="direct" privacy="direct",
) )
@classmethod @classmethod

View file

@ -72,7 +72,7 @@ class GroupViews(TestCase):
view = views.FindUsers.as_view() view = views.FindUsers.as_view()
request = self.factory.get("") request = self.factory.get("")
request.user = self.local_user request.user = self.local_user
result = view(request,group_id=999) result = view(request, group_id=999)
self.assertIsInstance(result, TemplateResponse) self.assertIsInstance(result, TemplateResponse)
validate_html(result.render()) validate_html(result.render())
self.assertEqual(result.status_code, 200) self.assertEqual(result.status_code, 200)
@ -85,7 +85,7 @@ class GroupViews(TestCase):
"name": "Updated Group", "name": "Updated Group",
"privacy": "private", "privacy": "private",
"description": "Test description", "description": "Test description",
"user": self.local_user "user": self.local_user,
} }
request = self.factory.post("", group_fields) request = self.factory.post("", group_fields)
request.user = self.local_user request.user = self.local_user

View file

@ -25,7 +25,11 @@ class Group(View):
group = get_object_or_404(models.Group, id=group_id) group = get_object_or_404(models.Group, id=group_id)
group.raise_visible_to_user(request.user) group.raise_visible_to_user(request.user)
lists = models.List.privacy_filter(request.user).filter(group=group).order_by("-updated_date") lists = (
models.List.privacy_filter(request.user)
.filter(group=group)
.order_by("-updated_date")
)
data = { data = {
"group": group, "group": group,
@ -53,7 +57,11 @@ class UserGroups(View):
def get(self, request, username): def get(self, request, username):
"""display a group""" """display a group"""
user = get_user_from_username(request.user, username) user = get_user_from_username(request.user, username)
groups = models.Group.privacy_filter(request.user).filter(memberships__user=user).order_by("-updated_date") groups = (
models.Group.privacy_filter(request.user)
.filter(memberships__user=user)
.order_by("-updated_date")
)
paginated = Paginator(groups, 12) paginated = Paginator(groups, 12)
data = { data = {
@ -164,7 +172,7 @@ def remove_member(request):
return HttpResponseBadRequest() return HttpResponseBadRequest()
# you can't be removed from your own group # you can't be removed from your own group
if request.POST["user"]== group.user: if request.POST["user"] == group.user:
return HttpResponseBadRequest() return HttpResponseBadRequest()
is_member = models.GroupMember.objects.filter(group=group, user=user).exists() is_member = models.GroupMember.objects.filter(group=group, user=user).exists()