Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

9 migrate ckan2.9 py3 #10

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions ckanext/geonetwork/harvesters/geonetwork.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@

from ckan.logic import ValidationError, NotFound, get_action

from pylons import config
from ckan.plugins.toolkit import config
from datetime import datetime

log = logging.getLogger(__name__)
Expand Down Expand Up @@ -180,9 +180,9 @@ def handle_groups(self, harvest_object, group_mapping, gn_localized_url, values)
#else:
#validated_groups.append(group['id'])
validated_groups.append({'name': groupname})
except NotFound, e:
except NotFound as e:
log.warning('Group %s from category %s is not available' % (groupname, cat))
except Exception, e:
except Exception as e:
log.warning('Error handling groups for metadata %s' % harvest_object.guid)

return validated_groups
Expand Down
8 changes: 3 additions & 5 deletions ckanext/geonetwork/harvesters/utils.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
# -*- coding: utf-8 -*-
import logging
#import re
import urllib
import urllib2
import zipfile
from StringIO import StringIO
from io import StringIO
from lxml import etree

GEONETWORK_V26 = "2.6"
Expand Down Expand Up @@ -37,8 +35,8 @@ def retrieveInfo(self, uuid):
})

logger.info('Loading MEF for %s', uuid)
request = urllib2.Request(url, query)
opener = urllib2.build_opener(urllib2.HTTPCookieProcessor(), urllib2.HTTPRedirectHandler())
request = urllib.request(url, query)
opener = urllib.request.build_opener(urllib.request.HTTPCookieProcessor(), urllib.request.HTTPRedirectHandler())

response = opener.open(request) # will get a ZIP file
content = response.read()
Expand Down
53 changes: 53 additions & 0 deletions ckanext/geonetwork/helpers.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
import logging
import urllib

import ckan.model as model
import ckan.plugins as p
import ckan.lib.search as search
import ckan.lib.helpers as h

import ckan.logic as logic
from ckan.common import request

import ckanext.multilang.helpers as multilang_helpers

from ckanext.multilang.model import PackageMultilang

log = logging.getLogger(__file__)


def recent_updates(n):
#
# Return a list of the n most recently updated datasets.
#
log.debug('::::: Retrieving latest datasets: %r' % n)
context = {'model': model,
'session': model.Session,
'user': p.toolkit.c.user or p.toolkit.c.author}

data_dict = {'rows': n,
'sort': u'metadata_modified desc',
'facet': u'false'}

try:
search_results = logic.get_action('package_search')(context, data_dict)
except search.SearchError as e:
log.error('Error searching for recently updated datasets')
log.error(e)
search_results = {}

for item in search_results.get('results'):
log.info(':::::::::::: Retrieving the corresponding localized title and abstract :::::::::::::::')

lang = multilang_helpers.getLanguage()

q_results = model.Session.query(PackageMultilang)\
.filter(PackageMultilang.package_id == item.get('id'),
PackageMultilang.lang == lang).all()

if q_results:
for result in q_results:
item[result.field] = result.text

return search_results.get('results', [])

Loading