Merge pull request #226 from Gluejar/library_notifications

notifications when user joins library or user borrows a book [#59238164][#59238032]
pull/1/head
Raymond Yee 2013-10-31 09:39:08 -07:00
commit b8150ad651
9 changed files with 104 additions and 1 deletions

View File

@ -332,11 +332,13 @@ class Acq(models.Model):
self.license=BORROWED self.license=BORROWED
self.expire_in(timedelta(days=14)) self.expire_in(timedelta(days=14))
self.user.wishlist.add_work( self.work, "borrow") self.user.wishlist.add_work( self.work, "borrow")
notification.send([self.user], "library_borrow", {'acq':self})
return self return self
elif self.borrowable and user: elif self.borrowable and user:
user.wishlist.add_work( self.work, "borrow") user.wishlist.add_work( self.work, "borrow")
borrowed = Acq.objects.create(user=user,work=self.work,license= BORROWED, lib_acq=self) borrowed = Acq.objects.create(user=user,work=self.work,license= BORROWED, lib_acq=self)
from regluit.core.tasks import watermark_acq from regluit.core.tasks import watermark_acq
notification.send([user], "library_borrow", {'acq':borrowed})
watermark_acq.delay(borrowed) watermark_acq.delay(borrowed)
return borrowed return borrowed

View File

@ -32,7 +32,7 @@ regluit imports
from regluit.payment.signals import transaction_charged, transaction_failed, pledge_modified, pledge_created from regluit.payment.signals import transaction_charged, transaction_failed, pledge_modified, pledge_created
from regluit.utils.localdatetime import now from regluit.utils.localdatetime import now
from regluit.core.parameters import REWARDS, BUY2UNGLUE, LIBRARY, RESERVE 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__) 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_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("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("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) 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() emit_notifications.delay()
supporter_message.connect(notify_supporter_message) 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)

View File

@ -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

View File

@ -0,0 +1,19 @@
{% extends "notification/notice_template.html" %}
{% block comments_book %}
<a href="{% url work acq.work.id %}"><img src="{{ acq.work.cover_image_small }}" alt="cover image for {{ acq.work.title }}" /></a>
{% 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 <a href="{% url download acq.work.id %}">the book's download page.</a>
{% endblock %}
{% block comments_textual %}
<p>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.</p>
<p>For more information about the book, visit the visit the <a href="{% url work acq.work.id %}">book's unglue.it page</a>.
</p>
<p>{{ acq.lib_acq.user.username }} and the Unglue.it team
</p>
{% endblock %}

View File

@ -0,0 +1 @@
You have borrowed {{ acq.work.title }} from {{ acq.lib_acq.user.username }}

View File

@ -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

View File

@ -0,0 +1,20 @@
{% extends "notification/notice_template.html" %}
{% block comments_book %}
<a href="{% url library library %}"><img src="{{ library.user.profile.avatar_url }}" alt="avatar for {{ library }}" /></a>
{% endblock %}
{% block comments_graphical %}
Your request to join {{ library }} has been accepted. Welcome!
{% endblock %}
{% block comments_textual %}
<p>{{ library }} is participating in Unglue.it. That means you can borrow Unglue.it ebooks owned by {{ library }} (when available). Here's <a href="{% url library library %}">a list of the ebooks available</a> to {{ library }} members. <p>
<p>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 }}. </p>
<p> 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.</p>
<p>{{ library.username }} and the Unglue.it team
</p>
{% endblock %}

View File

@ -0,0 +1 @@
{{ user.username }} has joined {{ library }}

View File

@ -163,6 +163,32 @@ $j(document).ready(function() {
<td colspan="2" id="last"><input type="submit" value="{% trans 'Change' %}"></input></td> <td colspan="2" id="last"><input type="submit" value="{% trans 'Change' %}"></input></td>
</tr> </tr>
</table> </table>
<h3>Library Notifications</h3>
<table class="notice_settings table table-striped" width="90%">
<tr>
<th>{% trans "Notify me when..." %}</th>
{% for header in notice_settings.column_headers %}
<th>{{ header }}</th>
{% endfor %}
</tr>
{% for row in notice_settings.rows %}
{% if row.notice_type.label|truncatechars:11 == 'library_...' %}
<tr class="{% cycle 'row1' 'row2' %}">
<td>
<span class="notice_type_description">{% trans row.notice_type.description %}</span>
</td>
{% for cell in row.cells %}
<td>
<input type="checkbox" name="{{ cell.0 }}" {% if cell.1 %}checked="yes"{% endif %}/>
</td>
{% endfor %}
</tr>
{% endif %}
{% endfor %}
<tr>
<td colspan="2" id="last"><input type="submit" value="{% trans 'Change' %}"></input></td>
</tr>
</table>
</form> </form>
<h3>Your mailing list subscription</h3> <h3>Your mailing list subscription</h3>