From 39a5840a9f17fb13a1a5d2190664e875579e4f5c Mon Sep 17 00:00:00 2001 From: amercader Date: Tue, 21 Feb 2012 17:06:24 +0000 Subject: [PATCH 1/7] [bugfix][noticket] Activity streams fail if the object has no id property --- ckan/lib/activity.py | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/ckan/lib/activity.py b/ckan/lib/activity.py index 9bbde7146fe..9fbc1a67e7f 100644 --- a/ckan/lib/activity.py +++ b/ckan/lib/activity.py @@ -92,6 +92,12 @@ def before_commit(self, session): objects = object_cache[activity_type] for obj in objects: logger.debug("Looking at %s object %s" % (activity_type, obj)) + + if not hasattr(obj,"id"): + logger.debug("Object has no id, skipping...") + continue + + if activity_type == "new" and obj.id in activities: logger.debug("This object was already logged as a new " "package") From 74075f8696ec2ec8e2bd0e99ebbd09837bd2b3ba Mon Sep 17 00:00:00 2001 From: Sean Hammond Date: Tue, 21 Feb 2012 19:05:40 +0100 Subject: [PATCH 2/7] Correct a typo in a string --- ckan/templates/js_strings.html | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ckan/templates/js_strings.html b/ckan/templates/js_strings.html index 55c056bdc96..513a5c2ad25 100644 --- a/ckan/templates/js_strings.html +++ b/ckan/templates/js_strings.html @@ -22,7 +22,7 @@ CKAN.Strings.failedToSave = "${_('Failed to save, possibly due to invalid data ')}"; CKAN.Strings.addDataset = "${_('Add Dataset')}"; CKAN.Strings.addGroup = "${_('Add Group')}"; - CKAN.Strings.youHaveUnsavedChanges = "${_("You have unsaved changed. Make sure to click 'Save Changes' below before leaving this page.")}"; + CKAN.Strings.youHaveUnsavedChanges = "${_("You have unsaved changes. Make sure to click 'Save Changes' below before leaving this page.")}"; CKAN.Strings.loading = "${_('Loading...')}"; CKAN.Strings.noNameBrackets = "${_('(no name)')}"; CKAN.Strings.deleteThisResourceQuestion = "${_('Delete the resource \'%name%\'?')}" From 901282c985666bef9c9ce95dcba4578790b6d137 Mon Sep 17 00:00:00 2001 From: Rufus Pollock Date: Wed, 22 Feb 2012 12:53:03 +0000 Subject: [PATCH 3/7] [bugfix,user/read][xs]: hide email address on user page. --- ckan/templates/user/read.html | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/ckan/templates/user/read.html b/ckan/templates/user/read.html index 318b9f12321..43716c66a3f 100644 --- a/ckan/templates/user/read.html +++ b/ckan/templates/user/read.html @@ -21,6 +21,13 @@
Name
${c.user_dict['fullname'] or 'No name provided'}
+
Member since
+
${h.render_datetime(c.user_dict['created'])}
+ +
About
+
${c.about_formatted}
+
+
Email
@@ -30,13 +37,6 @@ No email
-
Member since
-
${h.render_datetime(c.user_dict['created'])}
- -
About
-
${c.about_formatted}
-
-
API Key
From d37d4b1be221871fbeac36c443afb73fb8f1956f Mon Sep 17 00:00:00 2001 From: John Glover Date: Wed, 22 Feb 2012 13:41:27 +0000 Subject: [PATCH 4/7] [1817][schema] Add users and groups to default group schema --- ckan/logic/schema.py | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/ckan/logic/schema.py b/ckan/logic/schema.py index 961bb293924..164343a4eac 100644 --- a/ckan/logic/schema.py +++ b/ckan/logic/schema.py @@ -187,6 +187,16 @@ def default_group_schema(): 'packages': { "id": [not_empty, unicode, package_id_or_name_exists], "__extras": [ignore] + }, + 'users': { + "name": [not_empty, unicode], + "capacity": [ignore_missing], + "__extras": [ignore] + }, + 'groups': { + "name": [not_empty, unicode], + "capacity": [ignore_missing], + "__extras": [ignore] } } return schema From 0fc7cc533650d5477dd0eca6157802054c97132a Mon Sep 17 00:00:00 2001 From: Toby Date: Wed, 22 Feb 2012 13:46:57 +0000 Subject: [PATCH 5/7] [xs] bugfix default locale not needed --- ckan/lib/i18n.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/ckan/lib/i18n.py b/ckan/lib/i18n.py index c9691e3f213..743ef880aad 100644 --- a/ckan/lib/i18n.py +++ b/ckan/lib/i18n.py @@ -89,7 +89,8 @@ def get_available_locales(): def handle_request(request, tmpl_context): ''' Set the language for the request ''' - lang = request.environ.get('CKAN_LANG', config['ckan.locale_default']) + lang = request.environ.get('CKAN_LANG', + config.get('ckan.locale_default', 'en')) if lang != 'en': i18n.set_lang(lang) tmpl_context.language = lang From 3f7e5f081e3a2fa59598ae8990b0d7cd1e353e3e Mon Sep 17 00:00:00 2001 From: kindly Date: Wed, 22 Feb 2012 17:15:27 +0000 Subject: [PATCH 6/7] [1826] make query dismax and change package filtering to use fq for filtering --- ckan/controllers/package.py | 4 +++- ckan/lib/search/query.py | 13 ++++++------- ckan/tests/functional/test_search.py | 2 +- ckan/tests/lib/test_solr_package_search.py | 13 +++++++++---- 4 files changed, 19 insertions(+), 13 deletions(-) diff --git a/ckan/controllers/package.py b/ckan/controllers/package.py index 5884e8c98c1..ff9082b0d5d 100644 --- a/ckan/controllers/package.py +++ b/ckan/controllers/package.py @@ -239,12 +239,13 @@ def pager_url(q=None, page=None): try: c.fields = [] search_extras = {} + fq = '' for (param, value) in request.params.items(): if not param in ['q', 'page'] \ and len(value) and not param.startswith('_'): if not param.startswith('ext_'): c.fields.append((param, value)) - q += ' %s: "%s"' % (param, value) + fq += ' %s:"%s"' % (param, value) else: search_extras[param] = value @@ -253,6 +254,7 @@ def pager_url(q=None, page=None): data_dict = { 'q':q, + 'fq':fq, 'facet.field':g.facets, 'rows':limit, 'start':(page-1)*limit, diff --git a/ckan/lib/search/query.py b/ckan/lib/search/query.py index 3ad1608f4ea..e4d6dbb6152 100644 --- a/ckan/lib/search/query.py +++ b/ckan/lib/search/query.py @@ -282,13 +282,12 @@ def run(self, query): # return results as json encoded string query['wt'] = query.get('wt', 'json') - # query field weighting: disabled for now as solr 3.* is required for - # the 'edismax' query parser, our current Ubuntu version only has - # packages for 1.4 - # - # query['defType'] = 'edismax' - # query['tie'] = '0.5' - # query['qf'] = query.get('qf', QUERY_FIELDS) + # If the query has a colon in it then consider it a fielded search and do use dismax. + if ':' not in query['q']: + query['defType'] = 'dismax' + query['tie'] = '0.1' + query['mm'] = '1' + query['qf'] = query.get('qf', QUERY_FIELDS) conn = make_connection() log.debug('Package query: %r' % query) diff --git a/ckan/tests/functional/test_search.py b/ckan/tests/functional/test_search.py index bafbd0904ac..fe1802c76bf 100644 --- a/ckan/tests/functional/test_search.py +++ b/ckan/tests/functional/test_search.py @@ -67,7 +67,7 @@ def test_2_title(self): # multiple words res = self.app.get('/dataset?q=Government%20Expenditure') - result = self._check_results(res, 1, 'uk-government-expenditure') + result = self._check_results(res, 5, 'uk-government-expenditure') class TestSearch2(FunctionalTestCase, PylonsTestCase):#, TestPackageForm): diff --git a/ckan/tests/lib/test_solr_package_search.py b/ckan/tests/lib/test_solr_package_search.py index e530a15173e..6ec2b2fa2c4 100644 --- a/ckan/tests/lib/test_solr_package_search.py +++ b/ckan/tests/lib/test_solr_package_search.py @@ -92,13 +92,17 @@ def test_2_title(self): assert self._pkg_names(result) == 'se-opengov', self._pkg_names(result) # multiple words result = search.query_for(model.Package).run({'q': u'Government Expenditure'}) - assert self._pkg_names(result) == 'uk-government-expenditure', self._pkg_names(result) + # uk-government-expenditure is the best match but all other results should be retured + assert self._pkg_names(result).startswith('uk-government-expenditure'), self._pkg_names(result) + # se-opengov has only government in tags, all others hav it in title. + assert self._pkg_names(result).endswith('se-opengov'), self._pkg_names(result) # multiple words wrong order result = search.query_for(model.Package).run({'q': u'Expenditure Government'}) - assert self._pkg_names(result) == 'uk-government-expenditure', self._pkg_names(result) - # multiple words, one doesn't match + assert self._pkg_names(result).startswith('uk-government-expenditure'), self._pkg_names(result) + assert self._pkg_names(result).endswith('se-opengov'), self._pkg_names(result) + # multiple words all should match government result = search.query_for(model.Package).run({'q': u'Expenditure Government China'}) - assert len(result['results']) == 0, self._pkg_names(result) + assert len(result['results']) == 5, self._pkg_names(result) def test_3_licence(self): # this should result, but it is here to check that at least it does not error @@ -315,6 +319,7 @@ def test_overall(self): check_search_results('annakarenina', 1, ['annakarenina']) check_search_results('warandpeace', 1, ['warandpeace']) check_search_results('', 2) + check_search_results('A Novel By Tolstoy', 1, ['annakarenina']) check_search_results('title:Novel', 1, ['annakarenina']) check_search_results('title:peace', 0) From 1bcb88563b56070894d3f204b46aaa450df97b0a Mon Sep 17 00:00:00 2001 From: kindly Date: Thu, 23 Feb 2012 01:02:15 +0000 Subject: [PATCH 7/7] [1822] change query fields for multilingual query --- ckanext/multilingual/plugin.py | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/ckanext/multilingual/plugin.py b/ckanext/multilingual/plugin.py index fed6dd3caaa..2667e5fde0a 100644 --- a/ckanext/multilingual/plugin.py +++ b/ckanext/multilingual/plugin.py @@ -1,6 +1,9 @@ import ckan from ckan.plugins import SingletonPlugin, implements, IPackageController import pylons +from pylons import config + +LANGS = ['en', 'fr', 'de', 'es', 'it', 'nl', 'ro', 'pt', 'pl'] class MultilingualDataset(SingletonPlugin): implements(IPackageController, inherit=True) @@ -9,6 +12,25 @@ def before_index(self, search_params): return search_params def before_search(self, search_params): + lang_set = set(LANGS) + current_lang = pylons.request.environ['CKAN_LANG'] + # fallback to default locale if locale not in suported langs + if not current_lang in lang_set: + current_lang = config.get('ckan.locale_default') + # fallback to english if default locale is not supported + if not current_lang in lang_set: + current_lang = 'en' + # treat current lang differenly so remove from set + lang_set.remove(current_lang) + + # weight current lang more highly + query_fields = 'title_%s^8 text_%s^4' % (current_lang, current_lang) + + for lang in lang_set: + query_fields += ' title_%s^2 text_%s' % (lang, lang) + + search_params['qf'] = query_fields + return search_params # FIXME: Look for translation in fallback language when none found in