From c79572e8e4d3c38f179769ea386b03cf435500bb Mon Sep 17 00:00:00 2001 From: eric Date: Thu, 31 Oct 2013 12:26:43 -0400 Subject: [PATCH] notifications when user joins library or user borrows a book --- core/models.py | 2 ++ core/signals.py | 13 +++++++++- .../notification/library_borrow/full.txt | 11 ++++++++ .../notification/library_borrow/notice.html | 19 ++++++++++++++ .../notification/library_borrow/short.txt | 1 + .../notification/library_join/full.txt | 12 +++++++++ .../notification/library_join/notice.html | 20 ++++++++++++++ .../notification/library_join/short.txt | 1 + .../notification/notice_settings.html | 26 +++++++++++++++++++ 9 files changed, 104 insertions(+), 1 deletion(-) create mode 100644 frontend/templates/notification/library_borrow/full.txt create mode 100644 frontend/templates/notification/library_borrow/notice.html create mode 100644 frontend/templates/notification/library_borrow/short.txt create mode 100644 frontend/templates/notification/library_join/full.txt create mode 100644 frontend/templates/notification/library_join/notice.html create mode 100644 frontend/templates/notification/library_join/short.txt diff --git a/core/models.py b/core/models.py index 700f6a5e..71a91f1e 100755 --- a/core/models.py +++ b/core/models.py @@ -332,11 +332,13 @@ class Acq(models.Model): self.license=BORROWED self.expire_in(timedelta(days=14)) self.user.wishlist.add_work( self.work, "borrow") + notification.send([self.user], "library_borrow", {'acq':self}) return self elif self.borrowable and user: user.wishlist.add_work( self.work, "borrow") borrowed = Acq.objects.create(user=user,work=self.work,license= BORROWED, lib_acq=self) from regluit.core.tasks import watermark_acq + notification.send([user], "library_borrow", {'acq':borrowed}) watermark_acq.delay(borrowed) return borrowed diff --git a/core/signals.py b/core/signals.py index dd578337..6db6ec30 100644 --- a/core/signals.py +++ b/core/signals.py @@ -32,7 +32,7 @@ regluit imports from regluit.payment.signals import transaction_charged, transaction_failed, pledge_modified, pledge_created from regluit.utils.localdatetime import now from regluit.core.parameters import REWARDS, BUY2UNGLUE, LIBRARY, RESERVE -from regluit.libraryauth.models import Library +from regluit.libraryauth.models import Library, LibraryUser logger = logging.getLogger(__name__) @@ -118,6 +118,8 @@ def create_notice_types(app, created_models, verbosity, **kwargs): notification.create_notice_type("account_expired", _("Credit Card Has Expired"), _("Your credit card has expired.")) notification.create_notice_type("account_active", _("Credit Card Number Updated"), _("Payment method updated."), default = 1) notification.create_notice_type("purchase_complete", _("Your Purchase is Complete"), _("Your Unglue.it Purchase is Complete.")) + notification.create_notice_type("library_borrow", _("Library eBook Borrowed."), _("You've borrowed an ebook through a Library participating in Unglue.it")) + notification.create_notice_type("library_join", _("New Library User."), _("A library participating in Unglue.it has added a user")) signals.post_syncdb.connect(create_notice_types, sender=notification) @@ -324,3 +326,12 @@ def notify_supporter_message(sender, work, supporter, msg, **kwargs): emit_notifications.delay() supporter_message.connect(notify_supporter_message) + +def notify_join_library(sender, created, instance, **kwargs): + if created: + notification.send((instance.user, instance.library.user), "library_join", { + 'library': instance.library, + 'user': instance.user, + }) + +post_save.connect(notify_join_library, sender=LibraryUser) \ No newline at end of file diff --git a/frontend/templates/notification/library_borrow/full.txt b/frontend/templates/notification/library_borrow/full.txt new file mode 100644 index 00000000..e3e90b08 --- /dev/null +++ b/frontend/templates/notification/library_borrow/full.txt @@ -0,0 +1,11 @@ +You have borrowed {{ acq.work }} from {{ acq.lib_acq.user.username }}. During the borrowing period, you can download the ebook at the book's download page: +https://{{ current_site.domain }}{% url download acq.work.id %} + +This ebook is made available to you by {{ acq.lib_acq.user.username }} for your personal use only, and a personal license has been embedded in the ebook file. You may download as many times as you need to until {{ acq.expires }}. If you want to use the ebook after that, please consider buying a copy for yourself. Doing so will bring closer the day when this ebook is free for everyone to read. + +For more information about the book, visit the visit the book's unglue.it page at +https://{{ current_site.domain }}{% url work acq.work.id %} + +Thank you again for your support. + +{{ acq.lib_acq.user.username }} and the Unglue.it team \ No newline at end of file diff --git a/frontend/templates/notification/library_borrow/notice.html b/frontend/templates/notification/library_borrow/notice.html new file mode 100644 index 00000000..a9af6815 --- /dev/null +++ b/frontend/templates/notification/library_borrow/notice.html @@ -0,0 +1,19 @@ +{% extends "notification/notice_template.html" %} + +{% block comments_book %} + cover image for {{ acq.work.title }} +{% endblock %} + +{% block comments_graphical %} + You have borrowed {{ acq.work }} from {{ acq.lib_acq.user.username }}. During the borrowing period, you can download the ebook at the book's download page. +{% endblock %} + +{% block comments_textual %} + +

This ebook is made available to you by {{ acq.lib_acq.user.username }} for your personal use only, and a personal license has been embedded in the ebook file. You may download as many times as you need to until {{ acq.expires }}. If you want to use the ebook after that, please consider buying a copy for yourself. Doing so will bring closer the day when this ebook is free for everyone to read.

+ +

For more information about the book, visit the visit the book's unglue.it page. +

+

{{ acq.lib_acq.user.username }} and the Unglue.it team +

+{% endblock %} \ No newline at end of file diff --git a/frontend/templates/notification/library_borrow/short.txt b/frontend/templates/notification/library_borrow/short.txt new file mode 100644 index 00000000..ad6fdce4 --- /dev/null +++ b/frontend/templates/notification/library_borrow/short.txt @@ -0,0 +1 @@ +You have borrowed {{ acq.work.title }} from {{ acq.lib_acq.user.username }} \ No newline at end of file diff --git a/frontend/templates/notification/library_join/full.txt b/frontend/templates/notification/library_join/full.txt new file mode 100644 index 00000000..023bf876 --- /dev/null +++ b/frontend/templates/notification/library_join/full.txt @@ -0,0 +1,12 @@ +{{ user.username }}, + +Your request to join {{ library }} has been accepted. Welcome! + +{{ library }} is participating in Unglue.it. That means you can borrow Unglue.it ebooks owned by {{ library }} (when available). A list of the ebooks available to {{ library }} members is available here: +https://{{ current_site.domain }}{% url library library %} + +When you buy an ebook through Unglue.it, you'll be offered the option to by a library license in stead of an individual license. That means that {{ library }} will own the ebook, but you'll be the first in line to borrow it. After two weeks, the book will be available to other members of {{ library }}. + +eBooks available for purchase through Unglue.it will eventually be free to the whole world, for free. Every purchase of a book through Unglue.it brings the "ungluing date" of that book closer to the present. We hope you'll join us in our effort to make these books free. + +{{ library.username }} and the Unglue.it team \ No newline at end of file diff --git a/frontend/templates/notification/library_join/notice.html b/frontend/templates/notification/library_join/notice.html new file mode 100644 index 00000000..30d2ffaf --- /dev/null +++ b/frontend/templates/notification/library_join/notice.html @@ -0,0 +1,20 @@ +{% extends "notification/notice_template.html" %} +{% block comments_book %} + avatar for {{ library }} +{% endblock %} + +{% block comments_graphical %} + Your request to join {{ library }} has been accepted. Welcome! +{% endblock %} + +{% block comments_textual %} + +

{{ library }} is participating in Unglue.it. That means you can borrow Unglue.it ebooks owned by {{ library }} (when available). Here's a list of the ebooks available to {{ library }} members.

+ +

When you buy an ebook through unglue.it, you'll be offered the option to by a library license in stead of an individual license. That means that {{ library }} will own the ebook, but you'll be the first in line to borrow it. After two weeks, the book will be available to other members of {{ library }}.

+ +

eBooks available for purchase through Unglue.it will eventually be free to the whole world, for free. Every purchase of a book through Unglue.it brings the "ungluing date" of that book closer to the present. We hope you'll join us in our effort to make these books free.

+ +

{{ library.username }} and the Unglue.it team +

+{% endblock %} \ No newline at end of file diff --git a/frontend/templates/notification/library_join/short.txt b/frontend/templates/notification/library_join/short.txt new file mode 100644 index 00000000..f26d987d --- /dev/null +++ b/frontend/templates/notification/library_join/short.txt @@ -0,0 +1 @@ +{{ user.username }} has joined {{ library }} \ No newline at end of file diff --git a/frontend/templates/notification/notice_settings.html b/frontend/templates/notification/notice_settings.html index 5dc2ed04..18f83ca1 100644 --- a/frontend/templates/notification/notice_settings.html +++ b/frontend/templates/notification/notice_settings.html @@ -163,6 +163,32 @@ $j(document).ready(function() { +

Library Notifications

+ + + + {% for header in notice_settings.column_headers %} + + {% endfor %} + + {% for row in notice_settings.rows %} + {% if row.notice_type.label|truncatechars:11 == 'library_...' %} + + + {% for cell in row.cells %} + + {% endfor %} + + {% endif %} + {% endfor %} + + + +
{% trans "Notify me when..." %}{{ header }}
+ {% trans row.notice_type.description %} + + +

Your mailing list subscription