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:
Hugh Rundle 2021-10-02 16:52:34 +10:00
parent 21e6ed7388
commit 52a083a907
12 changed files with 31 additions and 36 deletions

View file

@ -297,7 +297,7 @@ class ListForm(CustomForm):
class GroupForm(CustomForm):
class Meta:
model = models.BookwyrmGroup
model = models.Group
fields = ["user", "privacy", "name", "description"]
class ReportForm(CustomForm):

View file

@ -21,7 +21,7 @@ from .relationship import UserFollows, UserFollowRequest, UserBlocks
from .report import Report, ReportComment
from .federated_server import FederatedServer
from .group import BookwyrmGroup, BookwyrmGroupMember, GroupMemberInvitation
from .group import Group, GroupMember, GroupMemberInvitation
from .import_job import ImportJob, ImportItem

View file

@ -8,7 +8,7 @@ from . import fields
from .relationship import UserBlocks
# from .user import User
class BookwyrmGroup(BookWyrmModel):
class Group(BookWyrmModel):
"""A group of users"""
name = fields.CharField(max_length=100)
@ -17,12 +17,12 @@ class BookwyrmGroup(BookWyrmModel):
description = fields.TextField(blank=True, null=True)
privacy = fields.PrivacyField()
class BookwyrmGroupMember(models.Model):
class GroupMember(models.Model):
"""Users who are members of a group"""
created_date = models.DateTimeField(auto_now_add=True)
updated_date = models.DateTimeField(auto_now=True)
group = models.ForeignKey(
"BookwyrmGroup",
"Group",
on_delete=models.CASCADE,
related_name="memberships"
)
@ -53,7 +53,7 @@ class BookwyrmGroupMember(models.Model):
)
).exists():
raise IntegrityError()
# accepts and requests are handled by the BookwyrmGroupInvitation model
# accepts and requests are handled by the GroupInvitation model
super().save(*args, **kwargs)
@classmethod
@ -74,7 +74,7 @@ class GroupMemberInvitation(models.Model):
"""adding a user to a group requires manual confirmation"""
created_date = models.DateTimeField(auto_now_add=True)
group = models.ForeignKey(
"BookwyrmGroup",
"Group",
on_delete=models.CASCADE,
related_name="user_invitations"
)
@ -94,7 +94,7 @@ class GroupMemberInvitation(models.Model):
"""make sure the membership doesn't already exist"""
# if there's an invitation for a membership that already exists, accept it
# without changing the local database state
if BookwyrmGroupMember.objects.filter(
if GroupMember.objects.filter(
user=self.user,
group=self.group
).exists():
@ -131,7 +131,7 @@ class GroupMemberInvitation(models.Model):
"""turn this request into the real deal"""
with transaction.atomic():
BookwyrmGroupMember.from_request(self)
GroupMember.from_request(self)
model = apps.get_model("bookwyrm.Notification", require_ready=True)
# tell the group owner

View file

@ -35,7 +35,7 @@ class List(OrderedCollectionMixin, BookWyrmModel):
max_length=255, default="closed", choices=CurationType.choices
)
group = models.ForeignKey(
"BookwyrmGroup",
"Group",
on_delete=models.PROTECT,
default=None,
blank=True,

View file

@ -23,7 +23,7 @@ class Notification(BookWyrmModel):
"User", on_delete=models.CASCADE, null=True, related_name="related_group_member"
)
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_import = models.ForeignKey("ImportJob", on_delete=models.CASCADE, null=True)

View file

@ -143,11 +143,6 @@ class User(OrderedCollectionPageMixin, AbstractUser):
property_fields = [("following_link", "following")]
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
def confirmation_link(self):
"""helper for generating confirmation links"""

View file

@ -37,6 +37,6 @@
{% endfor %}
{% else %}
<div >
No potential members found for "{{ query }}"
<p>No potential members found for "{{ query }}"</p>
</div>
{% endif %}

View file

@ -10,13 +10,13 @@ register = template.Library()
def has_groups(user):
"""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")
def is_member(group, user):
"""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")
def is_invited(group, user):

View file

@ -253,7 +253,7 @@ urlpatterns = [
re_path(r"^hide-suggestions/?$", views.hide_suggestions, name="hide-suggestions"),
# 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"^add-group-member/?$", views.invite_member, name="invite-group-member"),
re_path(r"^remove-group-member/?$", views.remove_member, name="remove-group-member"),

View file

@ -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 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 .inbox import Inbox
from .interaction import Favorite, Unfavorite, Boost, Unboost

View file

@ -18,13 +18,13 @@ from .helpers import privacy_filter
from .helpers import get_user_from_username
from bookwyrm.settings import DOMAIN
class BookwyrmGroup(View):
class Group(View):
"""group page"""
def get(self, request, group_id):
"""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 = privacy_filter(request.user, lists)
@ -43,7 +43,7 @@ class BookwyrmGroup(View):
@method_decorator(login_required, name="dispatch")
def post(self, request, group_id):
"""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)
if not form.is_valid():
return redirect("group", user_group.id)
@ -57,7 +57,7 @@ class UserGroups(View):
def get(self, request, username):
"""display a group"""
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)
data = {
@ -78,7 +78,7 @@ class UserGroups(View):
return redirect(request.user.local_path + "groups")
group = form.save()
# 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)
@method_decorator(login_required, name="dispatch")
@ -89,7 +89,7 @@ class FindUsers(View):
def get(self, request, group_id):
"""basic profile info"""
query = request.GET.get("query")
group = models.BookwyrmGroup.objects.get(id=group_id)
group = models.Group.objects.get(id=group_id)
user_results = (
models.User.viewer_aware_objects(request.user)
.exclude(memberships__in=group.memberships.all()) # don't suggest users who are already members
@ -112,7 +112,7 @@ class FindUsers(View):
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:
return HttpResponseBadRequest()
@ -133,7 +133,7 @@ class FindUsers(View):
def invite_member(request):
"""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:
return HttpResponseBadRequest()
@ -160,7 +160,7 @@ def invite_member(request):
def remove_member(request):
"""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:
return HttpResponseBadRequest()
@ -168,7 +168,7 @@ def remove_member(request):
if not user:
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()
if is_invited:
@ -186,13 +186,13 @@ def remove_member(request):
if is_member:
try:
membership = models.BookwyrmGroupMember.objects.get(group=group,user=user)
membership = models.GroupMember.objects.get(group=group,user=user)
membership.delete()
except IntegrityError:
pass
memberships = models.BookwyrmGroupMember.objects.filter(group=group)
memberships = models.GroupMember.objects.filter(group=group)
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"
# let the other members know about it
@ -221,7 +221,7 @@ def remove_member(request):
def accept_membership(request):
"""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:
return HttpResponseBadRequest()
@ -242,7 +242,7 @@ def accept_membership(request):
def reject_membership(request):
"""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:
return HttpResponseBadRequest()

View file

@ -140,7 +140,7 @@ class Groups(View):
user = get_user_from_username(request.user, username)
paginated = Paginator(
models.BookwyrmGroup.memberships.filter(user=user)
models.Group.memberships.filter(user=user)
)
data = {
"user": user,