Skip to content

Commit

Permalink
Merge pull request #22 from conwetlab/develop
Browse files Browse the repository at this point in the history
Version 0.3.1
  • Loading branch information
aitormagan committed Apr 28, 2016
2 parents f09b87b + 4817db4 commit 8a2b51e
Show file tree
Hide file tree
Showing 12 changed files with 85 additions and 45 deletions.
3 changes: 2 additions & 1 deletion MANIFEST.in
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
recursive-include ckanext/datarequests/templates *
recursive-include ckanext/datarequests/public *
recursive-include ckanext/datarequests/fanstatic *
recursive-include ckanext/datarequests/fanstatic *
recursive-include ckanext/datarequests/i18n *
8 changes: 4 additions & 4 deletions ckanext/datarequests/controllers/ui_controller.py
Original file line number Diff line number Diff line change
Expand Up @@ -258,7 +258,7 @@ def delete(self, id):
try:
tk.check_access(constants.DATAREQUEST_DELETE, context, data_dict)
datarequest = tk.get_action(constants.DATAREQUEST_DELETE)(context, data_dict)
helpers.flash_notice(tk._('Your Data Request %s has been deleted') % datarequest.get('title', ''))
helpers.flash_notice(tk._('Data Request %s has been deleted') % datarequest.get('title', ''))
base.redirect(helpers.url_for(controller='ckanext.datarequests.controllers.ui_controller:DataRequestsUI', action='index'))
except tk.ObjectNotFound as e:
log.warn(e)
Expand Down Expand Up @@ -363,9 +363,9 @@ def comment(self, id):
updated_comment = tk.get_action(action)(context, comment_data_dict)

if not comment_id:
flash_message = tk._('Your comment has been published')
flash_message = tk._('Comment has been published')
else:
flash_message = tk._('Your comment has been updated')
flash_message = tk._('Comment has been updated')

helpers.flash_notice(flash_message)

Expand Down Expand Up @@ -411,7 +411,7 @@ def delete_comment(self, datarequest_id, comment_id):
data_dict = {'id': comment_id}
tk.check_access(constants.DATAREQUEST_COMMENT_DELETE, context, data_dict)
tk.get_action(constants.DATAREQUEST_COMMENT_DELETE)(context, data_dict)
helpers.flash_notice(tk._('Your comment has been deleted'))
helpers.flash_notice(tk._('Comment has been deleted'))
base.redirect(helpers.url_for(controller='ckanext.datarequests.controllers.ui_controller:DataRequestsUI',
action='comment', id=datarequest_id))
except tk.ObjectNotFound as e:
Expand Down
16 changes: 8 additions & 8 deletions ckanext/datarequests/i18n/ckanext-datarequests.pot
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@
#, fuzzy
msgid ""
msgstr ""
"Project-Id-Version: ckanext-datarequests 0.3.0\n"
"Project-Id-Version: ckanext-datarequests 0.3.1\n"
"Report-Msgid-Bugs-To: EMAIL@ADDRESS\n"
"POT-Creation-Date: 2016-04-25 10:19+0200\n"
"POT-Creation-Date: 2016-04-28 11:43+0200\n"
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
"Language-Team: LANGUAGE <[email protected]>\n"
Expand Down Expand Up @@ -168,7 +168,7 @@ msgstr ""

#: ckanext/datarequests/controllers/ui_controller.py:261
#, python-format
msgid "Your Data Request %s has been deleted"
msgid "Data Request %s has been deleted"
msgstr ""

#: ckanext/datarequests/controllers/ui_controller.py:268
Expand All @@ -186,11 +186,11 @@ msgid "You are not authorized to close the Data Request %s"
msgstr ""

#: ckanext/datarequests/controllers/ui_controller.py:366
msgid "Your comment has been published"
msgid "Comment has been published"
msgstr ""

#: ckanext/datarequests/controllers/ui_controller.py:368
msgid "Your comment has been updated"
msgid "Comment has been updated"
msgstr ""

#: ckanext/datarequests/controllers/ui_controller.py:374
Expand All @@ -204,7 +204,7 @@ msgid "You are not authorized to list the comments of the Data Request %s"
msgstr ""

#: ckanext/datarequests/controllers/ui_controller.py:414
msgid "Your comment has been deleted"
msgid "Comment has been deleted"
msgstr ""

#: ckanext/datarequests/controllers/ui_controller.py:419
Expand Down Expand Up @@ -407,7 +407,7 @@ msgid "No Data Requests found"
msgstr ""

#: ckanext/datarequests/templates/datarequests/snippets/datarequest_list.html:14
msgid "There are currently no Data Requests for this site"
msgid "No Data Requests found with the given criteria"
msgstr ""

#: ckanext/datarequests/templates/datarequests/snippets/datarequest_list.html:16
Expand Down Expand Up @@ -469,6 +469,6 @@ msgstr ""

#: ckanext/datarequests/tests/test_ui_controller.py:672
#, python-format
msgid "Data Request %s deleted correctly"
msgid "Your Data Request %s has been deleted"
msgstr ""

Binary file modified ckanext/datarequests/i18n/es/LC_MESSAGES/ckanext-datarequests.mo
Binary file not shown.
28 changes: 11 additions & 17 deletions ckanext/datarequests/i18n/es/LC_MESSAGES/ckanext-datarequests.po
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ msgid ""
msgstr ""
"Project-Id-Version: ckanext-datarequests 0.3.0\n"
"Report-Msgid-Bugs-To: [email protected]\n"
"POT-Creation-Date: 2016-04-25 10:19+0200\n"
"POT-Creation-Date: 2016-04-28 11:43+0200\n"
"PO-Revision-Date: 2016-04-19 11:43+0200\n"
"Last-Translator: Aitor Magán <[email protected]>\n"
"Language-Team: es <[email protected]>\n"
Expand Down Expand Up @@ -142,8 +142,8 @@ msgstr "No estás autorizado a actualizar la Solicitud de Datos %s"

#: ckanext/datarequests/controllers/ui_controller.py:261
#, python-format
msgid "Your Data Request %s has been deleted"
msgstr "Tu Solicitud de Datos %s ha sido borrada"
msgid "Data Request %s has been deleted"
msgstr "La Solicitud de Datos %s ha sido borrada"

#: ckanext/datarequests/controllers/ui_controller.py:268
#, python-format
Expand All @@ -160,12 +160,12 @@ msgid "You are not authorized to close the Data Request %s"
msgstr "No estás autorizado a cerrar la Solicitud de Datos %s"

#: ckanext/datarequests/controllers/ui_controller.py:366
msgid "Your comment has been published"
msgstr "Tu comentario ha sido publicado"
msgid "Comment has been published"
msgstr "El comentario ha sido publicado"

#: ckanext/datarequests/controllers/ui_controller.py:368
msgid "Your comment has been updated"
msgstr "Tu comentario ha sido actualizado"
msgid "Comment has been updated"
msgstr "El comentario ha sido actualizado"

#: ckanext/datarequests/controllers/ui_controller.py:374
#, python-format
Expand All @@ -178,8 +178,8 @@ msgid "You are not authorized to list the comments of the Data Request %s"
msgstr "No estás autorizado a ver los comentarios de la Solicitud de Datos %s"

#: ckanext/datarequests/controllers/ui_controller.py:414
msgid "Your comment has been deleted"
msgstr "Tu comentario ha sido borrado"
msgid "Comment has been deleted"
msgstr "El comentario ha sido borrado"

#: ckanext/datarequests/controllers/ui_controller.py:419
#, python-format
Expand Down Expand Up @@ -364,8 +364,8 @@ msgid "No Data Requests found"
msgstr "No hay Solicitudes de Datos"

#: ckanext/datarequests/templates/datarequests/snippets/datarequest_list.html:14
msgid "There are currently no Data Requests for this site"
msgstr "Actualmente no hay Solicitudes de Datos para este sitio"
msgid "No Data Requests found with the given criteria"
msgstr "No se han encontrado Solicitudes de Datos para los criterios dados"

#: ckanext/datarequests/templates/datarequests/snippets/datarequest_list.html:16
msgid "How about creating one?"
Expand All @@ -374,9 +374,3 @@ msgstr "¿Quieres crear una?"
#: ckanext/datarequests/templates/datarequests/snippets/edit_datarequest_form.html:4
msgid "Update Data Request"
msgstr "Actualizar Solicitud de Datos"

#: ckanext/datarequests/tests/test_ui_controller.py:672
#, python-format
msgid "Data Request %s deleted correctly"
msgstr "Solicitud de Datos %s borrada correctamente"

49 changes: 46 additions & 3 deletions ckanext/datarequests/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@
import os
import sys

from ckan.lib.plugins import DefaultTranslation
from functools import partial
from pylons import config

Expand All @@ -37,14 +36,19 @@ def get_config_bool_value(config_name, default_value=False):
return value


class DataRequestsPlugin(p.SingletonPlugin, DefaultTranslation):
class DataRequestsPlugin(p.SingletonPlugin):

p.implements(p.IActions)
p.implements(p.IAuthFunctions)
p.implements(p.IConfigurer)
p.implements(p.IRoutes, inherit=True)
p.implements(p.ITemplateHelpers)
p.implements(p.ITranslation)

# ITranslation only available in 2.5+
try:
p.implements(p.ITranslation)
except AttributeError:
pass

def __init__(self, name=None):
self.comments_enabled = get_config_bool_value('ckan.datarequests.comments', True)
Expand Down Expand Up @@ -184,3 +188,42 @@ def get_helpers(self):
'get_open_datarequests_number': helpers.get_open_datarequests_number,
'get_open_datarequests_badge': partial(helpers.get_open_datarequests_badge, self._show_datarequests_badge)
}

######################################################################
########################### ITRANSLATION #############################
######################################################################

# The following methods are copied from ckan.lib.plugins.DefaultTranslation
# and have been modified to fix a bug in CKAN 2.5.1 that prevents CKAN from
# starting. In addition by copying these methods, it is ensured that Data
# Requests can be used even if Itranslation isn't available (less than 2.5)

def i18n_directory(self):
'''Change the directory of the *.mo translation files
The default implementation assumes the plugin is
ckanext/myplugin/plugin.py and the translations are stored in
i18n/
'''
# assume plugin is called ckanext.<myplugin>.<...>.PluginClass
extension_module_name = '.'.join(self.__module__.split('.')[:3])
module = sys.modules[extension_module_name]
return os.path.join(os.path.dirname(module.__file__), 'i18n')

def i18n_locales(self):
'''Change the list of locales that this plugin handles
By default the will assume any directory in subdirectory in the
directory defined by self.directory() is a locale handled by this
plugin
'''
directory = self.i18n_directory()
return [ d for
d in os.listdir(directory)
if os.path.isdir(os.path.join(directory, d))
]

def i18n_domain(self):
'''Change the gettext domain handled by this plugin
This implementation assumes the gettext domain is
ckanext-{extension name}, hence your pot, po and mo files should be
named ckanext-{extension name}.mo'''
return 'ckanext-{name}'.format(name=self.name)
9 changes: 5 additions & 4 deletions ckanext/datarequests/templates/datarequests/comment.html
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,17 @@

{% snippet "datarequests/snippets/comments.html", comments=c.comments, datarequest=c.datarequest, errors=c.errors, errors_summary=c.errors_summary, updated_comment=c.updated_comment %}

<div class="comment-new">
{% if h.check_access('datarequest_comment', {'id':c.datarequest.id }) %}
{% if h.check_access('datarequest_comment', {'id':c.datarequest.id }) %}
<div class="comment-new">

{% set create_comment_error = c.updated_comment is defined and c.updated_comment.id == '' %}

{% if create_comment_error %}
<a name="comment_focus"></a>
{% endif %}

{% snippet "datarequests/snippets/comment_form.html", datarequest=c.datarequest, errors=c.errors, errors_summary=c.errors_summary, offering=c.offering, initial_text=c.updated_comment.comment if create_comment_error, focus=create_comment_error, current_user=c.userobj %}
{% endif %}
</div>
</div>
{% endif %}

{% endblock %}
1 change: 1 addition & 0 deletions ckanext/datarequests/templates/datarequests/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
</div>
{% endif %}
{% snippet 'snippets/search_form.html', query=c.q, fields=(('organization', c.organization), ('state', c.state)), sorting=c.filters, sorting_selected=c.sort, placeholder=_('Search Data Requests...'), no_bottom_border=true, count=c.datarequest_count, no_title=True %}
<br />
{{ h.snippet('datarequests/snippets/datarequest_list.html', datarequest_count=c.datarequest_count, datarequests=c.datarequests, page=c.page, q=c.q)}}
{% endblock %}
</div>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{% set title= _('No Data Requests found') if datarequest_count == 0 else '%s datarequest found' % datarequest_count %}

<!--<h2>{{ title }}</h2>-->
<!--<h2>{{ title }}</h2>!-->

{% block datarequest_search_results_list %}
{% if datarequests %}
Expand All @@ -11,9 +11,9 @@
</ul>
{% else %}
<p class="empty">
{{ _('There are currently no Data Requests for this site') }}.
{{ _('No Data Requests found with the given criteria') }}.
{% if h.check_access('datarequest_create') %}
{% link_for _('How about creating one?'), controller='ckanext.datarequests.controllers.ui_controller:DataRequestsUI', action='new' %}</a>.
{% link_for _('How about creating one?'), controller='ckanext.datarequests.controllers.ui_controller:DataRequestsUI', action='new' %}</a>
{% endif %}
</p>
{% endif %}
Expand Down
6 changes: 3 additions & 3 deletions ckanext/datarequests/tests/test_selenium.py
Original file line number Diff line number Diff line change
Expand Up @@ -420,11 +420,11 @@ def test_delete_datarequest(self):
self.delete_datarequest(datarequest_id)

# Check that there are not more data requests in the system
self.assertTrue("There are currently no Data Requests for this site."
self.assertTrue("No Data Requests found with the given criteria."
in self.driver.find_element_by_css_selector("p.empty").text)

# Check flash message
self.assertTrue("Your Data Request " + datarequest_title + " has been deleted"
self.assertTrue("Data Request " + datarequest_title + " has been deleted"
in self.driver.find_element_by_xpath("//div[@id='content']/div/div").text)

def test_close_datarequest(self):
Expand Down Expand Up @@ -644,7 +644,7 @@ def test_delete_comment(self):
# Check that the comment has been deleted
self.assertEqual("This data request has not been commented yet",
self.driver.find_element_by_css_selector("p.empty").text)
self.assertTrue("Your comment has been deleted" in self.driver.find_element_by_xpath(
self.assertTrue("Comment has been deleted" in self.driver.find_element_by_xpath(
"//div[@id='content']/div/div").text)

def test_new_comments_always_visible(self):
Expand Down
2 changes: 1 addition & 1 deletion ckanext/datarequests/tests/test_ui_controller.py
Original file line number Diff line number Diff line change
Expand Up @@ -669,7 +669,7 @@ def test_delete(self):
controller.tk.check_access.assert_called_once_with(constants.DATAREQUEST_DELETE, self.expected_context, expected_data_dict)
datarequest_delete.assert_called_once_with(self.expected_context, expected_data_dict)
controller.helpers.flash_notice.assert_called_once_with(controller.tk._(
'Your Data Request %s has been deleted' % datarequest.get('title')))
'Data Request %s has been deleted' % datarequest.get('title')))

# Redirection
controller.helpers.url_for.assert_called_once_with(
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
from setuptools import setup, find_packages
import sys, os

version = '0.3.0'
version = '0.3.1'

setup(
name='ckanext-datarequests',
Expand Down

0 comments on commit 8a2b51e

Please sign in to comment.