diff --git a/MANIFEST.in b/MANIFEST.in index e5b0b3c1..78d64ce5 100644 --- a/MANIFEST.in +++ b/MANIFEST.in @@ -1,3 +1,4 @@ recursive-include ckanext/datarequests/templates * recursive-include ckanext/datarequests/public * -recursive-include ckanext/datarequests/fanstatic * \ No newline at end of file +recursive-include ckanext/datarequests/fanstatic * +recursive-include ckanext/datarequests/i18n * \ No newline at end of file diff --git a/ckanext/datarequests/controllers/ui_controller.py b/ckanext/datarequests/controllers/ui_controller.py index 4dbba1be..7f5697a4 100644 --- a/ckanext/datarequests/controllers/ui_controller.py +++ b/ckanext/datarequests/controllers/ui_controller.py @@ -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) @@ -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) @@ -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: diff --git a/ckanext/datarequests/i18n/ckanext-datarequests.pot b/ckanext/datarequests/i18n/ckanext-datarequests.pot index e8a5c780..dafbc8f3 100644 --- a/ckanext/datarequests/i18n/ckanext-datarequests.pot +++ b/ckanext/datarequests/i18n/ckanext-datarequests.pot @@ -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 \n" "Language-Team: LANGUAGE \n" @@ -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 @@ -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 @@ -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 @@ -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 @@ -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 "" diff --git a/ckanext/datarequests/i18n/es/LC_MESSAGES/ckanext-datarequests.mo b/ckanext/datarequests/i18n/es/LC_MESSAGES/ckanext-datarequests.mo index da0ce362..85a997f5 100644 Binary files a/ckanext/datarequests/i18n/es/LC_MESSAGES/ckanext-datarequests.mo and b/ckanext/datarequests/i18n/es/LC_MESSAGES/ckanext-datarequests.mo differ diff --git a/ckanext/datarequests/i18n/es/LC_MESSAGES/ckanext-datarequests.po b/ckanext/datarequests/i18n/es/LC_MESSAGES/ckanext-datarequests.po index a21fc2ef..2c72468d 100644 --- a/ckanext/datarequests/i18n/es/LC_MESSAGES/ckanext-datarequests.po +++ b/ckanext/datarequests/i18n/es/LC_MESSAGES/ckanext-datarequests.po @@ -9,7 +9,7 @@ msgid "" msgstr "" "Project-Id-Version: ckanext-datarequests 0.3.0\n" "Report-Msgid-Bugs-To: amagan@conwet.com\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 \n" "Language-Team: es \n" @@ -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 @@ -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 @@ -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 @@ -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?" @@ -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" - diff --git a/ckanext/datarequests/plugin.py b/ckanext/datarequests/plugin.py index 91711b3c..b8f292ea 100644 --- a/ckanext/datarequests/plugin.py +++ b/ckanext/datarequests/plugin.py @@ -26,7 +26,6 @@ import os import sys -from ckan.lib.plugins import DefaultTranslation from functools import partial from pylons import config @@ -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) @@ -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..<...>.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) diff --git a/ckanext/datarequests/templates/datarequests/comment.html b/ckanext/datarequests/templates/datarequests/comment.html index 02110223..e6a6efb6 100644 --- a/ckanext/datarequests/templates/datarequests/comment.html +++ b/ckanext/datarequests/templates/datarequests/comment.html @@ -10,8 +10,9 @@ {% snippet "datarequests/snippets/comments.html", comments=c.comments, datarequest=c.datarequest, errors=c.errors, errors_summary=c.errors_summary, updated_comment=c.updated_comment %} -
- {% if h.check_access('datarequest_comment', {'id':c.datarequest.id }) %} + {% if h.check_access('datarequest_comment', {'id':c.datarequest.id }) %} +
+ {% set create_comment_error = c.updated_comment is defined and c.updated_comment.id == '' %} {% if create_comment_error %} @@ -19,7 +20,7 @@ {% 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 %} -
+
+ {% endif %} {% endblock %} diff --git a/ckanext/datarequests/templates/datarequests/index.html b/ckanext/datarequests/templates/datarequests/index.html index edac3452..e627353d 100644 --- a/ckanext/datarequests/templates/datarequests/index.html +++ b/ckanext/datarequests/templates/datarequests/index.html @@ -10,6 +10,7 @@ {% 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 %} +
{{ h.snippet('datarequests/snippets/datarequest_list.html', datarequest_count=c.datarequest_count, datarequests=c.datarequests, page=c.page, q=c.q)}} {% endblock %} diff --git a/ckanext/datarequests/templates/datarequests/snippets/datarequest_list.html b/ckanext/datarequests/templates/datarequests/snippets/datarequest_list.html index 4aca7f8a..c63909ba 100644 --- a/ckanext/datarequests/templates/datarequests/snippets/datarequest_list.html +++ b/ckanext/datarequests/templates/datarequests/snippets/datarequest_list.html @@ -1,6 +1,6 @@ {% set title= _('No Data Requests found') if datarequest_count == 0 else '%s datarequest found' % datarequest_count %} - + {% block datarequest_search_results_list %} {% if datarequests %} @@ -11,9 +11,9 @@ {% else %}

- {{ _('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' %}. + {% link_for _('How about creating one?'), controller='ckanext.datarequests.controllers.ui_controller:DataRequestsUI', action='new' %} {% endif %}

{% endif %} diff --git a/ckanext/datarequests/tests/test_selenium.py b/ckanext/datarequests/tests/test_selenium.py index 15e01d58..23a151e2 100644 --- a/ckanext/datarequests/tests/test_selenium.py +++ b/ckanext/datarequests/tests/test_selenium.py @@ -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): @@ -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): diff --git a/ckanext/datarequests/tests/test_ui_controller.py b/ckanext/datarequests/tests/test_ui_controller.py index b9846fe3..64e2b945 100644 --- a/ckanext/datarequests/tests/test_ui_controller.py +++ b/ckanext/datarequests/tests/test_ui_controller.py @@ -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( diff --git a/setup.py b/setup.py index 1692f84a..e47cdf80 100644 --- a/setup.py +++ b/setup.py @@ -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',