Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
27 changes: 19 additions & 8 deletions badgekit_webhooks/claimcode_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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()


Expand Down
147 changes: 147 additions & 0 deletions badgekit_webhooks/templates/badgekit_webhooks/claim_code_email.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,147 @@
{% load inlinecss %}
{% inlinecss "css/email.css" %}

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<!-- If you delete this tag, the sky will fall on your head -->
<meta name="viewport" content="width=device-width" />

<!--remove once inlined -->
<!-- <link rel="stylesheet" href="../../static/css/email.css" type="text/css"> -->

<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>You've earned a badge. Claim it with this code.</title>

</head>

<body bgcolor="#FFFFFF">

<!-- HEADER -->
<table class="head-wrap" bgcolor="#f8f8f8">
<tr>
<td></td>
<td class="header container">

<div class="content">
<table bgcolor="#f8f8f8">
<tr>
<td><img src="http://placekitten.com/200/30" /></td>
<td align="right"><h6 class="collapse">{{ organization }}</h6></td>
</tr>
</table>
</div>

</td>
<td></td>
</tr>
</table><!-- /HEADER -->


<!-- BODY -->
<table class="body-wrap">
<tr>
<td></td>
<td class="container" bgcolor="#FFFFFF">

<div class="content">
<table>
<tr>
<td>

<h3>Cheers!</h3>
<p class="lead">You've earned a badge from {{ organization }}:</p>

<!-- Badge image -->
<p class="badge-container"><img src="{{ badgeclass_image_url }}" /></p><!-- /hero -->

<!-- Callout Panel
<p class="callout">
Claim your badge and add it to your collection. <a href="#">Claim now &raquo;</a>
</p> /Callout Panel -->

<h3>{{ badge_name }}</h3>
<p>{{ badge_earner_description }}</p>
<p class="claim-link"><a class="btn" href="{{ claim_url }}">Claim your badge!</a></p>
<p>You can choose to send this badge to whichever email address you prefer to receive badge awards.

<br/>
<br/>

<!-- social & contact -->
<table class="social" width="100%">
<tr>
<td>

<!--- column 1 -->
<table align="left" class="column">
<tr>
<td>

<h5 class="">Learn more about {{ organization }} badges:</h5>
<p class=""><a href="{{ about_program_url }}" class="">About our badges</a> <br /><a href="http://openbadges.org" class="">About Open Badges</a></p>

</td>
</tr>
</table><!-- /column 1 -->

<!--- column 2 -->
<table align="left" class="column">
<tr>
<td>

<h5 class="">Contact Info:</h5>
<p>Email: <strong><a href="emailto:{{contact_email}}">{{ contact_email }}</a></strong>
<br/>
Website: <strong><a href="{{site_base_url}}">{{ organization }}</a></strong></p>

</td>
</tr>
</table><!-- /column 2 -->

<span class="clear"></span>

</td>
</tr>
</table><!-- /social & contact -->


</td>
</tr>
</table>
</div>

</td>
<td></td>
</tr>
</table><!-- /BODY -->

<!-- FOOTER -->
<table class="footer-wrap">
<tr>
<td></td>
<td class="container">

<!-- content -->
<div class="content">
<table>
<tr>
<td align="center">
<p><small>
<!--<a href="#">Privacy</a> | -->
<a href="{{ unsubscribe_link }}"><unsubscribe>I don't want to see these notifications</unsubscribe></a>
</small></p>
</td>
</tr>
</table>
</div><!-- /content -->

</td>
<td></td>
</tr>
</table><!-- /FOOTER -->

</body>
</html>

{% endinlinecss %}
15 changes: 10 additions & 5 deletions badgekit_webhooks/templates/badgekit_webhooks/claim_code_email.txt
Original file line number Diff line number Diff line change
@@ -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 }}
13 changes: 12 additions & 1 deletion badgekit_webhooks/tests/email_tests.py
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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
28 changes: 28 additions & 0 deletions badgekit_webhooks/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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







2 changes: 2 additions & 0 deletions runtests.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
"django.contrib.sites",
"django.contrib.staticfiles",
"django_nose",
"django_inlinecss",
"badgekit_webhooks",
"badgekit_webhooks.tests"
],
Expand All @@ -26,6 +27,7 @@
}
},
STATIC_URL="/static/",
STATIC_ROOT="staticfiles",
SITE_ID=1,
ROOT_URLCONF="badgekit_webhooks.tests.urls",
SECRET_KEY="notasecret",
Expand Down