Skip to content

Commit

Permalink
New temporary proposal mail
Browse files Browse the repository at this point in the history
  • Loading branch information
Luis Felipe Álvarez Burgos committed May 2, 2016
1 parent cd33d47 commit 04d3a09
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 3 deletions.
11 changes: 10 additions & 1 deletion popular_proposal/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
19 changes: 17 additions & 2 deletions popular_proposal/tests/new_proposal_cycle_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand All @@ -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,
Expand Down
Original file line number Diff line number Diff line change
@@ -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á:<a href="http://{{site.domain}}{% url 'area' slug=area.id %}">{{area}}</a>

Gracias por querer hacer de {{area}} un lugar mejor.

--
El equipo de VotaInteligente.
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Recibimos tu Propuesta Ciudadana para {{area}}.

0 comments on commit 04d3a09

Please sign in to comment.