Skip to content

Commit

Permalink
Merge branch 'master' into agregando_featured_al_home
Browse files Browse the repository at this point in the history
votai_general_theme/templates/popular_proposal/_lista_propuestas.html
  • Loading branch information
damian-garrido committed Sep 22, 2017
2 parents 031a040 + 6022bd9 commit 5ed12f8
Show file tree
Hide file tree
Showing 63 changed files with 1,475 additions and 343 deletions.
8 changes: 4 additions & 4 deletions elections/fixtures/mini_2.yaml
Expand Up @@ -28,22 +28,22 @@
user_permissions: []
- model: popolo.area
pk: algarrobo-5602
fields: {content_type: null, object_id: null, start_date: null, end_date: null,
fields: {slug: algarrobo, content_type: null, object_id: null, start_date: null, end_date: null,
name: Algarrobo, identifier: '5602', classification: 'Comuna', parent: null, geom: null,
inhabitants: null}
- model: popolo.area
pk: alhue-13502
fields: {content_type: null, object_id: null, start_date: null, end_date: null,
fields: {slug: alhue, content_type: null, object_id: null, start_date: null, end_date: null,
name: "Alhu\xE9", identifier: '13502', classification: 'Comuna', parent: null, geom: null,
inhabitants: null}
- model: popolo.area
pk: arica-15101
fields: {content_type: null, object_id: null, start_date: null, end_date: null,
fields: {slug: alhue, content_type: null, object_id: null, start_date: null, end_date: null,
name: Arica, identifier: '15101', classification: '', parent: null, geom: null,
inhabitants: null}
- model: popolo.area
pk: fundacion-ciudadano-inteligente
fields: {content_type: null, object_id: null, start_date: null, end_date: null,
fields: {slug: ciudadanoi, content_type: null, object_id: null, start_date: null, end_date: null,
name: CiudadanoI, identifier: '15101', classification: '', parent: null, geom: null,
inhabitants: null}
- model: backend_citizen.profile
Expand Down
4 changes: 2 additions & 2 deletions elections/models.py
Expand Up @@ -39,7 +39,7 @@ class Meta:
proxy = True

def get_absolute_url(self):
return reverse('area', kwargs={'slug': self.id})
return reverse('area', kwargs={'slug': self.slug})

def ogp_description(self):
return self.name
Expand Down Expand Up @@ -200,7 +200,7 @@ def ranking_in_election(self):
def get_absolute_url(self):
if config.CANDIDATE_ABSOLUTE_URL_USING_AREA:
return reverse('candidate_detail_view_area', kwargs={
'area_slug': self.election.area.id,
'area_slug': self.election.area.slug,
'slug': self.id
})
election_slug = ''
Expand Down
2 changes: 1 addition & 1 deletion elections/tests/candidatorg_views_tests.py
Expand Up @@ -54,7 +54,7 @@ def test_candidate_get_absolute_url(self):
def test_candidate_get_absolute_url_with_area(self):
candidate = self.coquimbo.candidates.get(id=1)
url = reverse('candidate_detail_view_area', kwargs={
'area_slug': self.tarapaca.area.id,
'area_slug': self.tarapaca.area.slug,
'slug': candidate.id
})
self.assertEquals(candidate.get_absolute_url(), url)
Expand Down
4 changes: 2 additions & 2 deletions elections/tests/template_tags_tests.py
Expand Up @@ -81,9 +81,9 @@ def test_areas_json_template_tag(self):
Area.objects.create(name="Mar para Bolivia")
Area.objects.create(name="Guatemala")
for area in Area.public.all():
area_dict = {'slug': area.id,
area_dict = {'slug': area.slug,
'name': area.name,
'detaillink': reverse('area', kwargs={'slug': area.id})
'detaillink': area.get_absolute_url()
}
expected_areas.append(area_dict)

Expand Down
12 changes: 6 additions & 6 deletions elections/tests/version2/elections_per_area_tests.py
Expand Up @@ -24,7 +24,7 @@ def test_an_election_can_have_an_area(self):

def test_there_is_a_url_with_the_area(self):
argentina = Area.objects.create(name=u'Argentina')
url = reverse('area', kwargs={'slug': argentina.id})
url = argentina.get_absolute_url()
response = self.client.get(url)
self.assertEquals(response.status_code, 200)
self.assertTemplateUsed(response, 'elections/area.html')
Expand All @@ -37,7 +37,7 @@ def test_hidden_area(self):
@override_config(HIDDEN_AREAS='argentina')
def test_hidden_area_is_still_reachable(self):
argentina = Area.objects.create(name=u'Argentina')
url = reverse('area', kwargs={'slug': argentina.id})
url = argentina.get_absolute_url()
response = self.client.get(url)
self.assertEquals(response.status_code, 200)

Expand Down Expand Up @@ -177,13 +177,13 @@ def test_areas_redirect_when_necesary(self):
mother = Area.objects.create(name="mother")
mother.children.add(child)

url = reverse('area', kwargs={'slug': child.id})
url = child.get_absolute_url()
response = self.client.get(url)
url_mother = reverse('area', kwargs={'slug': mother.id})
url_mother = mother.get_absolute_url()
self.assertRedirects(response, url_mother)

child2 = Area.objects.create(name="children", classification="Comuna")
url = reverse('area', kwargs={'slug': child2.id})
url = child2.get_absolute_url()
response = self.client.get(url)
self.assertEquals(response.status_code, 200)

Expand All @@ -193,7 +193,7 @@ def setUp(self):
self.site = Site.objects.get_current()

def test_get_absolute_url(self):
url = reverse('area', kwargs={'slug': self.argentina.id})
url = reverse('area', kwargs={'slug': self.argentina.slug})
self.assertEquals(url, self.argentina.get_absolute_url())

def test_ogp_things(self):
Expand Down
6 changes: 3 additions & 3 deletions elections/urls.py
Expand Up @@ -61,7 +61,7 @@
cache_page(60 * settings.CACHE_MINUTES)(CandidateDetailView.as_view(template_name='elections/candidate_detail.html')),
name='candidate_detail_view'
),
url(r'^territorio/(?P<area_slug>[-\w]+)/(?P<slug>[-\w]+)/?$',
url(r'^candidaturas/(?P<area_slug>[-\w]+)/(?P<slug>[-\w]+)/?$',
cache_page(60 * settings.CACHE_MINUTES)(CandidateDetailView.as_view(template_name='elections/candidate_detail.html')),
name='candidate_detail_view_area'
),
Expand All @@ -73,10 +73,10 @@
url(r'^eleccion/(?P<slug>[-\w]+)/extra_info.html$',
ElectionDetailView.as_view(template_name='elections/extra_info.html'),
name='election_extra_info'),
url(r'^territorio/(?P<slug>[-\w]+)/?$',
url(r'^candidaturas/(?P<slug>[-\w]+)/?$',
AreaDetailView.as_view(template_name='elections/area.html'),
name='area'),
url(r'^territorio/?$', KnowYourCandidatesView.as_view(), name='know_your_candidates'),
url(r'^candidaturas/?$', KnowYourCandidatesView.as_view(), name='know_your_candidates'),
]

# urlpatterns += [
Expand Down
6 changes: 3 additions & 3 deletions elections/views.py
Expand Up @@ -147,7 +147,7 @@ def get_queryset(self):
if 'election_slug' in self.kwargs.keys():
queryset_ = queryset.filter(elections__slug=self.kwargs['election_slug'])
if 'area_slug' in self.kwargs.keys():
queryset_ = queryset.filter(elections__area__id=self.kwargs['area_slug'])
queryset_ = queryset.filter(elections__area__slug=self.kwargs['area_slug'])
cache.set(candidates_per_election_key,
queryset_,
60 * config.INFINITE_CACHE
Expand Down Expand Up @@ -187,12 +187,12 @@ class AreaDetailView(DetailView, FilterMixin):
model = Area
context_object_name = 'area'
template_name = 'area.html'
slug_field = 'id'
# slug_field = 'id'

def dispatch(self, request, *args, **kwargs):
area = self.get_object()
if area.classification in settings.FILTERABLE_AREAS_TYPE and area.parent:
return HttpResponseRedirect(reverse('area', kwargs={'slug': area.parent.id}))
return HttpResponseRedirect(Area.objects.get(id=area.parent.id).get_absolute_url())
return super(AreaDetailView, self).dispatch(request, *args, **kwargs)


Expand Down
10 changes: 1 addition & 9 deletions popular_proposal/migrations/0021_auto_20170607_2313.py
Expand Up @@ -7,15 +7,7 @@


def create_areas(apps, schema_editor):
Area = apps.get_model('elections', 'Area')
try:
Area.objects.get(id=config.HIDDEN_AREAS)
except Area.DoesNotExist as e:
Area.objects.create(id=config.HIDDEN_AREAS, name=config.HIDDEN_AREAS)
try:
Area.objects.get(id=config.DEFAULT_AREA)
except Area.DoesNotExist as e:
Area.objects.create(id=config.DEFAULT_AREA, name=config.DEFAULT_AREA)
pass


class Migration(migrations.Migration):
Expand Down
23 changes: 23 additions & 0 deletions popular_proposal/migrations/0027_auto_20170914_1841.py
@@ -0,0 +1,23 @@
# -*- coding: utf-8 -*-
# Generated by Django 1.10.7 on 2017-09-14 18:41
from __future__ import unicode_literals

from django.db import migrations


class Migration(migrations.Migration):

dependencies = [
('popular_proposal', '0026_popularproposal_featured'),
]

operations = [
migrations.AlterModelOptions(
name='popularproposal',
options={'ordering': ['-featured', 'for_all_areas', '-created'], 'verbose_name': 'Propuesta Ciudadana', 'verbose_name_plural': 'Propuestas Ciudadanas'},
),
migrations.AlterModelOptions(
name='proposallike',
options={'verbose_name': 'Apoyo', 'verbose_name_plural': 'Apoyos'},
),
]
27 changes: 0 additions & 27 deletions popular_proposal/subscriptions.py
Expand Up @@ -34,30 +34,6 @@ def notify(self):
to=[email])


class NewCommitmentNotification(SubscriptionEventBase):

def __init__(self, *args, **kwargs):
super(NewCommitmentNotification, self).__init__(*args, **kwargs)
self.commitment = kwargs.pop('commitment')

def get_who(self):
return self.proposal.likers.exclude(id=self.proposal.proposer.id)

def get_mail_from(self, person):
return person.email

def get_template(self):
if self.commitment.commited:
return 'new_commitment'
else:
return 'not_new_commitment'

def get_context(self, **kwargs):
context = super(NewCommitmentNotification, self).get_context(**kwargs)
context['commitment'] = self.commitment
return context


class NewCommitmentNotificationToProposer(SubscriptionEventBase):
mail_template = 'genia_lograste_compromiso'

Expand Down Expand Up @@ -146,6 +122,3 @@ def notification_trigger(event, **kwargs):
dispatcher = EventDispatcher()
proposal = kwargs.pop('proposal')
dispatcher.trigger(event, proposal, kwargs)



47 changes: 10 additions & 37 deletions popular_proposal/tests/subscription_tests.py
Expand Up @@ -6,7 +6,6 @@
)
from popular_proposal.subscriptions import (SubscriptionEventBase,
EventDispatcher,
NewCommitmentNotification,
ManyCitizensSupportingNotification,
YouAreAHeroNotification,
NewCommitmentNotificationToProposer,
Expand Down Expand Up @@ -59,6 +58,15 @@ class SubscriptionEventsTestCase(SubscriptionTestCaseBase):
def setUp(self):
super(SubscriptionEventsTestCase, self).setUp()

def test_raises_not_implemented_error(self):
class OnlyForThisTest(SubscriptionEventBase):
pass
bad_dispatcher = OnlyForThisTest(None)
with self.assertRaises(NotImplementedError):
bad_dispatcher.get_who()
with self.assertRaises(NotImplementedError):
bad_dispatcher.get_mail_from(None)

def test_triggering_an_event(self):
dispatcher = EventDispatcher()
dispatcher.register('test-event', [TestNewCandidateCommitment, ])
Expand Down Expand Up @@ -101,42 +109,6 @@ def test_letting_the_proposer_know_of_his_non_commitment(self):
self.assertIn(self.proposal.title, the_mail.body)
self.assertIn(self.candidate.name, the_mail.body)

def test_letting_know_the_citizens_that_a_candidate_has_commited_to_a_proposal(self):
ProposalLike.objects.create(user=self.feli,
proposal=self.proposal)
commitment = Commitment.objects.create(candidate=self.candidate,
proposal=self.proposal,
commited=True)
previous_amount = len(mail.outbox)
notifier = NewCommitmentNotification(proposal=self.proposal,
commitment=commitment)
notifier.notify()
self.assertEquals(len(mail.outbox), previous_amount + 1)
the_mail = mail.outbox[previous_amount]
self.assertIn(self.feli.email, the_mail.to)
self.assertEquals(len(the_mail.to), 1)
self.assertIn(self.proposal.title, the_mail.body)
self.assertIn(self.candidate.name, the_mail.body)

def test_letting_the_citizens_know_that_a_candidate_has_said_no(self):
ProposalLike.objects.create(user=self.feli,
proposal=self.proposal)
commitment = Commitment.objects.create(candidate=self.candidate,
proposal=self.proposal,
detail=u'Yo No me comprometo',
commited=False)
previous_amount = len(mail.outbox)
notifier = NewCommitmentNotification(proposal=self.proposal,
commitment=commitment)
notifier.notify()
self.assertEquals(len(mail.outbox), previous_amount + 1)
the_mail = mail.outbox[previous_amount]
self.assertIn(self.feli.email, the_mail.to)
self.assertEquals(len(the_mail.to), 1)
self.assertIn(self.proposal.title, the_mail.body)
self.assertIn(self.candidate.name, the_mail.body)
self.assertIn(commitment.detail, the_mail.body)

def test_notification_trigger_candidate_commit(self):
ProposalLike.objects.create(user=self.feli,
proposal=self.proposal)
Expand Down Expand Up @@ -269,6 +241,7 @@ def test_proposal_notification_for_candidates(self):
def test_new_proposal_notification_with_login_info(self):
self.feli.last_login = None
self.feli.save()
CandidacyContact.objects.all().delete()
candidacy = Candidacy.objects.create(user=self.feli,
candidate=self.candidate
)
Expand Down
4 changes: 2 additions & 2 deletions popular_proposal/tests/views_tests.py
Expand Up @@ -174,15 +174,15 @@ def test_filtering_form_by_area(self):
self.assertTrue(form.is_valid())

def test_area_detail_view_brings_proposals(self):
url = reverse('area', kwargs={'slug': self.algarrobo.id})
url = self.algarrobo.get_absolute_url()
response = self.client.get(url)
self.assertIn(self.popular_proposal1,
response.context['popular_proposals'])
self.assertIn(self.popular_proposal2,
response.context['popular_proposals'])

def test_get_area_with_form(self):
url = reverse('area', kwargs={'slug': self.algarrobo.id})
url = self.algarrobo.get_absolute_url()
response = self.client.get(url)
self.assertIsInstance(response.context['proposal_filter_form'],
Form)
Expand Down
11 changes: 0 additions & 11 deletions popular_proposal/tests/wizard_tests.py
Expand Up @@ -405,14 +405,3 @@ def test_done_brings_update_proposal_form(self):
self.assertIsInstance(form, UpdateProposalForm)
self.assertEquals(form.instance, temporary_data.created_proposal)

def test_if_we_say_is_testing_in_wizard_it_creates_a_proposal_in_testing_area(self):
try:
testing_area = Area.objects.get(id=config.HIDDEN_AREAS)
except Area.DoesNotExist:
testing_area = Area.objects.create(id=config.HIDDEN_AREAS, name=config.HIDDEN_AREAS)
response = self.fill_the_whole_wizard(override_example_data={3: {'3-title':'title',
'3-terms_and_conditions': True,
"3-is_testing":True}})
temporary_data = response.context['popular_proposal']

self.assertEquals(temporary_data.created_proposal.area, testing_area)
2 changes: 1 addition & 1 deletion popular_proposal/urls.py
Expand Up @@ -39,7 +39,7 @@
ProposalWizardFullWithoutArea.as_view(),
name='propose_wizard_full_without_area'),
url(r'^detail/(?P<slug>[-\w]+)/?$',
PopularProposalDetailView.as_view(),
xframe_options_exempt(PopularProposalDetailView.as_view()),
name='detail'),
url(r'^d/(?P<pk>\d+)/?$',
PopularProposalDetailRedirectView.as_view(),
Expand Down
2 changes: 0 additions & 2 deletions popular_proposal/views/wizard.py
Expand Up @@ -45,8 +45,6 @@ def get_previous_forms(self):

def determine_area(self, data):
is_testing = data.pop("is_testing", False)
if is_testing:
return Area.objects.get(id=config.HIDDEN_AREAS)
if 'area' in data.keys():
return data['area']
elif hasattr(self, 'area'):
Expand Down
3 changes: 3 additions & 0 deletions preguntales/tests/ask_candidates_tests.py
Expand Up @@ -525,6 +525,9 @@ def setUp(self):
self.candidate1 = Candidate.objects.get(id=4)
self.candidate2 = Candidate.objects.get(id=5)
self.candidate3 = Candidate.objects.get(id=6)
self.election.candidates.add(self.candidate1)
self.election.candidates.add(self.candidate2)
self.election.candidates.add(self.candidate3)

def tearDown(self):
pass
Expand Down

0 comments on commit 5ed12f8

Please sign in to comment.