Commit a6f9ea12 authored by Oscar Perez's avatar Oscar Perez
Browse files

Fixing resource_group for ckan2.3+. Using same convention in all places

parent d8729418
import os
import ckan.plugins as p
def load_config(config_filepath):
import paste.deploy
......@@ -30,7 +30,7 @@ def get_resources(state='active', publisher_ref=None, resource_id=None,
from ckan import model
resources = model.Session.query(model.Resource) \
.filter_by(state=state)
if hasattr(model, 'ResourceGroup'):
if p.toolkit.check_ckan_version(max_version='2.2.99'):
# earlier CKANs had ResourceGroup
resources = resources.join(model.ResourceGroup)
resources = resources \
......
......@@ -5,6 +5,7 @@ import time
import re
import shutil
import itertools
import ckan.plugins as p
from pylons import config
......@@ -178,7 +179,7 @@ class Archiver(CkanCommand):
self.log.info('Queue: %s', self.options.queue)
for package in packages:
if hasattr(model, 'ResourceGroup'):
if p.toolkit.check_ckan_version(max_version='2.2.99'):
# earlier CKANs had ResourceGroup
pkg_resources = \
[res for res in
......@@ -197,7 +198,10 @@ class Archiver(CkanCommand):
time.sleep(0.1) # to try to avoid Redis getting overloaded
for resource in resources:
package = resource.resource_group.package
if p.toolkit.check_ckan_version(max_version='2.2.99'):
package = resource.resource_group.package
else:
package = resource.package
self.log.info('Queuing resource %s/%s', package.name, resource.id)
lib.create_archiver_resource_task(resource, self.options.queue)
time.sleep(0.05) # to try to avoid Redis getting overloaded
......@@ -386,10 +390,16 @@ class Archiver(CkanCommand):
# check the package isn't deleted
# Need to refresh the resource's session
resource = model.Session.query(model.Resource).get(resource.id)
if resource.resource_group and resource.resource_group.package:
if resource.resource_group.package.state == model.State.DELETED:
print 'Package is deleted'
continue
if p.toolkit.check_ckan_version(max_version='2.2.99'):
package = None
if resource.resource_group:
package = resource.resource_group.package
else:
package = resource.package
if package and package.state == model.State.DELETED:
print 'Package is deleted'
continue
if url_base != site_url_base:
print 'ERROR Base URL is incorrect: %r != %r' % (url_base, site_url_base)
......
import os
import logging
import ckan.plugins as p
from ckan import model
from ckan.model.types import make_uuid
......@@ -10,7 +11,7 @@ log = logging.getLogger(__name__)
def create_archiver_resource_task(resource, queue):
from pylons import config
if hasattr(model, 'ResourceGroup'):
if p.toolkit.check_ckan_version(max_version='2.2.99'):
# earlier CKANs had ResourceGroup
package = resource.resource_group.package
else:
......
......@@ -6,6 +6,8 @@ from sqlalchemy import types
from sqlalchemy.ext.declarative import declarative_base
import ckan.model as model
import ckan.plugins as p
from ckan.lib import dictization
log = __import__('logging').getLogger(__name__)
......@@ -145,7 +147,7 @@ class Archival(Base):
# Find the package_id for the resource.
dataset = model.Session.query(model.Package)
if hasattr(model, 'ResourceGroup'):
if p.toolkit.check_ckan_version(max_version='2.2.99'):
# earlier CKANs had ResourceGroup
dataset = dataset.join(model.ResourceGroup)
dataset = dataset \
......
import copy
import ckan.model as model
from ckan.lib.helpers import OrderedDict
import ckan.plugins as p
from ckan.lib.helpers import OrderedDict
from ckanext.report import lib
def broken_links(organization, include_sub_organizations=False):
......@@ -38,7 +39,7 @@ def broken_links_index(include_sub_organizations=False):
num_resources = model.Session.query(model.Package)\
.filter_by(owner_org=org.id)\
.filter_by(state='active')
if hasattr(model, 'ResourceGroup'):
if p.toolkit.check_ckan_version(max_version='2.2.99'):
num_resources = num_resources.join(model.ResourceGroup)
num_resources = num_resources \
.join(model.Resource)\
......@@ -199,7 +200,7 @@ def broken_links_for_organization(organization, include_sub_organizations=False)
.count()
num_resources = model.Session.query(model.Resource)\
.filter_by(state='active')
if hasattr(model, 'ResourceGroup'):
if p.toolkit.check_ckan_version(max_version='2.2.99'):
num_resources = num_resources.join(model.ResourceGroup)
num_resources = num_resources \
.join(model.Package)\
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment