forked from mirrors/bookwyrm
revert name change for Group, GroupMember
these were named as BookwyrmGroup and BookwyrmGroupMember due to a misunderstanding about related_name and a dodgy development environment. This naming makes more sense.
This commit is contained in:
parent
21e6ed7388
commit
52a083a907
12 changed files with 31 additions and 36 deletions
|
@ -297,7 +297,7 @@ class ListForm(CustomForm):
|
||||||
|
|
||||||
class GroupForm(CustomForm):
|
class GroupForm(CustomForm):
|
||||||
class Meta:
|
class Meta:
|
||||||
model = models.BookwyrmGroup
|
model = models.Group
|
||||||
fields = ["user", "privacy", "name", "description"]
|
fields = ["user", "privacy", "name", "description"]
|
||||||
|
|
||||||
class ReportForm(CustomForm):
|
class ReportForm(CustomForm):
|
||||||
|
|
|
@ -21,7 +21,7 @@ from .relationship import UserFollows, UserFollowRequest, UserBlocks
|
||||||
from .report import Report, ReportComment
|
from .report import Report, ReportComment
|
||||||
from .federated_server import FederatedServer
|
from .federated_server import FederatedServer
|
||||||
|
|
||||||
from .group import BookwyrmGroup, BookwyrmGroupMember, GroupMemberInvitation
|
from .group import Group, GroupMember, GroupMemberInvitation
|
||||||
|
|
||||||
from .import_job import ImportJob, ImportItem
|
from .import_job import ImportJob, ImportItem
|
||||||
|
|
||||||
|
|
|
@ -8,7 +8,7 @@ from . import fields
|
||||||
from .relationship import UserBlocks
|
from .relationship import UserBlocks
|
||||||
# from .user import User
|
# from .user import User
|
||||||
|
|
||||||
class BookwyrmGroup(BookWyrmModel):
|
class Group(BookWyrmModel):
|
||||||
"""A group of users"""
|
"""A group of users"""
|
||||||
|
|
||||||
name = fields.CharField(max_length=100)
|
name = fields.CharField(max_length=100)
|
||||||
|
@ -17,12 +17,12 @@ class BookwyrmGroup(BookWyrmModel):
|
||||||
description = fields.TextField(blank=True, null=True)
|
description = fields.TextField(blank=True, null=True)
|
||||||
privacy = fields.PrivacyField()
|
privacy = fields.PrivacyField()
|
||||||
|
|
||||||
class BookwyrmGroupMember(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(
|
||||||
"BookwyrmGroup",
|
"Group",
|
||||||
on_delete=models.CASCADE,
|
on_delete=models.CASCADE,
|
||||||
related_name="memberships"
|
related_name="memberships"
|
||||||
)
|
)
|
||||||
|
@ -53,7 +53,7 @@ class BookwyrmGroupMember(models.Model):
|
||||||
)
|
)
|
||||||
).exists():
|
).exists():
|
||||||
raise IntegrityError()
|
raise IntegrityError()
|
||||||
# accepts and requests are handled by the BookwyrmGroupInvitation model
|
# accepts and requests are handled by the GroupInvitation model
|
||||||
super().save(*args, **kwargs)
|
super().save(*args, **kwargs)
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
|
@ -74,7 +74,7 @@ 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(
|
||||||
"BookwyrmGroup",
|
"Group",
|
||||||
on_delete=models.CASCADE,
|
on_delete=models.CASCADE,
|
||||||
related_name="user_invitations"
|
related_name="user_invitations"
|
||||||
)
|
)
|
||||||
|
@ -94,7 +94,7 @@ class GroupMemberInvitation(models.Model):
|
||||||
"""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 BookwyrmGroupMember.objects.filter(
|
if GroupMember.objects.filter(
|
||||||
user=self.user,
|
user=self.user,
|
||||||
group=self.group
|
group=self.group
|
||||||
).exists():
|
).exists():
|
||||||
|
@ -131,7 +131,7 @@ class GroupMemberInvitation(models.Model):
|
||||||
"""turn this request into the real deal"""
|
"""turn this request into the real deal"""
|
||||||
|
|
||||||
with transaction.atomic():
|
with transaction.atomic():
|
||||||
BookwyrmGroupMember.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
|
||||||
|
|
|
@ -35,7 +35,7 @@ class List(OrderedCollectionMixin, BookWyrmModel):
|
||||||
max_length=255, default="closed", choices=CurationType.choices
|
max_length=255, default="closed", choices=CurationType.choices
|
||||||
)
|
)
|
||||||
group = models.ForeignKey(
|
group = models.ForeignKey(
|
||||||
"BookwyrmGroup",
|
"Group",
|
||||||
on_delete=models.PROTECT,
|
on_delete=models.PROTECT,
|
||||||
default=None,
|
default=None,
|
||||||
blank=True,
|
blank=True,
|
||||||
|
|
|
@ -23,7 +23,7 @@ class Notification(BookWyrmModel):
|
||||||
"User", on_delete=models.CASCADE, null=True, related_name="related_group_member"
|
"User", on_delete=models.CASCADE, null=True, related_name="related_group_member"
|
||||||
)
|
)
|
||||||
related_group = models.ForeignKey(
|
related_group = models.ForeignKey(
|
||||||
"BookwyrmGroup", on_delete=models.CASCADE, null=True, related_name="notifications"
|
"Group", on_delete=models.CASCADE, null=True, related_name="notifications"
|
||||||
)
|
)
|
||||||
related_status = models.ForeignKey("Status", on_delete=models.CASCADE, null=True)
|
related_status = models.ForeignKey("Status", on_delete=models.CASCADE, null=True)
|
||||||
related_import = models.ForeignKey("ImportJob", on_delete=models.CASCADE, null=True)
|
related_import = models.ForeignKey("ImportJob", on_delete=models.CASCADE, null=True)
|
||||||
|
|
|
@ -143,11 +143,6 @@ class User(OrderedCollectionPageMixin, AbstractUser):
|
||||||
property_fields = [("following_link", "following")]
|
property_fields = [("following_link", "following")]
|
||||||
field_tracker = FieldTracker(fields=["name", "avatar"])
|
field_tracker = FieldTracker(fields=["name", "avatar"])
|
||||||
|
|
||||||
# @property
|
|
||||||
# def bookwyrm_groups(self):
|
|
||||||
# group_ids = bookwyrm_group_membership.values_list("user", flat=True)
|
|
||||||
# return BookwyrmGroup.objects.in_bulk(group_ids).values()
|
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def confirmation_link(self):
|
def confirmation_link(self):
|
||||||
"""helper for generating confirmation links"""
|
"""helper for generating confirmation links"""
|
||||||
|
|
|
@ -37,6 +37,6 @@
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
{% else %}
|
{% else %}
|
||||||
<div >
|
<div >
|
||||||
No potential members found for "{{ query }}"
|
<p>No potential members found for "{{ query }}"</p>
|
||||||
</div>
|
</div>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
|
|
@ -10,13 +10,13 @@ register = template.Library()
|
||||||
def has_groups(user):
|
def has_groups(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.BookwyrmGroupMember.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.BookwyrmGroupMember.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):
|
||||||
|
|
|
@ -253,7 +253,7 @@ 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.BookwyrmGroup.as_view(), name="group"),
|
re_path(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"^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(r"^remove-group-member/?$", views.remove_member, name="remove-group-member"),
|
||||||
|
|
|
@ -32,7 +32,7 @@ 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 BookwyrmGroup, 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,13 +18,13 @@ 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 BookwyrmGroup(View):
|
class Group(View):
|
||||||
"""group page"""
|
"""group page"""
|
||||||
|
|
||||||
def get(self, request, group_id):
|
def get(self, request, group_id):
|
||||||
"""display a group"""
|
"""display a group"""
|
||||||
|
|
||||||
group = get_object_or_404(models.BookwyrmGroup, id=group_id)
|
group = get_object_or_404(models.Group, id=group_id)
|
||||||
lists = models.List.objects.filter(group=group).order_by("-updated_date")
|
lists = models.List.objects.filter(group=group).order_by("-updated_date")
|
||||||
lists = privacy_filter(request.user, lists)
|
lists = privacy_filter(request.user, lists)
|
||||||
|
|
||||||
|
@ -43,7 +43,7 @@ class BookwyrmGroup(View):
|
||||||
@method_decorator(login_required, name="dispatch")
|
@method_decorator(login_required, name="dispatch")
|
||||||
def post(self, request, group_id):
|
def post(self, request, group_id):
|
||||||
"""edit a group"""
|
"""edit a group"""
|
||||||
user_group = get_object_or_404(models.BookwyrmGroup, id=group_id)
|
user_group = get_object_or_404(models.Group, id=group_id)
|
||||||
form = forms.GroupForm(request.POST, instance=user_group)
|
form = forms.GroupForm(request.POST, instance=user_group)
|
||||||
if not form.is_valid():
|
if not form.is_valid():
|
||||||
return redirect("group", user_group.id)
|
return redirect("group", user_group.id)
|
||||||
|
@ -57,7 +57,7 @@ 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.BookwyrmGroupMember.objects.filter(user=user).all()
|
memberships = models.GroupMember.objects.filter(user=user).all()
|
||||||
paginated = Paginator(memberships, 12)
|
paginated = Paginator(memberships, 12)
|
||||||
|
|
||||||
data = {
|
data = {
|
||||||
|
@ -78,7 +78,7 @@ class UserGroups(View):
|
||||||
return redirect(request.user.local_path + "groups")
|
return redirect(request.user.local_path + "groups")
|
||||||
group = form.save()
|
group = form.save()
|
||||||
# add the creator as a group member
|
# add the creator as a group member
|
||||||
models.BookwyrmGroupMember.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")
|
||||||
|
@ -89,7 +89,7 @@ class FindUsers(View):
|
||||||
def get(self, request, group_id):
|
def get(self, request, group_id):
|
||||||
"""basic profile info"""
|
"""basic profile info"""
|
||||||
query = request.GET.get("query")
|
query = request.GET.get("query")
|
||||||
group = models.BookwyrmGroup.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
|
||||||
|
@ -112,7 +112,7 @@ class FindUsers(View):
|
||||||
request.user
|
request.user
|
||||||
)
|
)
|
||||||
|
|
||||||
group = get_object_or_404(models.BookwyrmGroup, id=group_id)
|
group = get_object_or_404(models.Group, id=group_id)
|
||||||
|
|
||||||
if not group:
|
if not group:
|
||||||
return HttpResponseBadRequest()
|
return HttpResponseBadRequest()
|
||||||
|
@ -133,7 +133,7 @@ class FindUsers(View):
|
||||||
def invite_member(request):
|
def invite_member(request):
|
||||||
"""invite a member to the group"""
|
"""invite a member to the group"""
|
||||||
|
|
||||||
group = get_object_or_404(models.BookwyrmGroup, id=request.POST.get("group"))
|
group = get_object_or_404(models.Group, id=request.POST.get("group"))
|
||||||
if not group:
|
if not group:
|
||||||
return HttpResponseBadRequest()
|
return HttpResponseBadRequest()
|
||||||
|
|
||||||
|
@ -160,7 +160,7 @@ def invite_member(request):
|
||||||
def remove_member(request):
|
def remove_member(request):
|
||||||
"""remove a member from the group"""
|
"""remove a member from the group"""
|
||||||
|
|
||||||
group = get_object_or_404(models.BookwyrmGroup, id=request.POST.get("group"))
|
group = get_object_or_404(models.Group, id=request.POST.get("group"))
|
||||||
if not group:
|
if not group:
|
||||||
return HttpResponseBadRequest()
|
return HttpResponseBadRequest()
|
||||||
|
|
||||||
|
@ -168,7 +168,7 @@ def remove_member(request):
|
||||||
if not user:
|
if not user:
|
||||||
return HttpResponseBadRequest()
|
return HttpResponseBadRequest()
|
||||||
|
|
||||||
is_member = models.BookwyrmGroupMember.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:
|
||||||
|
@ -186,13 +186,13 @@ def remove_member(request):
|
||||||
if is_member:
|
if is_member:
|
||||||
|
|
||||||
try:
|
try:
|
||||||
membership = models.BookwyrmGroupMember.objects.get(group=group,user=user)
|
membership = models.GroupMember.objects.get(group=group,user=user)
|
||||||
membership.delete()
|
membership.delete()
|
||||||
|
|
||||||
except IntegrityError:
|
except IntegrityError:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
memberships = models.BookwyrmGroupMember.objects.filter(group=group)
|
memberships = models.GroupMember.objects.filter(group=group)
|
||||||
model = apps.get_model("bookwyrm.Notification", require_ready=True)
|
model = apps.get_model("bookwyrm.Notification", require_ready=True)
|
||||||
notification_type = "LEAVE" if "self_removal" in request.POST and request.POST["self_removal"] else "REMOVE"
|
notification_type = "LEAVE" if "self_removal" in request.POST and request.POST["self_removal"] else "REMOVE"
|
||||||
# let the other members know about it
|
# let the other members know about it
|
||||||
|
@ -221,7 +221,7 @@ def remove_member(request):
|
||||||
def accept_membership(request):
|
def accept_membership(request):
|
||||||
"""accept an invitation to join a group"""
|
"""accept an invitation to join a group"""
|
||||||
|
|
||||||
group = models.BookwyrmGroup.objects.get(id=request.POST["group"])
|
group = models.Group.objects.get(id=request.POST["group"])
|
||||||
if not group:
|
if not group:
|
||||||
return HttpResponseBadRequest()
|
return HttpResponseBadRequest()
|
||||||
|
|
||||||
|
@ -242,7 +242,7 @@ def accept_membership(request):
|
||||||
def reject_membership(request):
|
def reject_membership(request):
|
||||||
"""reject an invitation to join a group"""
|
"""reject an invitation to join a group"""
|
||||||
|
|
||||||
group = models.BookwyrmGroup.objects.get(id=request.POST["group"])
|
group = models.Group.objects.get(id=request.POST["group"])
|
||||||
if not group:
|
if not group:
|
||||||
return HttpResponseBadRequest()
|
return HttpResponseBadRequest()
|
||||||
|
|
||||||
|
|
|
@ -140,7 +140,7 @@ class Groups(View):
|
||||||
user = get_user_from_username(request.user, username)
|
user = get_user_from_username(request.user, username)
|
||||||
|
|
||||||
paginated = Paginator(
|
paginated = Paginator(
|
||||||
models.BookwyrmGroup.memberships.filter(user=user)
|
models.Group.memberships.filter(user=user)
|
||||||
)
|
)
|
||||||
data = {
|
data = {
|
||||||
"user": user,
|
"user": user,
|
||||||
|
|
Loading…
Reference in a new issue