fix reverse reference to user bookwyrm_groups

This commit is contained in:
Hugh Rundle 2021-09-28 18:53:11 +10:00
parent fb823189a0
commit 66494e7788
6 changed files with 28 additions and 7 deletions

View file

@ -21,7 +21,7 @@ class Group(BookWyrmModel):
symmetrical=False,
through="GroupMember",
through_fields=("group", "user"),
related_name="members"
related_name="bookwyrm_groups"
)
def get_remote_id(self):

View file

@ -3,7 +3,7 @@
{% load interaction %}
<div class="columns is-multiline">
{% for group in groups %}
{% for group in user.bookwyrm_groups.all %}
<div class="column is-one-quarter">
<div class="card is-stretchable">
<header class="card-header">

View file

@ -34,7 +34,7 @@
{% include 'groups/form.html' %}
</form>
{% include 'groups/user_groups.html' with groups=groups %}
{% include 'groups/user_groups.html' %}
</section>
<div>
{% include 'snippets/pagination.html' with page=user_groups path=path %}

View file

@ -75,7 +75,7 @@
<a href="{{ url }}">{% trans "Lists" %}</a>
</li>
{% endif %}
{% if is_self or has_groups %}
{% if is_self or user.bookwyrm_groups %}
{% url 'user-groups' user|username as url %}
<li{% if url in request.path %} class="is-active"{% endif %}>
<a href="{{ url }}">{% trans "Groups" %}</a>

View file

@ -22,6 +22,9 @@
{% block panel %}
{% if user.bookwyrm_user %}
{% for group in user.bookwyrm_groups.all %}
<div>{{ group.name }}</div>
{% endfor %}
<div class="block">
<h2 class="title">
{% include 'user/shelf/books_header.html' %}

View file

@ -1,4 +1,5 @@
"""group views"""
from django.apps import apps
from django.contrib.auth.decorators import login_required
from django.db import IntegrityError
from django.core.paginator import Paginator
@ -62,8 +63,6 @@ class UserGroups(View):
data = {
"user": user,
"has_groups": models.GroupMember.objects.filter(user=user).exists(),
"groups": paginated.get_page(request.GET.get("page")),
"group_form": forms.GroupForm(),
"path": user.local_path + "/group",
}
@ -144,6 +143,21 @@ def add_member(request):
except IntegrityError:
pass
# TODO: actually this needs to be associated with the user ACCEPTING AN INVITE!!! DOH!
"""create a notification too"""
# notify all team members when a user is added to the group
model = apps.get_model("bookwyrm.Notification", require_ready=True)
for team_member in group.members.all():
if team_member.local and team_member != request.user:
model.objects.create(
user=team_member,
related_user=request.user,
related_group_member=user,
related_group=group,
notification_type="ADD",
)
return redirect(user.local_path)
@require_POST
@ -151,8 +165,12 @@ def add_member(request):
def remove_member(request):
"""remove a member from the group"""
# TODO: send notification to user telling them they have been removed
# TODO: remove yourself from a group!!!! (except owner)
# FUTURE TODO: transfer ownership of group
# TODO: if groups become AP values we need something like get_group_from_group_fullname
# group = get_object_or_404(models.Group, id=request.POST.get("group"))
# group = get_object_or_404(models.Group, id=request.POST.get("group")) # NOTE: does this not work?
group = models.Group.objects.get(id=request.POST["group"])
if not group:
return HttpResponseBadRequest()