mirror of
https://github.com/bookwyrm-social/bookwyrm.git
synced 2025-01-21 14:38:08 +00:00
run Black on changed code
This commit is contained in:
parent
782512b2ce
commit
dafda649f1
10 changed files with 118 additions and 82 deletions
|
@ -294,11 +294,13 @@ class ListForm(CustomForm):
|
||||||
model = models.List
|
model = models.List
|
||||||
fields = ["user", "name", "description", "curation", "privacy", "group"]
|
fields = ["user", "name", "description", "curation", "privacy", "group"]
|
||||||
|
|
||||||
|
|
||||||
class GroupForm(CustomForm):
|
class GroupForm(CustomForm):
|
||||||
class Meta:
|
class Meta:
|
||||||
model = models.Group
|
model = models.Group
|
||||||
fields = ["user", "privacy", "name", "description"]
|
fields = ["user", "privacy", "name", "description"]
|
||||||
|
|
||||||
|
|
||||||
class ReportForm(CustomForm):
|
class ReportForm(CustomForm):
|
||||||
class Meta:
|
class Meta:
|
||||||
model = models.Report
|
model = models.Report
|
||||||
|
|
|
@ -82,7 +82,10 @@ class BookWyrmModel(models.Model):
|
||||||
return True
|
return True
|
||||||
|
|
||||||
# you can see groups of which you are a member
|
# you can see groups of which you are a member
|
||||||
if hasattr(self, "memberships") and self.memberships.filter(user=viewer).exists():
|
if (
|
||||||
|
hasattr(self, "memberships")
|
||||||
|
and self.memberships.filter(user=viewer).exists()
|
||||||
|
):
|
||||||
return True
|
return True
|
||||||
|
|
||||||
# you can see objects which have a group of which you are a member
|
# you can see objects which have a group of which you are a member
|
||||||
|
|
|
@ -6,14 +6,15 @@ from bookwyrm.settings import DOMAIN
|
||||||
from .base_model import BookWyrmModel
|
from .base_model import BookWyrmModel
|
||||||
from . import fields
|
from . import fields
|
||||||
from .relationship import UserBlocks
|
from .relationship import UserBlocks
|
||||||
|
|
||||||
# from .user import User
|
# from .user import User
|
||||||
|
|
||||||
|
|
||||||
class Group(BookWyrmModel):
|
class Group(BookWyrmModel):
|
||||||
"""A group of users"""
|
"""A group of users"""
|
||||||
|
|
||||||
name = fields.CharField(max_length=100)
|
name = fields.CharField(max_length=100)
|
||||||
user = fields.ForeignKey(
|
user = fields.ForeignKey("User", on_delete=models.PROTECT)
|
||||||
"User", on_delete=models.PROTECT)
|
|
||||||
description = fields.TextField(blank=True, null=True)
|
description = fields.TextField(blank=True, null=True)
|
||||||
privacy = fields.PrivacyField()
|
privacy = fields.PrivacyField()
|
||||||
|
|
||||||
|
@ -21,26 +22,22 @@ class Group(BookWyrmModel):
|
||||||
"""don't want the user to be in there in this case"""
|
"""don't want the user to be in there in this case"""
|
||||||
return f"https://{DOMAIN}/group/{self.id}"
|
return f"https://{DOMAIN}/group/{self.id}"
|
||||||
|
|
||||||
|
|
||||||
class GroupMember(models.Model):
|
class GroupMember(models.Model):
|
||||||
"""Users who are members of a group"""
|
"""Users who are members of a group"""
|
||||||
|
|
||||||
created_date = models.DateTimeField(auto_now_add=True)
|
created_date = models.DateTimeField(auto_now_add=True)
|
||||||
updated_date = models.DateTimeField(auto_now=True)
|
updated_date = models.DateTimeField(auto_now=True)
|
||||||
group = models.ForeignKey(
|
group = models.ForeignKey(
|
||||||
"Group",
|
"Group", on_delete=models.CASCADE, related_name="memberships"
|
||||||
on_delete=models.CASCADE,
|
|
||||||
related_name="memberships"
|
|
||||||
)
|
)
|
||||||
user = models.ForeignKey(
|
user = models.ForeignKey(
|
||||||
"User",
|
"User", on_delete=models.CASCADE, related_name="memberships"
|
||||||
on_delete=models.CASCADE,
|
)
|
||||||
related_name="memberships"
|
|
||||||
)
|
|
||||||
|
|
||||||
class Meta:
|
class Meta:
|
||||||
constraints = [
|
constraints = [
|
||||||
models.UniqueConstraint(
|
models.UniqueConstraint(fields=["group", "user"], name="unique_membership")
|
||||||
fields=["group", "user"], name="unique_membership"
|
|
||||||
)
|
|
||||||
]
|
]
|
||||||
|
|
||||||
def save(self, *args, **kwargs):
|
def save(self, *args, **kwargs):
|
||||||
|
@ -76,32 +73,25 @@ class GroupMember(models.Model):
|
||||||
|
|
||||||
class GroupMemberInvitation(models.Model):
|
class GroupMemberInvitation(models.Model):
|
||||||
"""adding a user to a group requires manual confirmation"""
|
"""adding a user to a group requires manual confirmation"""
|
||||||
|
|
||||||
created_date = models.DateTimeField(auto_now_add=True)
|
created_date = models.DateTimeField(auto_now_add=True)
|
||||||
group = models.ForeignKey(
|
group = models.ForeignKey(
|
||||||
"Group",
|
"Group", on_delete=models.CASCADE, related_name="user_invitations"
|
||||||
on_delete=models.CASCADE,
|
|
||||||
related_name="user_invitations"
|
|
||||||
)
|
)
|
||||||
user = models.ForeignKey(
|
user = models.ForeignKey(
|
||||||
"User",
|
"User", on_delete=models.CASCADE, related_name="group_invitations"
|
||||||
on_delete=models.CASCADE,
|
)
|
||||||
related_name="group_invitations"
|
|
||||||
)
|
|
||||||
|
|
||||||
class Meta:
|
class Meta:
|
||||||
constraints = [
|
constraints = [
|
||||||
models.UniqueConstraint(
|
models.UniqueConstraint(fields=["group", "user"], name="unique_invitation")
|
||||||
fields=["group", "user"], name="unique_invitation"
|
|
||||||
)
|
|
||||||
]
|
]
|
||||||
|
|
||||||
def save(self, *args, **kwargs): # pylint: disable=arguments-differ
|
def save(self, *args, **kwargs): # pylint: disable=arguments-differ
|
||||||
"""make sure the membership doesn't already exist"""
|
"""make sure the membership doesn't already exist"""
|
||||||
# if there's an invitation for a membership that already exists, accept it
|
# if there's an invitation for a membership that already exists, accept it
|
||||||
# without changing the local database state
|
# without changing the local database state
|
||||||
if GroupMember.objects.filter(
|
if GroupMember.objects.filter(user=self.user, group=self.group).exists():
|
||||||
user=self.user,
|
|
||||||
group=self.group
|
|
||||||
).exists():
|
|
||||||
self.accept()
|
self.accept()
|
||||||
return
|
return
|
||||||
|
|
||||||
|
@ -138,7 +128,7 @@ class GroupMemberInvitation(models.Model):
|
||||||
GroupMember.from_request(self)
|
GroupMember.from_request(self)
|
||||||
|
|
||||||
model = apps.get_model("bookwyrm.Notification", require_ready=True)
|
model = apps.get_model("bookwyrm.Notification", require_ready=True)
|
||||||
# tell the group owner
|
# tell the group owner
|
||||||
model.objects.create(
|
model.objects.create(
|
||||||
user=self.group.user,
|
user=self.group.user,
|
||||||
related_user=self.user,
|
related_user=self.user,
|
||||||
|
@ -148,7 +138,7 @@ class GroupMemberInvitation(models.Model):
|
||||||
|
|
||||||
# let the other members know about it
|
# let the other members know about it
|
||||||
for membership in self.group.memberships.all():
|
for membership in self.group.memberships.all():
|
||||||
member = membership.user
|
member = membership.user
|
||||||
if member != self.user and member != self.group.user:
|
if member != self.user and member != self.group.user:
|
||||||
model.objects.create(
|
model.objects.create(
|
||||||
user=member,
|
user=member,
|
||||||
|
|
|
@ -14,12 +14,7 @@ from .group import GroupMember
|
||||||
|
|
||||||
CurationType = models.TextChoices(
|
CurationType = models.TextChoices(
|
||||||
"Curation",
|
"Curation",
|
||||||
[
|
["closed", "open", "curated", "group"],
|
||||||
"closed",
|
|
||||||
"open",
|
|
||||||
"curated",
|
|
||||||
"group"
|
|
||||||
],
|
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
@ -70,11 +65,14 @@ class List(OrderedCollectionMixin, BookWyrmModel):
|
||||||
if self.user == viewer:
|
if self.user == viewer:
|
||||||
return
|
return
|
||||||
# group members can edit items in group lists
|
# group members can edit items in group lists
|
||||||
is_group_member = GroupMember.objects.filter(group=self.group, user=viewer).exists()
|
is_group_member = GroupMember.objects.filter(
|
||||||
|
group=self.group, user=viewer
|
||||||
|
).exists()
|
||||||
if is_group_member:
|
if is_group_member:
|
||||||
return
|
return
|
||||||
super().raise_not_editable(viewer)
|
super().raise_not_editable(viewer)
|
||||||
|
|
||||||
|
|
||||||
class ListItem(CollectionItemMixin, BookWyrmModel):
|
class ListItem(CollectionItemMixin, BookWyrmModel):
|
||||||
"""ok"""
|
"""ok"""
|
||||||
|
|
||||||
|
@ -119,14 +117,17 @@ class ListItem(CollectionItemMixin, BookWyrmModel):
|
||||||
user=membership.user,
|
user=membership.user,
|
||||||
related_user=self.user,
|
related_user=self.user,
|
||||||
related_list_item=self,
|
related_list_item=self,
|
||||||
notification_type="ADD"
|
notification_type="ADD",
|
||||||
)
|
)
|
||||||
|
|
||||||
def raise_not_deletable(self, viewer):
|
def raise_not_deletable(self, viewer):
|
||||||
"""the associated user OR the list owner can delete"""
|
"""the associated user OR the list owner can delete"""
|
||||||
if self.book_list.user == viewer:
|
if self.book_list.user == viewer:
|
||||||
return
|
return
|
||||||
# group members can delete items in group lists
|
# group members can delete items in group lists
|
||||||
is_group_member = GroupMember.objects.filter(group=self.book_list.group, user=viewer).exists()
|
is_group_member = GroupMember.objects.filter(
|
||||||
|
group=self.book_list.group, user=viewer
|
||||||
|
).exists()
|
||||||
if is_group_member:
|
if is_group_member:
|
||||||
return
|
return
|
||||||
super().raise_not_deletable(viewer)
|
super().raise_not_deletable(viewer)
|
||||||
|
|
|
@ -12,14 +12,16 @@ def has_groups(user):
|
||||||
|
|
||||||
return models.GroupMember.objects.filter(user=user).exists()
|
return models.GroupMember.objects.filter(user=user).exists()
|
||||||
|
|
||||||
|
|
||||||
@register.filter(name="is_member")
|
@register.filter(name="is_member")
|
||||||
def is_member(group, user):
|
def is_member(group, user):
|
||||||
"""whether or not the user is a member of this group"""
|
"""whether or not the user is a member of this group"""
|
||||||
|
|
||||||
return models.GroupMember.objects.filter(group=group,user=user).exists()
|
return models.GroupMember.objects.filter(group=group, user=user).exists()
|
||||||
|
|
||||||
|
|
||||||
@register.filter(name="is_invited")
|
@register.filter(name="is_invited")
|
||||||
def is_invited(group, user):
|
def is_invited(group, user):
|
||||||
"""whether or not the user has a pending invitation to join this group"""
|
"""whether or not the user has a pending invitation to join this group"""
|
||||||
|
|
||||||
return models.GroupMemberInvitation.objects.filter(group=group,user=user).exists()
|
return models.GroupMemberInvitation.objects.filter(group=group, user=user).exists()
|
||||||
|
|
|
@ -255,12 +255,28 @@ urlpatterns = [
|
||||||
re_path(r"^hide-suggestions/?$", views.hide_suggestions, name="hide-suggestions"),
|
re_path(r"^hide-suggestions/?$", views.hide_suggestions, name="hide-suggestions"),
|
||||||
# groups
|
# groups
|
||||||
re_path(rf"{USER_PATH}/groups/?$", views.UserGroups.as_view(), name="user-groups"),
|
re_path(rf"{USER_PATH}/groups/?$", views.UserGroups.as_view(), name="user-groups"),
|
||||||
re_path(r"^group/(?P<group_id>\d+)(.json)?/?$", views.Group.as_view(), name="group"),
|
re_path(
|
||||||
re_path(r"^group/(?P<group_id>\d+)/add-users/?$", views.FindUsers.as_view(), name="group-find-users"),
|
r"^group/(?P<group_id>\d+)(.json)?/?$", views.Group.as_view(), name="group"
|
||||||
|
),
|
||||||
|
re_path(
|
||||||
|
r"^group/(?P<group_id>\d+)/add-users/?$",
|
||||||
|
views.FindUsers.as_view(),
|
||||||
|
name="group-find-users",
|
||||||
|
),
|
||||||
re_path(r"^add-group-member/?$", views.invite_member, name="invite-group-member"),
|
re_path(r"^add-group-member/?$", views.invite_member, name="invite-group-member"),
|
||||||
re_path(r"^remove-group-member/?$", views.remove_member, name="remove-group-member"),
|
re_path(
|
||||||
re_path(r"^accept-group-invitation/?$", views.accept_membership, name="accept-group-invitation"),
|
r"^remove-group-member/?$", views.remove_member, name="remove-group-member"
|
||||||
re_path(r"^reject-group-invitation/?$", views.reject_membership, name="reject-group-invitation"),
|
),
|
||||||
|
re_path(
|
||||||
|
r"^accept-group-invitation/?$",
|
||||||
|
views.accept_membership,
|
||||||
|
name="accept-group-invitation",
|
||||||
|
),
|
||||||
|
re_path(
|
||||||
|
r"^reject-group-invitation/?$",
|
||||||
|
views.reject_membership,
|
||||||
|
name="reject-group-invitation",
|
||||||
|
),
|
||||||
# lists
|
# lists
|
||||||
re_path(rf"{USER_PATH}/lists/?$", views.UserLists.as_view(), name="user-lists"),
|
re_path(rf"{USER_PATH}/lists/?$", views.UserLists.as_view(), name="user-lists"),
|
||||||
re_path(r"^list/?$", views.Lists.as_view(), name="lists"),
|
re_path(r"^list/?$", views.Lists.as_view(), name="lists"),
|
||||||
|
|
|
@ -41,7 +41,15 @@ from .follow import follow, unfollow
|
||||||
from .follow import accept_follow_request, delete_follow_request
|
from .follow import accept_follow_request, delete_follow_request
|
||||||
from .get_started import GetStartedBooks, GetStartedProfile, GetStartedUsers
|
from .get_started import GetStartedBooks, GetStartedProfile, GetStartedUsers
|
||||||
from .goal import Goal, hide_goal
|
from .goal import Goal, hide_goal
|
||||||
from .group import Group, UserGroups, FindUsers, invite_member, remove_member, accept_membership, reject_membership
|
from .group import (
|
||||||
|
Group,
|
||||||
|
UserGroups,
|
||||||
|
FindUsers,
|
||||||
|
invite_member,
|
||||||
|
remove_member,
|
||||||
|
accept_membership,
|
||||||
|
reject_membership,
|
||||||
|
)
|
||||||
from .import_data import Import, ImportStatus
|
from .import_data import Import, ImportStatus
|
||||||
from .inbox import Inbox
|
from .inbox import Inbox
|
||||||
from .interaction import Favorite, Unfavorite, Boost, Unboost
|
from .interaction import Favorite, Unfavorite, Boost, Unboost
|
||||||
|
|
|
@ -18,6 +18,7 @@ from .helpers import privacy_filter
|
||||||
from .helpers import get_user_from_username
|
from .helpers import get_user_from_username
|
||||||
from bookwyrm.settings import DOMAIN
|
from bookwyrm.settings import DOMAIN
|
||||||
|
|
||||||
|
|
||||||
class Group(View):
|
class Group(View):
|
||||||
"""group page"""
|
"""group page"""
|
||||||
|
|
||||||
|
@ -47,7 +48,8 @@ class Group(View):
|
||||||
if not form.is_valid():
|
if not form.is_valid():
|
||||||
return redirect("group", user_group.id)
|
return redirect("group", user_group.id)
|
||||||
user_group = form.save()
|
user_group = form.save()
|
||||||
return redirect("group", user_group.id)
|
return redirect("group", user_group.id)
|
||||||
|
|
||||||
|
|
||||||
@method_decorator(login_required, name="dispatch")
|
@method_decorator(login_required, name="dispatch")
|
||||||
class UserGroups(View):
|
class UserGroups(View):
|
||||||
|
@ -56,7 +58,9 @@ 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)
|
||||||
memberships = models.GroupMember.objects.filter(user=user).all().order_by("-updated_date")
|
memberships = (
|
||||||
|
models.GroupMember.objects.filter(user=user).all().order_by("-updated_date")
|
||||||
|
)
|
||||||
paginated = Paginator(memberships, 12)
|
paginated = Paginator(memberships, 12)
|
||||||
|
|
||||||
data = {
|
data = {
|
||||||
|
@ -80,10 +84,12 @@ class UserGroups(View):
|
||||||
models.GroupMember.objects.create(group=group, user=request.user)
|
models.GroupMember.objects.create(group=group, user=request.user)
|
||||||
return redirect("group", group.id)
|
return redirect("group", group.id)
|
||||||
|
|
||||||
|
|
||||||
@method_decorator(login_required, name="dispatch")
|
@method_decorator(login_required, name="dispatch")
|
||||||
class FindUsers(View):
|
class FindUsers(View):
|
||||||
"""find friends to add to your group"""
|
"""find friends to add to your group"""
|
||||||
"""this is mostly borrowed from the Get Started friend finder"""
|
|
||||||
|
#this is mostly borrowed from the Get Started friend finder
|
||||||
|
|
||||||
def get(self, request, group_id):
|
def get(self, request, group_id):
|
||||||
"""basic profile info"""
|
"""basic profile info"""
|
||||||
|
@ -91,25 +97,23 @@ class FindUsers(View):
|
||||||
group = models.Group.objects.get(id=group_id)
|
group = models.Group.objects.get(id=group_id)
|
||||||
user_results = (
|
user_results = (
|
||||||
models.User.viewer_aware_objects(request.user)
|
models.User.viewer_aware_objects(request.user)
|
||||||
.exclude(memberships__in=group.memberships.all()) # don't suggest users who are already members
|
.exclude(
|
||||||
|
memberships__in=group.memberships.all()
|
||||||
|
) # don't suggest users who are already members
|
||||||
.annotate(
|
.annotate(
|
||||||
similarity=Greatest(
|
similarity=Greatest(
|
||||||
TrigramSimilarity("username", query),
|
TrigramSimilarity("username", query),
|
||||||
TrigramSimilarity("localname", query),
|
TrigramSimilarity("localname", query),
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
.filter(
|
.filter(similarity__gt=0.5, local=True)
|
||||||
similarity__gt=0.5,
|
|
||||||
local=True
|
|
||||||
)
|
|
||||||
.order_by("-similarity")[:5]
|
.order_by("-similarity")[:5]
|
||||||
)
|
)
|
||||||
data = {"no_results": not user_results}
|
data = {"no_results": not user_results}
|
||||||
|
|
||||||
if user_results.count() < 5:
|
if user_results.count() < 5:
|
||||||
user_results = list(user_results) + suggested_users.get_suggestions(
|
user_results = list(user_results) + suggested_users.get_suggestions(
|
||||||
request.user,
|
request.user, local=True
|
||||||
local=True
|
|
||||||
)
|
)
|
||||||
|
|
||||||
group = get_object_or_404(models.Group, id=group_id)
|
group = get_object_or_404(models.Group, id=group_id)
|
||||||
|
@ -121,13 +125,14 @@ class FindUsers(View):
|
||||||
return HttpResponseBadRequest()
|
return HttpResponseBadRequest()
|
||||||
|
|
||||||
data = {
|
data = {
|
||||||
"suggested_users": user_results,
|
"suggested_users": user_results,
|
||||||
"group": group,
|
"group": group,
|
||||||
"query": query,
|
"query": query,
|
||||||
"requestor_is_manager": request.user == group.user
|
"requestor_is_manager": request.user == group.user,
|
||||||
}
|
}
|
||||||
return TemplateResponse(request, "groups/find_users.html", data)
|
return TemplateResponse(request, "groups/find_users.html", data)
|
||||||
|
|
||||||
|
|
||||||
@require_POST
|
@require_POST
|
||||||
@login_required
|
@login_required
|
||||||
def invite_member(request):
|
def invite_member(request):
|
||||||
|
@ -145,16 +150,14 @@ def invite_member(request):
|
||||||
return HttpResponseBadRequest()
|
return HttpResponseBadRequest()
|
||||||
|
|
||||||
try:
|
try:
|
||||||
models.GroupMemberInvitation.objects.create(
|
models.GroupMemberInvitation.objects.create(user=user, group=group)
|
||||||
user=user,
|
|
||||||
group=group
|
|
||||||
)
|
|
||||||
|
|
||||||
except IntegrityError:
|
except IntegrityError:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
return redirect(user.local_path)
|
return redirect(user.local_path)
|
||||||
|
|
||||||
|
|
||||||
@require_POST
|
@require_POST
|
||||||
@login_required
|
@login_required
|
||||||
def remove_member(request):
|
def remove_member(request):
|
||||||
|
@ -168,15 +171,16 @@ def remove_member(request):
|
||||||
if not user:
|
if not 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()
|
||||||
is_invited = models.GroupMemberInvitation.objects.filter(group=group,user=user).exists()
|
is_invited = models.GroupMemberInvitation.objects.filter(
|
||||||
|
group=group, user=user
|
||||||
|
).exists()
|
||||||
|
|
||||||
if is_invited:
|
if is_invited:
|
||||||
try:
|
try:
|
||||||
invitation = models.GroupMemberInvitation.objects.get(
|
invitation = models.GroupMemberInvitation.objects.get(
|
||||||
user=user,
|
user=user, group=group
|
||||||
group=group
|
)
|
||||||
)
|
|
||||||
|
|
||||||
invitation.reject()
|
invitation.reject()
|
||||||
|
|
||||||
|
@ -186,11 +190,13 @@ def remove_member(request):
|
||||||
if is_member:
|
if is_member:
|
||||||
|
|
||||||
try:
|
try:
|
||||||
membership = models.GroupMember.objects.get(group=group,user=user)
|
membership = models.GroupMember.objects.get(group=group, user=user)
|
||||||
membership.delete()
|
membership.delete()
|
||||||
|
|
||||||
# remove this user's group-curated lists from the group
|
# remove this user's group-curated lists from the group
|
||||||
models.List.objects.filter(group=group,user=user).update(group=None,curation="closed")
|
models.List.objects.filter(group=group, user=user).update(
|
||||||
|
group=None, curation="closed"
|
||||||
|
)
|
||||||
|
|
||||||
except IntegrityError:
|
except IntegrityError:
|
||||||
pass
|
pass
|
||||||
|
@ -200,7 +206,7 @@ def remove_member(request):
|
||||||
notification_type = "LEAVE" if user == request.user else "REMOVE"
|
notification_type = "LEAVE" if user == request.user else "REMOVE"
|
||||||
# let the other members know about it
|
# let the other members know about it
|
||||||
for membership in memberships:
|
for membership in memberships:
|
||||||
member = membership.user
|
member = membership.user
|
||||||
if member != request.user:
|
if member != request.user:
|
||||||
model.objects.create(
|
model.objects.create(
|
||||||
user=member,
|
user=member,
|
||||||
|
@ -219,6 +225,7 @@ def remove_member(request):
|
||||||
|
|
||||||
return redirect(user.local_path)
|
return redirect(user.local_path)
|
||||||
|
|
||||||
|
|
||||||
@require_POST
|
@require_POST
|
||||||
@login_required
|
@login_required
|
||||||
def accept_membership(request):
|
def accept_membership(request):
|
||||||
|
@ -228,7 +235,7 @@ def accept_membership(request):
|
||||||
if not group:
|
if not group:
|
||||||
return HttpResponseBadRequest()
|
return HttpResponseBadRequest()
|
||||||
|
|
||||||
invite = models.GroupMemberInvitation.objects.get(group=group,user=request.user)
|
invite = models.GroupMemberInvitation.objects.get(group=group, user=request.user)
|
||||||
if not invite:
|
if not invite:
|
||||||
return HttpResponseBadRequest()
|
return HttpResponseBadRequest()
|
||||||
|
|
||||||
|
@ -240,6 +247,7 @@ def accept_membership(request):
|
||||||
|
|
||||||
return redirect(group.local_path)
|
return redirect(group.local_path)
|
||||||
|
|
||||||
|
|
||||||
@require_POST
|
@require_POST
|
||||||
@login_required
|
@login_required
|
||||||
def reject_membership(request):
|
def reject_membership(request):
|
||||||
|
@ -249,7 +257,7 @@ def reject_membership(request):
|
||||||
if not group:
|
if not group:
|
||||||
return HttpResponseBadRequest()
|
return HttpResponseBadRequest()
|
||||||
|
|
||||||
invite = models.GroupMemberInvitation.objects.get(group=group,user=request.user)
|
invite = models.GroupMemberInvitation.objects.get(group=group, user=request.user)
|
||||||
if not invite:
|
if not invite:
|
||||||
return HttpResponseBadRequest()
|
return HttpResponseBadRequest()
|
||||||
|
|
||||||
|
@ -259,4 +267,4 @@ def reject_membership(request):
|
||||||
except IntegrityError:
|
except IntegrityError:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
return redirect(request.user.local_path)
|
return redirect(request.user.local_path)
|
||||||
|
|
|
@ -183,7 +183,7 @@ class List(View):
|
||||||
"query": query or "",
|
"query": query or "",
|
||||||
"sort_form": forms.SortListForm(
|
"sort_form": forms.SortListForm(
|
||||||
{"direction": direction, "sort_by": sort_by}
|
{"direction": direction, "sort_by": sort_by}
|
||||||
)
|
),
|
||||||
}
|
}
|
||||||
return TemplateResponse(request, "lists/list.html", data)
|
return TemplateResponse(request, "lists/list.html", data)
|
||||||
|
|
||||||
|
@ -287,14 +287,20 @@ def add_book(request):
|
||||||
book_list = get_object_or_404(models.List, id=request.POST.get("list"))
|
book_list = get_object_or_404(models.List, id=request.POST.get("list"))
|
||||||
is_group_member = False
|
is_group_member = False
|
||||||
if book_list.curation == "group":
|
if book_list.curation == "group":
|
||||||
is_group_member = models.GroupMember.objects.filter(group=book_list.group, user=request.user).exists()
|
is_group_member = models.GroupMember.objects.filter(
|
||||||
|
group=book_list.group, user=request.user
|
||||||
|
).exists()
|
||||||
|
|
||||||
book_list.raise_visible_to_user(request.user)
|
book_list.raise_visible_to_user(request.user)
|
||||||
|
|
||||||
book = get_object_or_404(models.Edition, id=request.POST.get("book"))
|
book = get_object_or_404(models.Edition, id=request.POST.get("book"))
|
||||||
# do you have permission to add to the list?
|
# do you have permission to add to the list?
|
||||||
try:
|
try:
|
||||||
if request.user == book_list.user or is_group_member or book_list.curation == "open":
|
if (
|
||||||
|
request.user == book_list.user
|
||||||
|
or is_group_member
|
||||||
|
or book_list.curation == "open"
|
||||||
|
):
|
||||||
# add the book at the latest order of approved books, before pending books
|
# add the book at the latest order of approved books, before pending books
|
||||||
order_max = (
|
order_max = (
|
||||||
book_list.listitem_set.filter(approved=True).aggregate(Max("order"))[
|
book_list.listitem_set.filter(approved=True).aggregate(Max("order"))[
|
||||||
|
|
|
@ -137,6 +137,7 @@ class Following(View):
|
||||||
}
|
}
|
||||||
return TemplateResponse(request, "user/relationships/following.html", data)
|
return TemplateResponse(request, "user/relationships/following.html", data)
|
||||||
|
|
||||||
|
|
||||||
class Groups(View):
|
class Groups(View):
|
||||||
"""list of user's groups view"""
|
"""list of user's groups view"""
|
||||||
|
|
||||||
|
@ -144,9 +145,7 @@ class Groups(View):
|
||||||
"""list of groups"""
|
"""list of groups"""
|
||||||
user = get_user_from_username(request.user, username)
|
user = get_user_from_username(request.user, username)
|
||||||
|
|
||||||
paginated = Paginator(
|
paginated = Paginator(models.Group.memberships.filter(user=user))
|
||||||
models.Group.memberships.filter(user=user)
|
|
||||||
)
|
|
||||||
data = {
|
data = {
|
||||||
"user": user,
|
"user": user,
|
||||||
"is_self": request.user.id == user.id,
|
"is_self": request.user.id == user.id,
|
||||||
|
@ -154,6 +153,7 @@ class Groups(View):
|
||||||
}
|
}
|
||||||
return TemplateResponse(request, "user/groups.html", data)
|
return TemplateResponse(request, "user/groups.html", data)
|
||||||
|
|
||||||
|
|
||||||
@require_POST
|
@require_POST
|
||||||
@login_required
|
@login_required
|
||||||
def hide_suggestions(request):
|
def hide_suggestions(request):
|
||||||
|
|
Loading…
Reference in a new issue