Commit 52e2826f authored by Claude Paroz's avatar Claude Paroz

Send mail to coordinator when user join his team

parent 5806b330
......@@ -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"))
......
......@@ -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."))
......
# -*- 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
......
# -*- 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)
......@@ -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 %}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment