Skip to content

Commit

Permalink
Merge pull request #335 from ciudadanointeligente/proposal_detail_page
Browse files Browse the repository at this point in the history
Proposal detail page
  • Loading branch information
lfalvarez committed Apr 18, 2016
2 parents 1675202 + 2051315 commit 947056a
Show file tree
Hide file tree
Showing 19 changed files with 191 additions and 44 deletions.
2 changes: 1 addition & 1 deletion backend_citizen/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
)

urlpatterns = patterns('',
url(r'^index/?$',
url(r'^$',
IndexView.as_view(),
name='index'),
url(r'^update_temporary_data/(?P<pk>[\d]+)/?$',
Expand Down
2 changes: 1 addition & 1 deletion backend_staff/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
)

urlpatterns = patterns('',
url(r'^index/?$',
url(r'^$',
IndexView.as_view(),
name='index'),
url(r'^popular_proposal_comments/(?P<pk>[-\w]+)/?$',
Expand Down
2 changes: 1 addition & 1 deletion elections/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ def __init__(self, *args, **kwargs):


class Candidate(Person, ExtraInfoMixin):
elections = models.ManyToManyField('Election', related_name='candidates', null=True, default=None)
elections = models.ManyToManyField('Election', related_name='candidates', default=None)
force_has_answer = models.BooleanField(default=False,
help_text=_('Marca esto si quieres que el candidato aparezca como que no ha respondido'))

Expand Down
2 changes: 1 addition & 1 deletion elections/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
}

urlpatterns = patterns('',
url(r'^/?$', cache_page(60 * settings.CACHE_MINUTES)(HomeView.as_view(template_name='elections/home.html')), name='home'),
url(r'^$', cache_page(60 * settings.CACHE_MINUTES)(HomeView.as_view(template_name='elections/home.html')), name='home'),
url(r'^buscar/?$', SearchView(template='search.html',
form_class=ElectionForm), name='search'),
url(r'^busqueda_tags/?$', ElectionsSearchByTagView.as_view(), name='tags_search'),
Expand Down
8 changes: 4 additions & 4 deletions popular_proposal/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,13 +54,13 @@

class ProposalFormBase(forms.Form):
problem = forms.CharField(label=_(u'Según la óptica de tu organización, describe un problema de tu comuna que \
quieras solucionar. 2 líneas)'),
quieras solucionar. (2 líneas)'),
help_text=_(u'Ej: Poca participación en el Plan Regulador, falta de transparencia en \
el trabajo de la municipalidad, pocos puntos de reciclaje, etc.'),
el trabajo de la municipalidad, pocos puntos de reciclaje, etc.'),
max_length=512)
solution = forms.CharField(label=_(u'¿Qué debería hacer la municipalidad para solucionar el problema? (3 líneas)'),
help_text=_(u'Ejemplo: "Crear una ciclovia que circunvale Valdivia", \
"Que se publiquen todos los concejos municipales en el sitio web del municipio".'),
"Que se publiquen todos los concejos municipales en el sitio web del municipio".'),
max_length=256,
)
solution_at_the_end = forms.CharField(label=u"¿Qué avances concretos esperas que se logren durante el periodo del alcalde (4 años)?",
Expand All @@ -69,7 +69,7 @@ class ProposalFormBase(forms.Form):
when = forms.ChoiceField(choices=WHEN_CHOICES, label=_(u'¿En qué plazo te gustaría que esté solucionado?'))
title = forms.CharField(label=_(u'Título corto'),
help_text=_(u"Un título que nos permita describir tu propuesta\
ciudadana. Ej: 50% más de ciclovías para la comuna"),
ciudadana. Ej: 50% más de ciclovías para la comuna"),
max_length=256,)
clasification = forms.ChoiceField(choices=TOPIC_CHOICES, label=_(u'¿Cómo clasificarías tu propuesta?'))
allies = forms.CharField(label=_(u'¿Quiénes son tus posibles aliados?'),
Expand Down
21 changes: 21 additions & 0 deletions popular_proposal/migrations/0009_popularproposal_slug.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# -*- coding: utf-8 -*-
# Generated by Django 1.9.2 on 2016-04-18 20:56
from __future__ import unicode_literals

import autoslug.fields
from django.db import migrations


class Migration(migrations.Migration):

dependencies = [
('popular_proposal', '0008_proposaltemporarydata_overall_comments'),
]

operations = [
migrations.AddField(
model_name='popularproposal',
name='slug',
field=autoslug.fields.AutoSlugField(default='', editable=False, populate_from='title', unique=True),
),
]
24 changes: 24 additions & 0 deletions popular_proposal/migrations/0010_auto_20160418_2117.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# -*- coding: utf-8 -*-
# Generated by Django 1.9.2 on 2016-04-18 21:17
from __future__ import unicode_literals

from django.db import migrations


def gen_slug(apps, schema_editor):
PopularProposal = apps.get_model('popular_proposal', 'PopularProposal')
counter = 0
for popular_proposal in PopularProposal.objects.all():
counter += 1
popular_proposal.slug = 'proposal_{:d}'.format(counter)
popular_proposal.save()

class Migration(migrations.Migration):

dependencies = [
('popular_proposal', '0009_popularproposal_slug'),
]

operations = [
migrations.RunPython(gen_slug, reverse_code=migrations.RunPython.noop),
]
6 changes: 6 additions & 0 deletions popular_proposal/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
from django.utils.encoding import python_2_unicode_compatible
from backend_citizen.models import Enrollment
from django.contrib.sites.models import Site
from autoslug import AutoSlugField
from django.core.urlresolvers import reverse


class NeedingModerationManager(models.Manager):
Expand Down Expand Up @@ -105,6 +107,7 @@ def __str__(self):
@python_2_unicode_compatible
class PopularProposal(models.Model):
title = models.CharField(max_length=255, default='')
slug = AutoSlugField(populate_from='title', unique=True)
proposer = models.ForeignKey(User, related_name='proposals')
area = models.ForeignKey(Area, related_name='proposals')
data = PickledObjectField()
Expand All @@ -119,6 +122,9 @@ class PopularProposal(models.Model):

def __str__(self):
return self.title

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


class Subscription(models.Model):
Expand Down
10 changes: 9 additions & 1 deletion popular_proposal/tests/form_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
from django.core import mail
from django.template.loader import get_template
from django.template import Context, Template
from popular_proposal.forms import WHEN_CHOICES
from popular_proposal.forms import WHEN_CHOICES, ProposalFormBase


class FormTestCase(ProposingCycleTestCaseBase):
Expand Down Expand Up @@ -161,3 +161,11 @@ def test_when_template_tag(self):
template = Template("{% load votainteligente_extras %}{{ 'perrito'|popular_proposal_when }}")
self.assertEquals(template.render(Context({})), 'perrito')

def test_form_questions_template_tag(self):
fields = ProposalFormBase.base_fields
key = fields.keys()[0]
question = fields[key].label
template = Template("{% load votainteligente_extras %}{{ 'problem'|popular_proposal_question }}")
self.assertEquals(template.render(Context({})), question)
template = Template("{% load votainteligente_extras %}{{ 'perrito'|popular_proposal_question }}")
self.assertEquals(template.render(Context({})), 'perrito')
1 change: 1 addition & 0 deletions popular_proposal/tests/new_proposal_cycle_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,7 @@ def test_instantiate_one(self):
)
self.assertTrue(popular_proposal.created)
self.assertTrue(popular_proposal.updated)
self.assertTrue(popular_proposal.slug)
self.assertEquals(popular_proposal.title, u'This is a title')
self.assertIn(popular_proposal, self.fiera.proposals.all())
self.assertIn(popular_proposal, self.arica.proposals.all())
Expand Down
15 changes: 15 additions & 0 deletions popular_proposal/tests/views_tests.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# coding=utf-8
from popular_proposal.tests import ProposingCycleTestCaseBase as TestCase
from django.core.urlresolvers import reverse
from popular_proposal.models import PopularProposal


class ProposalViewTestCase(TestCase):
Expand All @@ -12,3 +13,17 @@ def test_there_is_a_page(self):
response = self.client.get(url)
self.assertEquals(response.status_code, 200)
self.assertTemplateUsed('popular_proposals/home.html')

def test_there_is_a_page_for_popular_proposal(self):
popular_proposal = PopularProposal.objects.create(proposer=self.fiera,
area=self.arica,
data=self.data,
title=u'This is a title'
)
# no need to be logged in
url = reverse('popular_proposals:detail', kwargs={'slug': popular_proposal.slug})
self.assertEquals(popular_proposal.get_absolute_url(), url)
response = self.client.get(url)
self.assertEquals(response.status_code, 200)
self.assertEqual(response.context['popular_proposal'], popular_proposal)
self.assertTemplateUsed(response, 'popular_proposal/detail.html')
6 changes: 5 additions & 1 deletion popular_proposal/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,16 @@
ThanksForProposingView,
SubscriptionView,
HomeView,
PopularProposalDetailView,
)

urlpatterns = patterns('',
url(r'^/?$',
url(r'^$',
HomeView.as_view(),
name='home'),
url(r'^detail/(?P<slug>[-\w]+)/?$',
PopularProposalDetailView.as_view(),
name='detail'),
url(r'^(?P<slug>[-\w]+)/?$',
ProposalCreationView.as_view(),
name='propose'),
Expand Down
7 changes: 7 additions & 0 deletions popular_proposal/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
from django.utils.decorators import method_decorator
from django.contrib.auth.decorators import login_required
from django.views.generic.base import TemplateView
from django.views.generic.detail import DetailView
from popular_proposal.models import PopularProposal


Expand Down Expand Up @@ -71,3 +72,9 @@ def form_valid(self, form):

class HomeView(TemplateView):
template_name = 'popular_proposal/home.html'


class PopularProposalDetailView(DetailView):
model = PopularProposal
template_name = 'popular_proposal/detail.html'
context_object_name = 'popular_proposal'
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@


Puedes ver tu propuesta en el siguiente link:
http://{{site.domain}}{{ temporary_data.created_proposal.get_absolute_url }}

Y acá puedes ver la lista de todas las propuestas de {{area}}:
http://{{site.domain}}{% url 'area' slug=area.id %}


Expand Down
36 changes: 36 additions & 0 deletions votai_general_theme/templates/popular_proposal/_likers.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
{% load staticfiles %}
{% load votainteligente_extras %}
{% load i18n %}
{% load thumbnail %}
{% if proposal.likers.all %}

<div class="row">
<div class="col-md-12">
<div class="alert alert-success" role="alert">
<span class="badge">{{proposal.likers.count}}</span>
{% blocktrans %}Ciudadanos apoyan{% endblocktrans %}
</div>

</div>
</div>
{% endif %}
<div class="row">
<div class="col-md-12">
{% if user.is_authenticated %}

{% if not user|likes:proposal %}
<a class="btn btn-md btn-success full-width" data-toggle="modal" data-target="#supportProposal"
data-url="{% url 'popular_proposals:like_a_proposal' pk=proposal.id %}">
{% blocktrans %}Apoyar{% endblocktrans %}
</span>
</a>
{% endif %}
{% else %}
<a class="btn btn-md btn-success full-width" href="{% url 'auth_login' %}">
{% blocktrans %}Apoyar{% endblocktrans %}
</span>
</a>

{% endif%}
</div>
</div>
45 changes: 45 additions & 0 deletions votai_general_theme/templates/popular_proposal/detail.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
{% extends "base.html" %}
{% load votainteligente_extras %}
{% load staticfiles %}
{% load i18n %}
{% load thumbnail %}
{% load bootstrap_tags %}
{% block extrajs %}
$(function(){
$('.loadFromUrl').on('show.bs.modal', function (event) {
var anchor = $(event.relatedTarget) // Button that triggered the modal
var modal = $(this)
var body = modal.find('.modal-body');
body.load(anchor.data('url'));
})
$('[data-toggle="tooltip"]').tooltip();
});
{% endblock extrajs %}

{% block title %}{{popular_proposal.title}}{% endblock title%}

{% block content %}
{% include 'modal.html' with modalId='supportProposal' title='Apoya una propuesta' %}
<div>


<!-- Featured Elections -->
<div class="contenedorDestacado fondo-blanco">
<h1>{{popular_proposal.title}}</h1>
<div class="text-right"><a href="{% url 'area' slug=popular_proposal.area.id %}" class="btn btn-primary btn-lg">{{popular_proposal.area}}</a></div>

<dl>


{% for key, value in popular_proposal.data.items %}
<dt>{{key|popular_proposal_question}}</dt>
<dd>{{value|popular_proposal_when}}</dd>
{% endfor %}
</dl>
</div>
{% include 'popular_proposal/_likers.html' with proposal=popular_proposal %}
</div>
{% endblock content %}

{% block extrafooter %}
{% endblock extrafooter %}
Original file line number Diff line number Diff line change
Expand Up @@ -10,37 +10,8 @@
{% else %}
{{proposal.data.solution}}
{% endif %}
{% if proposal.likers.all %}
<div class="row">
<div class="col-md-12">
<div class="alert alert-success" role="alert">
<span class="badge">{{proposal.likers.count}}</span>
{% blocktrans %}Ciudadanos apoyan{% endblocktrans %}
</div>

</div>
</div>
{% endif %}
<div class="row">
<div class="col-md-12">
{% if user.is_authenticated %}

{% if not user|likes:proposal %}
<a class="btn btn-md btn-success full-width" data-toggle="modal" data-target="#supportProposal"
data-url="{% url 'popular_proposals:like_a_proposal' pk=proposal.id %}">
{% blocktrans %}Apoyar{% endblocktrans %}
</span>
</a>
{% endif %}
{% else %}
<a class="btn btn-md btn-success full-width" href="{% url 'auth_login' %}">
{% blocktrans %}Apoyar{% endblocktrans %}
</span>
</a>

{% endif%}
</div>
</div>
</div>
<a href="{% url 'popular_proposals:detail' slug=proposal.slug %}"><i class="fa fa-link" aria-hidden="true"></i></a>
{% include 'popular_proposal/_likers.html' with proposal=proposal %}
</div>
</div>
</div>
9 changes: 8 additions & 1 deletion votai_general_theme/templatetags/votainteligente_extras.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
from django.contrib.sites.models import Site
from popolo.models import Area
from django.core.urlresolvers import reverse
from popular_proposal.forms import WHEN_CHOICES
from popular_proposal.forms import WHEN_CHOICES, ProposalFormBase


@register.simple_tag
Expand Down Expand Up @@ -188,3 +188,10 @@ def popular_proposal_when(when):
if item[0] == when:
return item[1]
return when

@register.filter(name='popular_proposal_question')
def popular_proposal_question(question):
fields = ProposalFormBase.base_fields
if question not in fields.keys():
return question
return getattr(fields[question], 'label', question)
1 change: 0 additions & 1 deletion votainteligente/votainteligente_settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@


DEBUG = True
TEMPLATE_DEBUG = DEBUG
DEFAULT_CANDIDATE_EXTRA_INFO = {
"portrait_photo": "/static/img/candidate-default.jpg",
'custom_ribbon': 'ribbon text'
Expand Down

0 comments on commit 947056a

Please sign in to comment.