fix reverse reference to user bookwyrm_groups
This commit is contained in:
parent
fb823189a0
commit
66494e7788
|
@ -21,7 +21,7 @@ class Group(BookWyrmModel):
|
||||||
symmetrical=False,
|
symmetrical=False,
|
||||||
through="GroupMember",
|
through="GroupMember",
|
||||||
through_fields=("group", "user"),
|
through_fields=("group", "user"),
|
||||||
related_name="members"
|
related_name="bookwyrm_groups"
|
||||||
)
|
)
|
||||||
|
|
||||||
def get_remote_id(self):
|
def get_remote_id(self):
|
||||||
|
|
|
@ -3,7 +3,7 @@
|
||||||
{% load interaction %}
|
{% load interaction %}
|
||||||
|
|
||||||
<div class="columns is-multiline">
|
<div class="columns is-multiline">
|
||||||
{% for group in groups %}
|
{% for group in user.bookwyrm_groups.all %}
|
||||||
<div class="column is-one-quarter">
|
<div class="column is-one-quarter">
|
||||||
<div class="card is-stretchable">
|
<div class="card is-stretchable">
|
||||||
<header class="card-header">
|
<header class="card-header">
|
||||||
|
|
|
@ -34,7 +34,7 @@
|
||||||
{% include 'groups/form.html' %}
|
{% include 'groups/form.html' %}
|
||||||
</form>
|
</form>
|
||||||
|
|
||||||
{% include 'groups/user_groups.html' with groups=groups %}
|
{% include 'groups/user_groups.html' %}
|
||||||
</section>
|
</section>
|
||||||
<div>
|
<div>
|
||||||
{% include 'snippets/pagination.html' with page=user_groups path=path %}
|
{% include 'snippets/pagination.html' with page=user_groups path=path %}
|
||||||
|
|
|
@ -75,7 +75,7 @@
|
||||||
<a href="{{ url }}">{% trans "Lists" %}</a>
|
<a href="{{ url }}">{% trans "Lists" %}</a>
|
||||||
</li>
|
</li>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
{% if is_self or has_groups %}
|
{% if is_self or user.bookwyrm_groups %}
|
||||||
{% url 'user-groups' user|username as url %}
|
{% url 'user-groups' user|username as url %}
|
||||||
<li{% if url in request.path %} class="is-active"{% endif %}>
|
<li{% if url in request.path %} class="is-active"{% endif %}>
|
||||||
<a href="{{ url }}">{% trans "Groups" %}</a>
|
<a href="{{ url }}">{% trans "Groups" %}</a>
|
||||||
|
|
|
@ -22,6 +22,9 @@
|
||||||
|
|
||||||
{% block panel %}
|
{% block panel %}
|
||||||
{% if user.bookwyrm_user %}
|
{% if user.bookwyrm_user %}
|
||||||
|
{% for group in user.bookwyrm_groups.all %}
|
||||||
|
<div>{{ group.name }}</div>
|
||||||
|
{% endfor %}
|
||||||
<div class="block">
|
<div class="block">
|
||||||
<h2 class="title">
|
<h2 class="title">
|
||||||
{% include 'user/shelf/books_header.html' %}
|
{% include 'user/shelf/books_header.html' %}
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
"""group views"""
|
"""group views"""
|
||||||
|
from django.apps import apps
|
||||||
from django.contrib.auth.decorators import login_required
|
from django.contrib.auth.decorators import login_required
|
||||||
from django.db import IntegrityError
|
from django.db import IntegrityError
|
||||||
from django.core.paginator import Paginator
|
from django.core.paginator import Paginator
|
||||||
|
@ -62,8 +63,6 @@ class UserGroups(View):
|
||||||
|
|
||||||
data = {
|
data = {
|
||||||
"user": user,
|
"user": user,
|
||||||
"has_groups": models.GroupMember.objects.filter(user=user).exists(),
|
|
||||||
"groups": paginated.get_page(request.GET.get("page")),
|
|
||||||
"group_form": forms.GroupForm(),
|
"group_form": forms.GroupForm(),
|
||||||
"path": user.local_path + "/group",
|
"path": user.local_path + "/group",
|
||||||
}
|
}
|
||||||
|
@ -144,6 +143,21 @@ def add_member(request):
|
||||||
except IntegrityError:
|
except IntegrityError:
|
||||||
pass
|
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)
|
return redirect(user.local_path)
|
||||||
|
|
||||||
@require_POST
|
@require_POST
|
||||||
|
@ -151,8 +165,12 @@ def add_member(request):
|
||||||
def remove_member(request):
|
def remove_member(request):
|
||||||
"""remove a member from the group"""
|
"""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
|
# 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"])
|
group = models.Group.objects.get(id=request.POST["group"])
|
||||||
if not group:
|
if not group:
|
||||||
return HttpResponseBadRequest()
|
return HttpResponseBadRequest()
|
||||||
|
|
Loading…
Reference in New Issue