From dd2865da1d40c39cab0fd3be85339926b829ab51 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Aitor=20Mag=C3=A1n?= Date: Thu, 28 Apr 2016 10:53:27 +0200 Subject: [PATCH 1/4] Fix errors that prevent the plugin from working when using a dist file --- MANIFEST.in | 3 ++- ckanext/datarequests/plugin.py | 49 +++++++++++++++++++++++++++++++--- 2 files changed, 48 insertions(+), 4 deletions(-) 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/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) From 8d2bbf25d16e726b7a9c1b9018413d56871bb20a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Aitor=20Mag=C3=A1n?= Date: Thu, 28 Apr 2016 11:48:36 +0200 Subject: [PATCH 2/4] Default theme improvements --- .../datarequests/controllers/ui_controller.py | 8 ++--- .../i18n/ckanext-datarequests.pot | 16 +++++----- .../es/LC_MESSAGES/ckanext-datarequests.mo | Bin 7202 -> 7095 bytes .../es/LC_MESSAGES/ckanext-datarequests.po | 28 +++++++----------- .../templates/datarequests/comment.html | 9 +++--- .../templates/datarequests/index.html | 1 + .../snippets/datarequest_list.html | 6 ++-- ckanext/datarequests/tests/test_selenium.py | 6 ++-- 8 files changed, 35 insertions(+), 39 deletions(-) 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 da0ce362e2598f5e90e70a5db2265826ff1be69c..85a997f50c08d8e069df6d874c7bfdf6a4a89ca9 100644 GIT binary patch delta 1433 zcmZwGe`rl%7{Kv&r)%7?ad-E_b~oN(VvU&%^Ruu`Nzo!&S&p4!yWHJ7_nc9F-SCGN z!cL@=HOU{A{J4tp2MUQ$YND9@N|DGv%1XXZj{M_x@BO^bbMATH=Y8ID&(vL;lN!to z99O&=`IPWkVMz4vwJV_1M8e&egMBy#FX2eM?Z=NWL_CP2@f%JCP*NgR0mLwwdg#OAAO+dP@79g8c z^(gnR^xc9}i4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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/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): From ffc3c5826d71ed3b1b0ce55f25edf3da6d58272b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Aitor=20Mag=C3=A1n?= Date: Thu, 28 Apr 2016 11:48:50 +0200 Subject: [PATCH 3/4] Version 0.3.1 --- setup.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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', From 4817db4de128868cd0de6b211cddddf5070377dd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Aitor=20Mag=C3=A1n?= Date: Thu, 28 Apr 2016 12:02:56 +0200 Subject: [PATCH 4/4] Fix test --- ckanext/datarequests/tests/test_ui_controller.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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(