Skip to content

Commit

Permalink
Added the ability to select between showing percentage or number of v…
Browse files Browse the repository at this point in the history
…otes. gh-4
  • Loading branch information
frapell committed Jan 7, 2012
1 parent f3a5f4c commit b23b320
Show file tree
Hide file tree
Showing 5 changed files with 111 additions and 42 deletions.
12 changes: 12 additions & 0 deletions src/collective/polls/content/poll.py
Expand Up @@ -39,6 +39,10 @@
SimpleTerm(value=u'pie', title=_(u'Pie Chart')),
SimpleTerm(value=u'numbers', title=_(u'Numbers Only'))])

format_options = SimpleVocabulary(
[SimpleTerm(value=u'percentage', title=_(u'Percentage')),
SimpleTerm(value=u'numbers', title=_(u'Numbers'))])


class IOption(interface.Interface):
''' An option in a poll '''
Expand Down Expand Up @@ -82,6 +86,13 @@ class IPoll(form.Schema):
required=True,
source=graph_options)

results_format = schema.Choice(
title=_(u'Results Format'),
description=_(u"Format to show the numbers."),
default='numbers',
required=True,
source=format_options)

options = schema.List(
title=_(u"Available options"),
value_type=DictRow(title=_(u'Option'),
Expand Down Expand Up @@ -140,6 +151,7 @@ def getResults(self):
all_results.append((item['description'],
item['votes'],
item['percentage']))

return all_results

def _validateVote(self, options=[]):
Expand Down
10 changes: 9 additions & 1 deletion src/collective/polls/content/poll_templates/view.pt
Expand Up @@ -47,7 +47,15 @@
<ul id="results">
<li tal:repeat="option_result results">
<span class="option_description" tal:content="python: option_result[0]" />:
<span class="option_result" tal:content="python: option_result[1]" />

<span class="option_result"
tal:content="python: option_result[1]"
tal:condition="python:context.results_format!='percentage'"/>

<span class="option_result"
tal:content="python: '%.2f%%'%(option_result[2]*100)"
tal:condition="python:context.results_format=='percentage'"/>

</li>
</ul>
<tal:barchart condition="python:context.results_graph=='bar'">
Expand Down
42 changes: 29 additions & 13 deletions src/collective/polls/locales/collective.polls.pot
Expand Up @@ -4,7 +4,7 @@
msgid ""
msgstr ""
"Project-Id-Version: PACKAGE VERSION\n"
"POT-Creation-Date: 2012-01-07 03:55+0000\n"
"POT-Creation-Date: 2012-01-07 23:14+0000\n"
"PO-Revision-Date: YEAR-MO-DA HO:MI +ZONE\n"
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
"Language-Team: LANGUAGE <LL@li.org>\n"
Expand All @@ -26,15 +26,15 @@ msgstr ""
msgid "A portlet to allow voting on a specific poll"
msgstr ""

#: collective/polls/content/poll.py:60
#: collective/polls/content/poll.py:64
msgid "Allow anonymous"
msgstr ""

#: collective/polls/content/poll.py:61
#: collective/polls/content/poll.py:65
msgid "Allow not logged in users to vote."
msgstr ""

#: collective/polls/content/poll.py:86
#: collective/polls/content/poll.py:97
msgid "Available options"
msgstr ""

Expand All @@ -46,23 +46,27 @@ msgstr ""
msgid "Bar Chart"
msgstr ""

#: collective/polls/content/poll.py:51
#: collective/polls/content/poll.py:55
msgid "Description"
msgstr ""

#: collective/polls/content/poll.py:80
#: collective/polls/content/poll.py:91
msgid "Format to show the numbers."
msgstr ""

#: collective/polls/content/poll.py:84
msgid "Format to show the results."
msgstr ""

#: collective/polls/content/poll.py:79
#: collective/polls/content/poll.py:83
msgid "Graph"
msgstr ""

#: collective/polls/portlet/voteportlet.py:53
msgid "Header"
msgstr ""

#: collective/polls/content/poll.py:292
#: collective/polls/content/poll.py:304
msgid "Invalid option"
msgstr ""

Expand All @@ -74,18 +78,26 @@ msgstr ""
msgid "Nothing to see here"
msgstr ""

#: collective/polls/content/poll.py:44
msgid "Numbers"
msgstr ""

#: collective/polls/content/poll.py:40
msgid "Numbers Only"
msgstr ""

#: collective/polls/content/poll.py:87
#: collective/polls/content/poll.py:98
msgid "Option"
msgstr ""

#: collective/polls/portlet/voteportlet.pt:21
msgid "Partial results"
msgstr ""

#: collective/polls/content/poll.py:43
msgid "Percentage"
msgstr ""

#: collective/polls/content/poll.py:39
msgid "Pie Chart"
msgstr ""
Expand All @@ -95,19 +107,23 @@ msgstr ""
msgid "Poll"
msgstr ""

#: collective/polls/content/poll.py:90
msgid "Results Format"
msgstr ""

#: collective/polls/content/poll_templates/view.pt:45
msgid "Results:"
msgstr ""

#: collective/polls/content/poll.py:72
#: collective/polls/content/poll.py:76
msgid "Show partial results"
msgstr ""

#: collective/polls/content/poll.py:73
#: collective/polls/content/poll.py:77
msgid "Show partial results after a voter has already voted."
msgstr ""

#: collective/polls/content/poll.py:306
#: collective/polls/content/poll.py:318
msgid "Thanks for your vote"
msgstr ""

Expand All @@ -130,7 +146,7 @@ msgstr ""
msgid "Which poll to show in the portlet."
msgstr ""

#: collective/polls/content/poll.py:311
#: collective/polls/content/poll.py:323
msgid "You are not authorized to vote"
msgstr ""

49 changes: 33 additions & 16 deletions src/collective/polls/locales/es/LC_MESSAGES/collective.polls.po
@@ -1,11 +1,11 @@
# Franco Pellegrini <frapell@gmail.com>, 2011.
# Franco Pellegrini <frapell@gmail.com>, 2011, 2012.
msgid ""
msgstr ""
"Project-Id-Version: collective.polls\n"
"POT-Creation-Date: YEAR-MO-DA HO:MI +ZONE\n"
"PO-Revision-Date: 2012-01-06 21:56-0600\n"
"Last-Translator: Héctor Velarde <hector.velarde@gmail.com>\n"
"Language-Team: Spanish <https://github.com/collective>\n"
"PO-Revision-Date: 2012-01-07 20:12-0300\n"
"Last-Translator: Franco Pellegrini\n"
"Language-Team: Spanish <>\n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: 8bit\n"
Expand All @@ -15,6 +15,7 @@ msgstr ""
"Preferred-Encodings: utf-8 latin1\n"
"Domain: collective.polls\n"
"X-Generator: Lokalize 1.2\n"
"Language: es\n"

#: collective/polls/profiles/default/types/collective.polls.poll.xml
msgid "A poll"
Expand All @@ -25,15 +26,15 @@ msgstr "Una encuesta"
msgid "A portlet to allow voting on a specific poll"
msgstr "Un portlet que permite votar en una encuesta específica"

#: collective/polls/content/poll.py:60
#: collective/polls/content/poll.py:64
msgid "Allow anonymous"
msgstr "Permitir anónimos"

#: collective/polls/content/poll.py:61
#: collective/polls/content/poll.py:65
msgid "Allow not logged in users to vote."
msgstr "Permitir a usuarios que no han iniciado sesión, votar."

#: collective/polls/content/poll.py:86
#: collective/polls/content/poll.py:97
msgid "Available options"
msgstr "Opciones disponibles"

Expand All @@ -45,23 +46,27 @@ msgstr "Opciones disponibles:"
msgid "Bar Chart"
msgstr "Gráfico de barras"

#: collective/polls/content/poll.py:51
#: collective/polls/content/poll.py:55
msgid "Description"
msgstr "Descripción"

#: collective/polls/content/poll.py:80
#: collective/polls/content/poll.py:91
msgid "Format to show the numbers."
msgstr "Formato para mostrar los numeros."

#: collective/polls/content/poll.py:84
msgid "Format to show the results."
msgstr "Formato en el que se mostrarán los resultados."

#: collective/polls/content/poll.py:79
#: collective/polls/content/poll.py:83
msgid "Graph"
msgstr "Gráfico"

#: collective/polls/portlet/voteportlet.py:53
msgid "Header"
msgstr "Cabecera"

#: collective/polls/content/poll.py:292
#: collective/polls/content/poll.py:304
msgid "Invalid option"
msgstr "Opción inválida"

Expand All @@ -73,18 +78,26 @@ msgstr "La encuesta abierta más reciente"
msgid "Nothing to see here"
msgstr "No hay nada aquí que pueda ver"

#: collective/polls/content/poll.py:44
msgid "Numbers"
msgstr "Números"

#: collective/polls/content/poll.py:40
msgid "Numbers Only"
msgstr "Sólo números"

#: collective/polls/content/poll.py:87
#: collective/polls/content/poll.py:98
msgid "Option"
msgstr "Opción"

#: collective/polls/portlet/voteportlet.pt:21
msgid "Partial results"
msgstr "Resultados parciales"

#: collective/polls/content/poll.py:43
msgid "Percentage"
msgstr "Porcentaje"

#: collective/polls/content/poll.py:39
msgid "Pie Chart"
msgstr "Gráfico de tarta"
Expand All @@ -94,19 +107,23 @@ msgstr "Gráfico de tarta"
msgid "Poll"
msgstr "Encuesta"

#: collective/polls/content/poll.py:90
msgid "Results Format"
msgstr "Formato de Resultados"

#: collective/polls/content/poll_templates/view.pt:45
msgid "Results:"
msgstr "Resultados:"

#: collective/polls/content/poll.py:72
#: collective/polls/content/poll.py:76
msgid "Show partial results"
msgstr "Mostrar resultados parciales"

#: collective/polls/content/poll.py:73
#: collective/polls/content/poll.py:77
msgid "Show partial results after a voter has already voted."
msgstr "Mostrar resultados parciales luego de que el votante ya haya votado."

#: collective/polls/content/poll.py:306
#: collective/polls/content/poll.py:318
msgid "Thanks for your vote"
msgstr "Gracias por su voto"

Expand All @@ -124,7 +141,7 @@ msgstr "Portlet de votación"
msgid "Which poll to show in the portlet."
msgstr "Qué encuesta mostrar en el portlet."

#: collective/polls/content/poll.py:311
#: collective/polls/content/poll.py:323
msgid "You are not authorized to vote"
msgstr "Usted no está autorizado para votar"

0 comments on commit b23b320

Please sign in to comment.