diff --git a/badges/badge/models.py b/badges/badge/models.py index 6ec3486..37873f7 100644 --- a/badges/badge/models.py +++ b/badges/badge/models.py @@ -4,6 +4,7 @@ from .db import Badge from .db import Award from .notification_helpers import send_badge_creation_notification +from .notification_helpers import send_badge_published_notification from .notification_helpers import send_badge_awarded_notification @@ -136,6 +137,7 @@ def publish_badge(uri): badge_db.author_uri, reverse('badge_view', args=(badge_db.pk, )), ) + send_badge_published_notification(_badge2dict(badge_db)) return True diff --git a/badges/badge/notification_helpers.py b/badges/badge/notification_helpers.py index 27c447a..7609111 100644 --- a/badges/badge/notification_helpers.py +++ b/badges/badge/notification_helpers.py @@ -15,6 +15,19 @@ def send_badge_creation_notification(badge): context=context ) +def send_badge_published_notification(badge): + subject_template = 'emails/badge_published_subject.txt' + text_template = 'emails/badge_published.txt' + html_template = 'emails/badge_published.html' + context = {'badge': fetch_badge_resources(badge)} + return send_notification_i18n( + badge['author_uri'], + subject_template, + text_template, + html_template, + context=context + ) + def send_badge_awarded_notification(badge, expert_uri): subject_template = 'emails/badge_awarded_subject.txt' diff --git a/badges/badge/views.py b/badges/badge/views.py index c1093b6..67ee0b6 100644 --- a/badges/badge/views.py +++ b/badges/badge/views.py @@ -1,6 +1,6 @@ from django.core.serializers.json import DjangoJSONEncoder from django import http -from django.http import HttpResponse +from django.http import HttpResponse, HttpResponseRedirect from django.shortcuts import render_to_response from django.template import RequestContext from django.core.urlresolvers import reverse @@ -70,6 +70,10 @@ def create(request): @require_login def preview(request, badge_id): badge = badge_api.get_badge(badge_api.id2uri(badge_id)) + + if badge['published_date']: + return HttpResponseRedirect(reverse('badge_view', args=[badge_id])) + fetch_badge_resources(badge) user = request.session['user'] user['is_author'] = _user_is_author(badge, user) diff --git a/badges/badges/settings.py b/badges/badges/settings.py index 99c2247..656bae0 100644 --- a/badges/badges/settings.py +++ b/badges/badges/settings.py @@ -207,4 +207,4 @@ def skip_suspicious_operations(record): ################################################################# MANDRILL_API_KEY = "" EMAIL_BACKEND = "djrill.mail.backends.djrill.DjrillBackend" -DEFAULT_FROM_EMAIL = "badges@p2pu.org" \ No newline at end of file +DEFAULT_FROM_EMAIL = "P2PU team " \ No newline at end of file diff --git a/badges/dashboard/templatetags/projects_tags.py b/badges/dashboard/templatetags/projects_tags.py index f37770a..5286906 100644 --- a/badges/dashboard/templatetags/projects_tags.py +++ b/badges/dashboard/templatetags/projects_tags.py @@ -1,9 +1,24 @@ from django import template from django.template.defaultfilters import mark_safe +from subprocess import Popen, PIPE register = template.Library() @register.filter def purge_content(value): - return mark_safe(value.replace('

 

', '')) \ No newline at end of file + return mark_safe(value.replace('

 

', '')) + +@register.filter +def html2text(value): + """ + Pipes given HTML string into the text browser W3M, which renders it. + Rendered text is grabbed from STDOUT and returned. + """ + try: + cmd = "w3m -dump -T text/html -O ascii" + proc = Popen(cmd, shell=True, stdin=PIPE, stdout=PIPE) + return proc.communicate(str(value))[0] + except OSError: + # something bad happened, so just return the input + return value \ No newline at end of file diff --git a/badges/templates/emails/badge_created.html b/badges/templates/emails/badge_created.html index 8879748..a19c776 100644 --- a/badges/templates/emails/badge_created.html +++ b/badges/templates/emails/badge_created.html @@ -7,29 +7,30 @@ Howdy!

-Your badge {{ badge.title }} is published, live, and ready-to-go. +Your badge {{ badge.title }} is created. Woohoo! +

+

+ Your Badge is created, but that doesn't mean that people can apply for it yet. If you haven't already, then you + must publish it and let the world see your creation. Publish it by pressing on the "Publish" button + here.

- +

{{ badge.title }}

{{ badge.description|purge_content }}

-

{{ badge.requirements }}

+

{{ badge.requirements|purge_content }}

-

-Your Badge now exists on badges.p2pu.org and learners can apply for it immediately. As the Badge's creator, this badge will automatically appear on your profile. -

-

-Tell the world about your spiffy Badge! {% include 'emails/social_buttons.html' %} +

As the Badge's creator, this badge will automatically appear on your profile.

diff --git a/badges/templates/emails/badge_created.txt b/badges/templates/emails/badge_created.txt index 70cd9fc..7c79ef7 100644 --- a/badges/templates/emails/badge_created.txt +++ b/badges/templates/emails/badge_created.txt @@ -1,20 +1,16 @@ -{% load projects_tags %}{% load i18n %}{% blocktrans with title=badge.title decription=badge.description|purge_content requirements=badge.requirements%} +{% load projects_tags %}{% load i18n %}{% blocktrans with title=badge.title description=badge.description|purge_content requirements=badge.requirements|html2text %} Howdy! -Your badge {{ title }} is published, live, and ready-to-go. +Your badge {{ badge.title }} is created. Woohoo! -{{ title }} -{{ description }} -{{ requirements }} +* Title: {{ title }} +* Description: {{ description }} +* Requirements: {{ requirements }} {% endblocktrans %} -Your Badge now exists at http://badges.p2pu.org{% url badge_view badge.id %} and learners can apply for it immediately. As the Badge's creator, this badge will automatically appear on your profile. +Your Badge is created, but that doesn't mean that people can apply for it yet. If you haven't already, then you must publish it and let the world see your creation. Publish it by pressing on the "Publish" button at http://badges.p2pu.org{% url badge_preview badge.id %} -Tell the world about your spiffy Badge! - -Google+ - https://plus.google.com/share?url=http://badges.p2pu.org{% url badge_view badge.id %} - -Tweet - http://twitter.com/share?url=http://badges.p2pu.org{% url badge_view badge.id %}&text=Check out the spiffy badge I made!&via=p2pu +As the Badge's creator, this badge will automatically appear on your profile. {% blocktrans %} Yours in the future of learning, diff --git a/badges/templates/emails/badge_published.html b/badges/templates/emails/badge_published.html new file mode 100644 index 0000000..b582640 --- /dev/null +++ b/badges/templates/emails/badge_published.html @@ -0,0 +1,42 @@ +{% extends 'emails/base.html' %} +{% load i18n %} +{% load projects_tags %} + +{% block body %} +

+Howdy! +

+

+Your badge {{ badge.title }} is published, live, and ready-to-go. +

+ + + + + + + +
+ + + + +

{{ badge.title }}

+

{{ badge.description|purge_content }}

+

{{ badge.requirements|purge_content }}

+
+

+Your Badge now exists on badges.p2pu.org and learners can apply for it immediately. +

+

+Tell the world about your spiffy Badge! {% include 'emails/social_buttons.html' %} +

+ +

+ +

+

+Yours in the future of learning,
+- The P2PU team +

+{% endblock %} diff --git a/badges/templates/emails/badge_published.txt b/badges/templates/emails/badge_published.txt new file mode 100644 index 0000000..73fc37a --- /dev/null +++ b/badges/templates/emails/badge_published.txt @@ -0,0 +1,22 @@ +{% load projects_tags %}{% load i18n %}{% blocktrans with title=badge.title description=badge.description|purge_content requirements=badge.requirements|html2text %} +Howdy! + +Your badge {{ title }} is published, live, and ready-to-go. + +* Title: {{ title }} +* Description: {{ description }} +* Requirements: {{ requirements }} +{% endblocktrans %} + +Your Badge now exists at http://badges.p2pu.org{% url badge_view badge.id %} and learners can apply for it immediately. + +Tell the world about your spiffy Badge! + +Google+ - https://plus.google.com/share?url=http://badges.p2pu.org{% url badge_view badge.id %} + +Tweet - http://twitter.com/share?url=http://badges.p2pu.org{% url badge_view badge.id %}&text=Check out the spiffy badge I made!&via=p2pu + +{% blocktrans %} +Yours in the future of learning, +- The P2PU team +{% endblocktrans %} diff --git a/badges/templates/emails/badge_published_subject.txt b/badges/templates/emails/badge_published_subject.txt new file mode 100644 index 0000000..8d6ebe5 --- /dev/null +++ b/badges/templates/emails/badge_published_subject.txt @@ -0,0 +1 @@ +{% load i18n %}{% blocktrans with badge_title=badge.title%}You've just published a {{ badge_title }} Badge. Congrats!{% endblocktrans %}