diff --git a/.travis.yml b/.travis.yml
index bd21a55..c32b352 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -3,8 +3,9 @@ language: python
python:
- 2.6
- 2.7
- - 3.2
- - 3.3
+# django-inlinecss is py2 only for now :(
+ #- 3.2
+ #- 3.3
env:
- DJANGO=https://github.com/django/django/tarball/master
diff --git a/badgekit_webhooks/claimcode_views.py b/badgekit_webhooks/claimcode_views.py
index 59a6d54..77cc3d1 100644
--- a/badgekit_webhooks/claimcode_views.py
+++ b/badgekit_webhooks/claimcode_views.py
@@ -5,6 +5,7 @@
from django.core.urlresolvers import reverse
from django.shortcuts import render
from django.core.mail import EmailMessage
+from django.core.mail import EmailMultiAlternatives
from django.conf import settings
from django.template.loader import render_to_string
from . import forms
@@ -87,14 +88,24 @@ def form_valid(self, form, request):
def send_claim_mail(self, request, code_obj):
claim_url = request.build_absolute_uri(
reverse('claimcode_claim', args=[code_obj.code]))
- text_message = render_to_string(
- 'badgekit_webhooks/claim_code_email.txt',
- {
- 'claim_url': claim_url,
- })
- email = EmailMessage("You're earned a badge!",
- text_message, settings.DEFAULT_FROM_EMAIL,
- [code_obj.initial_email])
+ context = {
+ 'claim_url': claim_url,
+ 'organization': 'open edX',
+ 'badge_name': 'Open edX Contributor',
+ 'badgeclass_image_url': 'http://placekitten.com/300/300',
+ 'badge_earner_description': 'Contribute to the edX code, which is accomplished most visibly with an accepted pull request on GitHub.',
+ 'about_program_url': '#',
+ 'contact_email': 'contact@example.com',
+ 'site_base_url': 'http://localhost:8000',
+ 'unsubscribe_link': '#',
+ }
+
+ text_message = render_to_string('badgekit_webhooks/claim_code_email.txt', context)
+ html_message = render_to_string('badgekit_webhooks/claim_code_email.html')
+
+ email = EmailMultiAlternatives("You've earned a badge!", text_message,
+ settings.DEFAULT_FROM_EMAIL, [code_obj.initial_email])
+ email.attach_alternative(html_message, "text/html")
email.send()
diff --git a/badgekit_webhooks/templates/badgekit_webhooks/claim_code_email.html b/badgekit_webhooks/templates/badgekit_webhooks/claim_code_email.html
new file mode 100644
index 0000000..cb4dfee
--- /dev/null
+++ b/badgekit_webhooks/templates/badgekit_webhooks/claim_code_email.html
@@ -0,0 +1,147 @@
+{% load inlinecss %}
+{% inlinecss "css/email.css" %}
+
+
+
+
+
+
+
+
+
+
+
+You've earned a badge. Claim it with this code.
+
+
+
+
+
+
+
+
+
+
+
+
+ |
+
+
+
+
+
+
+
+ Cheers!
+ You've earned a badge from {{ organization }}:
+
+
+ 
+
+
+
+ {{ badge_name }}
+ {{ badge_earner_description }}
+ Claim your badge!
+ You can choose to send this badge to whichever email address you prefer to receive badge awards.
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ |
+
+
+
+
+ |
+
+
+
+
+ |
+ |
+
+
+
+
+
+
+
+
+
+{% endinlinecss %}
\ No newline at end of file
diff --git a/badgekit_webhooks/templates/badgekit_webhooks/claim_code_email.txt b/badgekit_webhooks/templates/badgekit_webhooks/claim_code_email.txt
index 7f92d09..4686c91 100644
--- a/badgekit_webhooks/templates/badgekit_webhooks/claim_code_email.txt
+++ b/badgekit_webhooks/templates/badgekit_webhooks/claim_code_email.txt
@@ -1,9 +1,14 @@
-Hi!
+Congratulations!
-Congratulations! You have been awarded a digital badge in recognition for your
-contributions to Open edX. You can go to the URL below to claim your badge,
-and show it off to the world.
+You have been awarded a digital badge from {{ organization }}. You can visit the URL below to claim your badge and show it off to the world. You can choose to send this badge to whichever email address you prefer to receive badge awards.
{{ claim_url }}
-Thanks for your work!
+Badge information:
+{{ badge_name }}
+{{ badge_earner_description }}
+
+
+Learn more about {{ organization }} badges: {{ about_program_url }}
+
+Contact us: {{ contact_email }} | {{ site_base_url }}
\ No newline at end of file
diff --git a/badgekit_webhooks/tests/email_tests.py b/badgekit_webhooks/tests/email_tests.py
index 634acd5..4492c69 100644
--- a/badgekit_webhooks/tests/email_tests.py
+++ b/badgekit_webhooks/tests/email_tests.py
@@ -1,4 +1,5 @@
from __future__ import unicode_literals
+from badgekit_webhooks import utils
from django.test import TestCase
from badgekit_webhooks import views
from badgekit_webhooks import models
@@ -10,12 +11,22 @@ class MockRequest(object):
def build_absolute_uri(self, location):
return "Fake-absolute-uri"
+
class SendEmailTest(TestCase):
+ def setUp(self):
+ # monkey patch / mock the image grabber
+ self.old_get_image = utils.get_image_for_assertion
+ utils.get_image_for_assertion = lambda x: 'http://example.com/image.png'
+
def testEmailIsSent(self):
- with self.settings(BADGEKIT_SEND_CLAIM_EMAILS=True):
+ # Need DEBUG=True because django-inlinecss depends on it >_<
+ with self.settings(BADGEKIT_SEND_CLAIM_EMAILS=True, DEBUG=True):
models.badge_instance_issued.send(sender=MockRequest(),
uid='asdf1234', email='recipient@example.com',
assertionUrl='http://example.com/assertion/1.json',
issuedOn=datetime.datetime.now())
self.assertEqual(len(mail.outbox), 1)
+
+ def tearDown(self):
+ utils.get_image_for_assertion = self.old_get_image
diff --git a/badgekit_webhooks/utils.py b/badgekit_webhooks/utils.py
index 88a0801..da8ce9e 100644
--- a/badgekit_webhooks/utils.py
+++ b/badgekit_webhooks/utils.py
@@ -51,3 +51,31 @@ def get_image_for_assertion(assertion_url):
except (requests.exceptions.RequestException, ValueError, KeyError):
logging.exception('Problem while determining image for assertion %s' % assertion_url)
return settings.BADGEKIT_DEFAULT_BADGE_IMAGE
+
+# def get_properties_for_assertion(assertion_url, props):
+# """
+# Given a badge assertion URL, return a specified list of properties for that assertion.
+
+# If the assertion is not available or parseable, returns a default
+# image, which is settings.BADGEKIT_DEFAULT_BADGE_IMAGE.
+# """
+# # TODO: make sure various URLs are subjected to a whitelist test.
+# # Maybe also check that they are reasonable size, etc?
+# try:
+# assertion_resp = requests.get(assertion_url)
+# assertion_obj = json.loads(assertion_resp.text)
+# badge_url = assertion_obj['badge']
+# badge_resp = requests.get(badge_url)
+# badge_obj = json.loads(badge_resp.text)
+# return badge_obj['image']
+
+# except (requests.exceptions.RequestException, ValueError, KeyError):
+# logging.exception('Problem while determining image for assertion %s' % assertion_url)
+# return settings.BADGEKIT_DEFAULT_BADGE_IMAGE
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/runtests.py b/runtests.py
index bbe0704..8768ed9 100644
--- a/runtests.py
+++ b/runtests.py
@@ -16,6 +16,7 @@
"django.contrib.sites",
"django.contrib.staticfiles",
"django_nose",
+ "django_inlinecss",
"badgekit_webhooks",
"badgekit_webhooks.tests"
],
@@ -26,6 +27,7 @@
}
},
STATIC_URL="/static/",
+ STATIC_ROOT="staticfiles",
SITE_ID=1,
ROOT_URLCONF="badgekit_webhooks.tests.urls",
SECRET_KEY="notasecret",