[damned-lies] Send mail to coordinator when user join his team
- From: Claude Paroz <claudep src gnome org>
- To: svn-commits-list gnome org
- Cc:
- Subject: [damned-lies] Send mail to coordinator when user join his team
- Date: Thu, 20 Aug 2009 08:02:24 +0000 (UTC)
commit 52e2826f497c17b12feb8021f2ad4ebe39f73aff
Author: Claude Paroz <claude 2xlibre net>
Date: Thu Aug 20 09:58:20 2009 +0200
Send mail to coordinator when user join his team
common/views.py | 2 +-
people/views.py | 4 ++++
teams/models.py | 13 +++++++++++++
teams/tests.py | 22 ++++++++++++++++++++++
templates/languages/language_release_stats.html | 2 +-
5 files changed, 41 insertions(+), 2 deletions(-)
---
diff --git a/common/views.py b/common/views.py
index 37d7ebf..8ef0c1f 100644
--- a/common/views.py
+++ b/common/views.py
@@ -67,7 +67,7 @@ def site_login(request, msgs=[]):
'url': reverse('person_team_join'),
}
user.message_set.create(message=message)
- if request.POST['referer']:
+ if 'referer' in request.POST:
return HttpResponseRedirect(request.POST['referer'])
else:
return HttpResponseRedirect(reverse("home"))
diff --git a/people/views.py b/people/views.py
index 98ae78d..ca76f8a 100644
--- a/people/views.py
+++ b/people/views.py
@@ -26,6 +26,7 @@ from django.template import RequestContext
from django.db import transaction, IntegrityError
from django.contrib.auth.decorators import login_required
from django.contrib.auth.forms import PasswordChangeForm
+from django.contrib.sites.models import Site
from people.models import Person
from teams.models import Team, Role
from people.forms import TeamJoinForm, DetailForm
@@ -84,6 +85,9 @@ def person_team_join(request):
try:
new_role.save()
request.user.message_set.create(message=_("You have successfully joined the team '%s'.") % team.get_description())
+ team.send_mail_to_coordinator(subject=_("A new person joined your team"),
+ message=_("%(name)s has just joined your translation team on %(site)s") %
+ {'name': person.name, 'site': Site.objects.get_current()})
except IntegrityError:
transaction.rollback()
request.user.message_set.create(message=_("You are already member of this team."))
diff --git a/teams/models.py b/teams/models.py
index 89604e9..2164957 100644
--- a/teams/models.py
+++ b/teams/models.py
@@ -1,6 +1,7 @@
# -*- coding: utf-8 -*-
#
# Copyright (c) 2008 Stéphane Raimbault <stephane raimbault gmail com>.
+# Copyright (c) 2009 Claude Paroz <claude 2xlibre net>
#
# This file is part of Damned Lies.
#
@@ -19,7 +20,10 @@
# 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
from django.db import models
+from django.core import mail
from django.utils.translation import ugettext_lazy, ugettext as _
+from django.conf import settings
+from django.contrib.sites.models import Site
from people.models import Person
class TeamManager(models.Manager):
@@ -173,6 +177,15 @@ class Team(models.Model):
members = list(self.members.all())
return members
+ def send_mail_to_coordinator(self, subject, message):
+ message += "\n--\n" + _(u"This is an automated message sent from %s.") % Site.objects.get_current()
+ mail.send_mail(
+ subject,
+ message,
+ settings.DEFAULT_FROM_EMAIL,
+ [self.get_coordinator().email]
+ )
+
class FakeTeam(object):
"""
This is a class replacing a Team object when a language
diff --git a/teams/tests.py b/teams/tests.py
index 4677e2a..6ac3ac3 100644
--- a/teams/tests.py
+++ b/teams/tests.py
@@ -1,4 +1,9 @@
+# -*- coding: utf-8 -*-
from django.test import TestCase
+from django.test.client import Client
+from django.core.urlresolvers import reverse
+from django.core import mail
+from django.contrib.auth import login
from people.models import Person
from teams.models import Team, Role
@@ -7,6 +12,7 @@ class TeamTest(TestCase):
def setUp(self):
self.pn = Person(first_name='John', last_name='Nothing',
email='jn devnull com', username= 'jn')
+ self.pn.set_password('password')
self.pn.save()
self.pt = Person(first_name='John', last_name='Translator',
@@ -102,3 +108,19 @@ class TeamTest(TestCase):
def test_roles_prefilled_all(self):
self.run_roles_test(Team.objects.all_with_roles()[0])
+
+ def test_join_team(self):
+ c = Client()
+ response = c.post('/login/', {'username': self.pn.username, 'password': 'password'})
+ # Display team join page
+ team_join_url = reverse('person_team_join', current_app='people')
+ response = c.get(team_join_url)
+ self.assertContains(response, "select name=\"teams\"")
+ # Post for joining
+ response = c.post(team_join_url, {'teams':[str(self.t.pk)]})
+ # Test user is member of team
+ self.assertTrue(self.pn.is_translator(self.t))
+ # Test coordinator receives email
+ self.assertEquals(len(mail.outbox), 1)
+ self.assertEquals(mail.outbox[0].recipients()[0], self.pcoo.email)
+
diff --git a/templates/languages/language_release_stats.html b/templates/languages/language_release_stats.html
index 855694d..a0b9b5b 100644
--- a/templates/languages/language_release_stats.html
+++ b/templates/languages/language_release_stats.html
@@ -104,7 +104,7 @@
<ul>
{% for err in modstats.all_errors %}
<li><img src="{{ err.get_icon }}" alt="{{ err.type }}" /> {{ err.statistics.module_name }}:<br />
- <span class="error">{{ err.get_description }}</span></li>
+ <span class="error">{{ err.get_description|safe }}</span></li>
{% endfor %}
</ul>
{% endif %}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]