mirror of
https://github.com/bookwyrm-social/bookwyrm.git
synced 2024-11-26 19:41:11 +00:00
List add notifications
This commit is contained in:
parent
41f42e33ed
commit
8cbf8f62c7
3 changed files with 111 additions and 30 deletions
|
@ -150,7 +150,7 @@ class ListItem(CollectionItemMixin, BookWyrmModel):
|
|||
collection_field = "book_list"
|
||||
|
||||
def save(self, *args, **kwargs):
|
||||
"""create a notification too"""
|
||||
"""Update the list's date"""
|
||||
super().save(*args, **kwargs)
|
||||
# tick the updated date on the parent list
|
||||
self.book_list.updated_date = timezone.now()
|
||||
|
|
|
@ -66,6 +66,27 @@ class Notification(BookWyrmModel):
|
|||
notification.read = False
|
||||
notification.save()
|
||||
|
||||
@classmethod
|
||||
@transaction.atomic
|
||||
def notify_list_item(cls, user, list_item):
|
||||
""" Group the notifications around the list items, not the user """
|
||||
related_user = list_item.user
|
||||
notification = cls.objects.filter(
|
||||
user=user,
|
||||
related_users=related_user,
|
||||
related_list_items__book_list=list_item.book_list,
|
||||
notification_type=Notification.ADD
|
||||
).first()
|
||||
if not notification:
|
||||
notification = cls.objects.create(
|
||||
user=user,
|
||||
notification_type=Notification.ADD
|
||||
)
|
||||
notification.related_users.add(related_user)
|
||||
notification.related_list_items.add(list_item)
|
||||
notification.read = False
|
||||
notification.save()
|
||||
|
||||
@classmethod
|
||||
def unnotify(cls, user, related_user, **kwargs):
|
||||
"""Remove a user from a notification and delete it if that was the only user"""
|
||||
|
@ -79,7 +100,6 @@ class Notification(BookWyrmModel):
|
|||
|
||||
|
||||
@receiver(models.signals.post_save, sender=Favorite)
|
||||
@transaction.atomic()
|
||||
# pylint: disable=unused-argument
|
||||
def notify_on_fav(sender, instance, *args, **kwargs):
|
||||
"""someone liked your content, you ARE loved"""
|
||||
|
@ -144,7 +164,6 @@ def notify_user_on_mention(sender, instance, *args, **kwargs):
|
|||
|
||||
|
||||
@receiver(models.signals.post_save, sender=Boost)
|
||||
@transaction.atomic
|
||||
# pylint: disable=unused-argument
|
||||
def notify_user_on_boost(sender, instance, *args, **kwargs):
|
||||
"""boosting a status"""
|
||||
|
@ -210,7 +229,6 @@ def notify_admins_on_report(sender, instance, *args, **kwargs):
|
|||
|
||||
|
||||
@receiver(models.signals.post_save, sender=GroupMemberInvitation)
|
||||
@transaction.atomic
|
||||
# pylint: disable=unused-argument
|
||||
def notify_user_on_group_invite(sender, instance, *args, **kwargs):
|
||||
"""Cool kids club here we come"""
|
||||
|
@ -233,19 +251,16 @@ def notify_user_on_list_item_add(sender, instance, created, *args, **kwargs):
|
|||
list_owner = instance.book_list.user
|
||||
# create a notification if somoene ELSE added to a local user's list
|
||||
if list_owner.local and list_owner != instance.user:
|
||||
Notification.notify(
|
||||
# keep the related_user singular, group the items
|
||||
Notification.notify_list_item(
|
||||
list_owner,
|
||||
instance.user,
|
||||
related_list_item=instance,
|
||||
notification_type=Notification.ADD
|
||||
instance
|
||||
)
|
||||
|
||||
if instance.book_list.group:
|
||||
for membership in instance.book_list.group.memberships.all():
|
||||
if membership.user != instance.user:
|
||||
Notification.notify(
|
||||
Notification.notify_list_item(
|
||||
membership.user,
|
||||
instance.user,
|
||||
related_list_item=instance,
|
||||
notification_type=Notification.ADD,
|
||||
instance
|
||||
)
|
||||
|
|
|
@ -1,14 +1,16 @@
|
|||
{% extends 'notifications/items/layout.html' %}
|
||||
|
||||
{% load i18n %}
|
||||
{% load utilities %}
|
||||
{% load humanize %}
|
||||
|
||||
{% block primary_link %}{% spaceless %}
|
||||
{% if notification.related_list_item.approved %}
|
||||
{{ notification.related_list_item.book_list.local_path }}
|
||||
{% with related_list=notification.related_list_items.first.book_list %}
|
||||
{% if related_list.curation != "curated" %}
|
||||
{{ related_list.local_path }}
|
||||
{% else %}
|
||||
{% url 'list-curate' notification.related_list_item.book_list.id %}
|
||||
{% url 'list-curate' related_list.id %}
|
||||
{% endif %}
|
||||
{% endwith %}
|
||||
{% endspaceless %}{% endblock %}
|
||||
|
||||
{% block icon %}
|
||||
|
@ -16,25 +18,89 @@
|
|||
{% endblock %}
|
||||
|
||||
{% block description %}
|
||||
{% with book_path=notification.related_list_item.book.local_path %}
|
||||
{% with book_title=notification.related_list_item.book|book_title %}
|
||||
{% with list_name=notification.related_list_item.book_list.name %}
|
||||
{% with related_list=notification.related_list_items.first.book_list %}
|
||||
{% with book_path=notification.related_list_items.first.book.local_path %}
|
||||
{% with book_title=notification.related_list_items.first.book|book_title %}
|
||||
{% with second_book_path=notification.related_list_items.all.1.book.local_path %}
|
||||
{% with second_book_title=notification.related_list_items.all.1.book|book_title %}
|
||||
{% with list_name=related_list.name %}
|
||||
|
||||
{% if notification.related_list_item.approved %}
|
||||
{% blocktrans trimmed with list_path=notification.related_list_item.book_list.local_path %}
|
||||
{% url 'list' related_list.id as list_path %}
|
||||
{% url 'list-curate' related_list.id as list_curate_path %}
|
||||
|
||||
added <em><a href="{{ book_path }}">{{ book_title }}</a></em> to your list "<a href="{{ list_path }}">{{ list_name }}</a>"
|
||||
|
||||
{% endblocktrans %}
|
||||
{% if notification.related_list_items.count == 1 %}
|
||||
{% if related_list.curation != "curated" %}
|
||||
{% blocktrans trimmed %}
|
||||
<a href="{{ related_user_link }}">{{ related_user }}</a>
|
||||
added <em><a href="{{ book_path }}">{{ book_title }}</a></em>
|
||||
to your list "<a href="{{ list_path }}">{{ list_name }}</a>"
|
||||
{% endblocktrans %}
|
||||
{% else %}
|
||||
{% url 'list-curate' notification.related_list_item.book_list.id as list_path %}
|
||||
{% blocktrans trimmed with list_path=list_path %}
|
||||
|
||||
suggested adding <em><a href="{{ book_path }}">{{ book_title }}</a></em> to your list "<a href="{{ list_path }}">{{ list_name }}</a>"
|
||||
|
||||
{% endblocktrans %}
|
||||
{% blocktrans trimmed %}
|
||||
<a href="{{ related_user_link }}">{{ related_user }}</a>
|
||||
suggested adding <em><a href="{{ book_path }}">{{ book_title }}</a></em>
|
||||
to your list "<a href="{{ list_curate_path }}">{{ list_name }}</a>"
|
||||
{% endblocktrans %}
|
||||
{% endif %}
|
||||
{% elif notification.related_list_items.count == 2 %}
|
||||
{% if related_list.curation != "curated" %}
|
||||
{% blocktrans trimmed %}
|
||||
<a href="{{ related_user_link }}">{{ related_user }}</a>
|
||||
added <em><a href="{{ book_path }}">{{ book_title }}</a></em>
|
||||
and <em><a href="{{ second_book_path }}">{{ second_book_title }}</a></em>
|
||||
to your list "<a href="{{ list_path }}">{{ list_name }}</a>"
|
||||
{% endblocktrans %}
|
||||
{% else %}
|
||||
{% blocktrans trimmed %}
|
||||
<a href="{{ related_user_link }}">{{ related_user }}</a>
|
||||
suggested adding <em><a href="{{ book_path }}">{{ book_title }}</a></em>
|
||||
and <em><a href="{{ second_book_path }}">{{ second_book_title }}</a></em>
|
||||
to your list "<a href="{{ list_curate_path }}">{{ list_name }}</a>"
|
||||
{% endblocktrans %}
|
||||
{% endif %}
|
||||
{% else %}
|
||||
{% with count=notification.related_list_items.count|add:"-2" %}
|
||||
{% with display_count=count|intcomma %}
|
||||
{% if related_list.curation != "curated" %}
|
||||
|
||||
{% blocktrans trimmed count counter=count %}
|
||||
<a href="{{ related_user_link }}">{{ related_user }}</a>
|
||||
added <em><a href="{{ book_path }}">{{ book_title }}</a></em>,
|
||||
<em><a href="{{ second_book_path }}">{{ second_book_title }}</a></em>,
|
||||
and {{ display_count }} other book
|
||||
to your list "<a href="{{ list_path }}">{{ list_name }}</a>"
|
||||
{% plural %}
|
||||
<a href="{{ related_user_link }}">{{ related_user }}</a>
|
||||
added <em><a href="{{ book_path }}">{{ book_title }}</a></em>,
|
||||
<em><a href="{{ second_book_path }}">{{ second_book_title }}</a></em>,
|
||||
and {{ display_count }} other books
|
||||
to your list "<a href="{{ list_path }}">{{ list_name }}</a>"
|
||||
{% endblocktrans %}
|
||||
|
||||
{% else %}
|
||||
|
||||
{% blocktrans trimmed count counter=count %}
|
||||
<a href="{{ related_user_link }}">{{ related_user }}</a>
|
||||
suggested adding <em><a href="{{ book_path }}">{{ book_title }}</a></em>,
|
||||
<em><a href="{{ second_book_path }}">{{ second_book_title }}</a></em>,
|
||||
and {{ display_count }} other book
|
||||
to your list "<a href="{{ list_curate_path }}">{{ list_name }}</a>"
|
||||
{% plural %}
|
||||
<a href="{{ related_user_link }}">{{ related_user }}</a>
|
||||
suggested adding <em><a href="{{ book_path }}">{{ book_title }}</a></em>,
|
||||
<em><a href="{{ second_book_path }}">{{ second_book_title }}</a></em>,
|
||||
and {{ display_count }} other books
|
||||
to your list "<a href="{{ list_curate_path }}">{{ list_name }}</a>"
|
||||
{% endblocktrans %}
|
||||
|
||||
{% endif %}
|
||||
{% endwith %}
|
||||
{% endwith %}
|
||||
{% endif %}
|
||||
|
||||
{% endwith %}
|
||||
{% endwith %}
|
||||
{% endwith %}
|
||||
{% endwith %}
|
||||
{% endwith %}
|
||||
{% endwith %}
|
||||
|
|
Loading…
Reference in a new issue