From 04d3a0994f622cd8522d24b09919fe4f0f71e4bc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Luis=20Felipe=20=C3=81lvarez=20Burgos?= Date: Mon, 2 May 2016 14:44:45 +0000 Subject: [PATCH] New temporary proposal mail --- popular_proposal/models.py | 11 ++++++++++- .../tests/new_proposal_cycle_tests.py | 19 +++++++++++++++++-- .../mails/new_temporary_proposal_body.html | 15 +++++++++++++++ .../mails/new_temporary_proposal_subject.html | 1 + 4 files changed, 43 insertions(+), 3 deletions(-) create mode 100644 votai_general_theme/templates/mails/new_temporary_proposal_body.html create mode 100644 votai_general_theme/templates/mails/new_temporary_proposal_subject.html diff --git a/popular_proposal/models.py b/popular_proposal/models.py index 8c8245e7..37998ded 100644 --- a/popular_proposal/models.py +++ b/popular_proposal/models.py @@ -70,13 +70,22 @@ class Statuses(DjangoChoices): objects = models.Manager() def save(self, *args, **kwargs): + creating = self.id is None if not self.comments: self.comments = {} for key in self.data.keys(): if key not in self.comments.keys(): self.comments[key] = '' - return super(ProposalTemporaryData, self).save(*args, **kwargs) + + def notify_new(self): + site = Site.objects.get_current() + mail_context = { + 'area': self.area, + 'temporary_data': self, + 'site': site, + } + send_mail(mail_context, 'new_temporary_proposal', to=[self.proposer.email]) def create_proposal(self, moderator=None): self.status = ProposalTemporaryData.Statuses.Accepted diff --git a/popular_proposal/tests/new_proposal_cycle_tests.py b/popular_proposal/tests/new_proposal_cycle_tests.py index 228b6db9..b2618c44 100644 --- a/popular_proposal/tests/new_proposal_cycle_tests.py +++ b/popular_proposal/tests/new_proposal_cycle_tests.py @@ -30,6 +30,18 @@ def test_instanciate_one(self): self.assertIn(temporary_data, self.fiera.temporary_proposals.all()) self.assertEquals(temporary_data.get_title(), self.data['title']) self.assertEquals(str(temporary_data.get_title()), self.data['title']) + + def test_send_temporary_data_new_mail(self): + temporary_data = ProposalTemporaryData.objects.create(proposer=self.fiera, + area=self.arica, + data=self.data) + temporary_data.notify_new() + self.assertEquals(len(mail.outbox), 1) + the_mail = mail.outbox[0] + self.assertTrue(the_mail) + self.assertIn(self.fiera.email, the_mail.to) + print the_mail.body + self.fail() def test_proposing_with_an_organization(self): local_org = Organization.objects.create(name="Local Organization") @@ -59,11 +71,12 @@ def test_rejecting_a_proposal(self): temporary_data = ProposalTemporaryData.objects.create(proposer=self.fiera, area=self.arica, data=self.data) + original_amount_of_mails = len(mail.outbox) temporary_data.reject('es muy mala la cosa') temporary_data = ProposalTemporaryData.objects.get(id=temporary_data.id) self.assertEquals(temporary_data.rejected_reason, 'es muy mala la cosa') self.assertEquals(temporary_data.status, ProposalTemporaryData.Statuses.Rejected) - self.assertEquals(len(mail.outbox), 1) + self.assertEquals(len(mail.outbox), original_amount_of_mails + 1) the_mail = mail.outbox[0] self.assertIn(self.fiera.email, the_mail.to) @@ -145,12 +158,14 @@ def test_can_have_an_organization(self): ) def test_create_popular_proposal_from_temporary_data(self): + data = self.data data['organization'] = self.org.id # Testing temporary_data = ProposalTemporaryData.objects.create(proposer=self.fiera, area=self.arica, data=self.data) + original_amount_of_mails = len(mail.outbox) popular_proposal = temporary_data.create_proposal(moderator=self.feli) self.assertEquals(popular_proposal.proposer, self.fiera) self.assertTrue(popular_proposal.organization) @@ -168,7 +183,7 @@ def test_create_popular_proposal_from_temporary_data(self): self.assertEquals(len(mail.outbox), 1) the_mail = mail.outbox[0] self.assertIn(self.fiera.email, the_mail.to) - self.assertEquals(len(the_mail.to), 1) + self.assertEquals(len(the_mail.to), original_amount_of_mails + 1) # context = Context({'area': self.arica, # 'temporary_data': temporary_data, diff --git a/votai_general_theme/templates/mails/new_temporary_proposal_body.html b/votai_general_theme/templates/mails/new_temporary_proposal_body.html new file mode 100644 index 00000000..fc34a142 --- /dev/null +++ b/votai_general_theme/templates/mails/new_temporary_proposal_body.html @@ -0,0 +1,15 @@ +{% load votainteligente_extras %}Hola {{temporary_data.proposer}}! +Recibimos tu propuesta ciudadana y pronto tendremos noticias. + +Tu propuesta tiene el siguiente detalle: +{% for key, item in temporary_data.data.items %} +{{key|popular_proposal_question}}: {{item|popular_proposal_when}}{% if not forloop.last %} +------------------------ +{% endif %}{% endfor %} + +Puedes ver otras propuestas acá:{{area}} + +Gracias por querer hacer de {{area}} un lugar mejor. + +-- +El equipo de VotaInteligente. diff --git a/votai_general_theme/templates/mails/new_temporary_proposal_subject.html b/votai_general_theme/templates/mails/new_temporary_proposal_subject.html new file mode 100644 index 00000000..42011de7 --- /dev/null +++ b/votai_general_theme/templates/mails/new_temporary_proposal_subject.html @@ -0,0 +1 @@ +Recibimos tu Propuesta Ciudadana para {{area}}. \ No newline at end of file