Commit 7fde1b43 authored by David Read's avatar David Read
Browse files

Merge pull request #18 from mostrovoi/master

Fixing resource_group for ckan2.3+. Using same convention in all places
parents d8729418 a6f9ea12
import os import os
import ckan.plugins as p
def load_config(config_filepath): def load_config(config_filepath):
import paste.deploy import paste.deploy
...@@ -30,7 +30,7 @@ def get_resources(state='active', publisher_ref=None, resource_id=None, ...@@ -30,7 +30,7 @@ def get_resources(state='active', publisher_ref=None, resource_id=None,
from ckan import model from ckan import model
resources = model.Session.query(model.Resource) \ resources = model.Session.query(model.Resource) \
.filter_by(state=state) .filter_by(state=state)
if hasattr(model, 'ResourceGroup'): if p.toolkit.check_ckan_version(max_version='2.2.99'):
# earlier CKANs had ResourceGroup # earlier CKANs had ResourceGroup
resources = resources.join(model.ResourceGroup) resources = resources.join(model.ResourceGroup)
resources = resources \ resources = resources \
......
...@@ -5,6 +5,7 @@ import time ...@@ -5,6 +5,7 @@ import time
import re import re
import shutil import shutil
import itertools import itertools
import ckan.plugins as p
from pylons import config from pylons import config
...@@ -178,7 +179,7 @@ class Archiver(CkanCommand): ...@@ -178,7 +179,7 @@ class Archiver(CkanCommand):
self.log.info('Queue: %s', self.options.queue) self.log.info('Queue: %s', self.options.queue)
for package in packages: for package in packages:
if hasattr(model, 'ResourceGroup'): if p.toolkit.check_ckan_version(max_version='2.2.99'):
# earlier CKANs had ResourceGroup # earlier CKANs had ResourceGroup
pkg_resources = \ pkg_resources = \
[res for res in [res for res in
...@@ -197,7 +198,10 @@ class Archiver(CkanCommand): ...@@ -197,7 +198,10 @@ class Archiver(CkanCommand):
time.sleep(0.1) # to try to avoid Redis getting overloaded time.sleep(0.1) # to try to avoid Redis getting overloaded
for resource in resources: for resource in resources:
if p.toolkit.check_ckan_version(max_version='2.2.99'):
package = resource.resource_group.package package = resource.resource_group.package
else:
package = resource.package
self.log.info('Queuing resource %s/%s', package.name, resource.id) self.log.info('Queuing resource %s/%s', package.name, resource.id)
lib.create_archiver_resource_task(resource, self.options.queue) lib.create_archiver_resource_task(resource, self.options.queue)
time.sleep(0.05) # to try to avoid Redis getting overloaded time.sleep(0.05) # to try to avoid Redis getting overloaded
...@@ -386,8 +390,14 @@ class Archiver(CkanCommand): ...@@ -386,8 +390,14 @@ class Archiver(CkanCommand):
# check the package isn't deleted # check the package isn't deleted
# Need to refresh the resource's session # Need to refresh the resource's session
resource = model.Session.query(model.Resource).get(resource.id) resource = model.Session.query(model.Resource).get(resource.id)
if resource.resource_group and resource.resource_group.package: if p.toolkit.check_ckan_version(max_version='2.2.99'):
if resource.resource_group.package.state == model.State.DELETED: 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' print 'Package is deleted'
continue continue
......
import os import os
import logging import logging
import ckan.plugins as p
from ckan import model from ckan import model
from ckan.model.types import make_uuid from ckan.model.types import make_uuid
...@@ -10,7 +11,7 @@ log = logging.getLogger(__name__) ...@@ -10,7 +11,7 @@ log = logging.getLogger(__name__)
def create_archiver_resource_task(resource, queue): def create_archiver_resource_task(resource, queue):
from pylons import config from pylons import config
if hasattr(model, 'ResourceGroup'): if p.toolkit.check_ckan_version(max_version='2.2.99'):
# earlier CKANs had ResourceGroup # earlier CKANs had ResourceGroup
package = resource.resource_group.package package = resource.resource_group.package
else: else:
......
...@@ -6,6 +6,8 @@ from sqlalchemy import types ...@@ -6,6 +6,8 @@ from sqlalchemy import types
from sqlalchemy.ext.declarative import declarative_base from sqlalchemy.ext.declarative import declarative_base
import ckan.model as model import ckan.model as model
import ckan.plugins as p
from ckan.lib import dictization from ckan.lib import dictization
log = __import__('logging').getLogger(__name__) log = __import__('logging').getLogger(__name__)
...@@ -145,7 +147,7 @@ class Archival(Base): ...@@ -145,7 +147,7 @@ class Archival(Base):
# Find the package_id for the resource. # Find the package_id for the resource.
dataset = model.Session.query(model.Package) 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 # earlier CKANs had ResourceGroup
dataset = dataset.join(model.ResourceGroup) dataset = dataset.join(model.ResourceGroup)
dataset = dataset \ dataset = dataset \
......
import copy import copy
import ckan.model as model import ckan.model as model
from ckan.lib.helpers import OrderedDict
import ckan.plugins as p import ckan.plugins as p
from ckan.lib.helpers import OrderedDict
from ckanext.report import lib from ckanext.report import lib
def broken_links(organization, include_sub_organizations=False): def broken_links(organization, include_sub_organizations=False):
...@@ -38,7 +39,7 @@ def broken_links_index(include_sub_organizations=False): ...@@ -38,7 +39,7 @@ def broken_links_index(include_sub_organizations=False):
num_resources = model.Session.query(model.Package)\ num_resources = model.Session.query(model.Package)\
.filter_by(owner_org=org.id)\ .filter_by(owner_org=org.id)\
.filter_by(state='active') .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.ResourceGroup)
num_resources = num_resources \ num_resources = num_resources \
.join(model.Resource)\ .join(model.Resource)\
...@@ -199,7 +200,7 @@ def broken_links_for_organization(organization, include_sub_organizations=False) ...@@ -199,7 +200,7 @@ def broken_links_for_organization(organization, include_sub_organizations=False)
.count() .count()
num_resources = model.Session.query(model.Resource)\ num_resources = model.Session.query(model.Resource)\
.filter_by(state='active') .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.ResourceGroup)
num_resources = num_resources \ num_resources = num_resources \
.join(model.Package)\ .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