Merge branch 'issue-1391-ljv'

Update Issue 1391
Status: FixPending
diff --git a/app/soc/modules/gsoc/models/program.py b/app/soc/modules/gsoc/models/program.py
index 3fd5a3d..e5c7c00 100644
--- a/app/soc/modules/gsoc/models/program.py
+++ b/app/soc/modules/gsoc/models/program.py
@@ -31,6 +31,12 @@
   accepted_students_msg = db.TextProperty(required=False,
       verbose_name=ugettext('Accepted Students Message'))
 
+  #: Message sent to welcome accepted students to the program. This does
+  #: not include any personalized text from the organization they got
+  #: accepted for.
+  accepted_students_welcome_msg = db.TextProperty(required=False,
+      verbose_name=ugettext('Accepted Students Welcome Message'))
+
   #: Message sent to the students that are rejected for the program.
   rejected_students_msg = db.TextProperty(required=False,
       verbose_name=ugettext('Rejected Students Message'))
diff --git a/app/soc/modules/gsoc/tasks/accept_proposals.py b/app/soc/modules/gsoc/tasks/accept_proposals.py
index 3a1757d..66a0f99 100644
--- a/app/soc/modules/gsoc/tasks/accept_proposals.py
+++ b/app/soc/modules/gsoc/tasks/accept_proposals.py
@@ -229,6 +229,30 @@
         template_string, context, parent=proposal.parent(),
         transactional=transactional)
 
+  def getWelcomeMailTxn(self, proposal, transactional=True):
+    """Returns the function to sent an welcome email for an accepted proposal.
+    """
+    sender_name, sender = mail_dispatcher.getDefaultMailSender()
+
+    student_entity = proposal.parent()
+    program_entity = proposal.program
+
+    context = {
+      'to': student_entity.email,
+      'to_name': student_entity.given_name,
+      'sender': sender,
+      'sender_name': sender_name,
+      'program_name': program_entity.name,
+      'subject': 'Welcome to %s' % program_entity.name,
+      }
+
+    messages = program_entity.getProgramMessages()
+    template_string = messages.accepted_students_welcome_msg
+
+    return mail_dispatcher.getSendMailFromTemplateStringTxn(
+        template_string, context, parent=proposal.parent(),
+        transactional=transactional)
+
   def getRejectProposalMailTxn(self, proposal):
     """Returns the function to sent an rejectance mail for the specified
     proposal.
@@ -275,7 +299,9 @@
     project = GSoCProject(parent=student_profile, **fields)
     student_info_key = student_profile.student_info.key()
 
-    mail_txn = self.getAcceptProposalMailTxn(
+    accepted_mail_txn = self.getAcceptProposalMailTxn(
+        proposal, transactional=transactional)
+    welcome_mail_txn = self.getWelcomeMailTxn(
         proposal, transactional=transactional)
 
     proposal_key = proposal.key()
@@ -294,7 +320,7 @@
 
       # add a task that performs conversion status per
       # proposal
-      status_task.add(transactional=True)
+      status_task.add(transactional=transactional)
 
       proposal = db.get(proposal_key)
       proposal.status = 'accepted'
@@ -306,7 +332,8 @@
       db.put(project)
       db.put(proposal)
       db.put(student_info)
-      mail_txn()
+      accepted_mail_txn()
+      welcome_mail_txn()
 
     db.RunInTransaction(acceptProposalTxn)
 
diff --git a/app/soc/templates/v2/modules/gsoc/program/messages.html b/app/soc/templates/v2/modules/gsoc/program/messages.html
index 4f187ae..6075364 100644
--- a/app/soc/templates/v2/modules/gsoc/program/messages.html
+++ b/app/soc/templates/v2/modules/gsoc/program/messages.html
@@ -28,6 +28,7 @@
        "melange-description-textarea", "rejected_orgs_msg",
        "melange-description-textarea", "mentor_welcome_msg",
        "melange-description-textarea", "accepted_students_msg",
+       "melange-description-textarea", "accepted_students_welcome_msg",
        "melange-description-textarea", "rejected_students_msg"
       ]));
     }
diff --git a/tests/app/soc/modules/gsoc/tasks/test_accept_proposals.py b/tests/app/soc/modules/gsoc/tasks/test_accept_proposals.py
index 18cce46..95e414d 100644
--- a/tests/app/soc/modules/gsoc/tasks/test_accept_proposals.py
+++ b/tests/app/soc/modules/gsoc/tasks/test_accept_proposals.py
@@ -171,6 +171,8 @@
     self.assertEqual(response.status_code, httplib.OK)
     self.assertEmailSent(to=self.student1.profile.email,
                          subject='Congratulations!')
+    self.assertEmailSent(to=self.student1.profile.email,
+                         subject='Welcome to %s' % self.gsoc.name)
     self.assertEmailNotSent(to=self.student2.profile.email)
 
     #assert post status of proposal to be accepted
diff --git a/tests/app/soc/modules/gsoc/views/test_program.py b/tests/app/soc/modules/gsoc/views/test_program.py
index 7c6f128..1d8547d 100644
--- a/tests/app/soc/modules/gsoc/views/test_program.py
+++ b/tests/app/soc/modules/gsoc/views/test_program.py
@@ -212,6 +212,7 @@
   DEF_REJECTED_ORGS_MSG = 'Rejected Orgs Message'
   DEF_MENTOR_WELCOME_MSG = 'Mentor Welcome Message'
   DEF_ACCEPTED_STUDENTS_MSG = 'Accepted Students Messages'
+  DEF_ACCEPTED_STUDENTS_WELCOME_MSG = 'Accepted Students Welcome Messages'
   DEF_REJECTED_STUDENTS_MSG = 'Rejected Students Message'
 
   def assertProgramTemplatesUsed(self, response):
@@ -233,6 +234,7 @@
         'rejected_orgs_msg': self.DEF_MENTOR_WELCOME_MSG,
         'mentor_welcome_msg': self.DEF_MENTOR_WELCOME_MSG,
         'accepted_students_msg': self.DEF_ACCEPTED_STUDENTS_MSG,
+        'accepted_students_welcome_msg': self.DEF_ACCEPTED_STUDENTS_WELCOME_MSG,
         'rejected_students_msg': self.DEF_REJECTED_STUDENTS_MSG,
         }