Skip to content

Commit

Permalink
Merge branch 'master' into feature-2204-related-ui
Browse files Browse the repository at this point in the history
  • Loading branch information
aron committed May 1, 2012
2 parents dcb2432 + 96e486d commit c373cf6
Show file tree
Hide file tree
Showing 24 changed files with 130 additions and 696 deletions.
5 changes: 3 additions & 2 deletions ckan/config/middleware.py
Expand Up @@ -134,8 +134,9 @@ def make_app(global_conf, full_stack=True, static_files=True, **app_conf):
if asbool(config.get('ckan.page_cache_enabled')):
app = PageCacheMiddleware(app, config)

# Tracking add config option
app = TrackingMiddleware(app, config)
# Tracking
if asbool(config.get('ckan.tracking_enabled', 'false')):
app = TrackingMiddleware(app, config)
return app

class I18nMiddleware(object):
Expand Down
1 change: 0 additions & 1 deletion ckan/config/routing.py
Expand Up @@ -153,7 +153,6 @@ def make_map():
##map.connect('/package/edit/{id}', controller='package_formalchemy', action='edit')

with SubMapper(map, controller='related') as m:
m.connect('related_edit', '/related/{id}/edit', action='edit')
m.connect('related_list', '/dataset/{id}/related', action='list')
m.connect('related_read', '/dataset/{id}/related/{related_id}', action='read')

Expand Down
3 changes: 2 additions & 1 deletion ckan/controllers/group.py
Expand Up @@ -72,7 +72,8 @@ def index(self):
group_type = self._guess_group_type()

context = {'model': model, 'session': model.Session,
'user': c.user or c.author, 'for_view': True}
'user': c.user or c.author, 'for_view': True,
'with_private': False}

data_dict = {'all_fields': True}

Expand Down
3 changes: 2 additions & 1 deletion ckan/controllers/home.py
Expand Up @@ -31,7 +31,7 @@ def __before__(self, action, **env):
# TODO: send an email to the admin person (#1285)
else:
raise


def index(self):
try:
Expand All @@ -43,6 +43,7 @@ def index(self):
'facet.field':g.facets,
'rows':0,
'start':0,
'fq': 'capacity:"public"'
}
query = ckan.logic.get_action('package_search')(context,data_dict)
c.package_count = query['count']
Expand Down
5 changes: 3 additions & 2 deletions ckan/lib/dictization/model_dictize.py
Expand Up @@ -15,7 +15,7 @@ def group_list_dictize(obj_list, context,
sort_key=lambda x:x['display_name'], reverse=False):

active = context.get('active', True)

with_private = context.get('include_private_packages', False)
result_list = []

for obj in obj_list:
Expand All @@ -30,7 +30,8 @@ def group_list_dictize(obj_list, context,

group_dict['display_name'] = obj.display_name

group_dict['packages'] = len(obj.active_packages().all())
group_dict['packages'] = \
len(obj.active_packages(with_private=with_private).all())

if context.get('for_view'):
for item in plugins.PluginImplementations(
Expand Down
17 changes: 14 additions & 3 deletions ckan/lib/helpers.py
Expand Up @@ -153,9 +153,18 @@ def _add_i18n_to_url(url_to_amend, **kw):
return url

def lang():
''' Reurn the language code for the current locale eg `en` '''
''' Return the language code for the current locale eg `en` '''
return request.environ.get('CKAN_LANG')

def lang_native_name(lang=None):
''' Return the langage name currently used in it's localised form
either from parameter or current environ setting'''
lang = lang or lang()
locale = get_locales_dict().get(lang)
if locale:
return locale.display_name or locale.english_name
return lang

class Message(object):
"""A message returned by ``Flash.pop_messages()``.
Expand Down Expand Up @@ -676,8 +685,8 @@ def group_link(group):
url = url_for(controller='group', action='read', id=group['name'])
return link_to(group['name'], url)

def dump_json(obj):
return json.dumps(obj)
def dump_json(obj, **kw):
return json.dumps(obj, **kw)

def auto_log_message(*args):
# auto_log_message() used to need c passing as the first arg
Expand Down Expand Up @@ -799,6 +808,7 @@ def process_names(items):
'snippet',
'convert_to_dict',
'activity_div',
'lang_native_name',
# imported into ckan.lib.helpers
'literal',
'link_to',
Expand All @@ -809,4 +819,5 @@ def process_names(items):
'mail_to',
'radio',
'submit',
'asbool',
]
6 changes: 3 additions & 3 deletions ckan/logic/action/get.py
Expand Up @@ -491,9 +491,9 @@ def resource_status_show(context, data_dict):
check_access('resource_status_show', context, data_dict)

# needs to be text query as celery tables are not in our model
q = text("""select status, date_done, traceback, task_status.*
from task_status left join celery_taskmeta
on task_status.value = celery_taskmeta.task_id and key = 'celery_task_id'
q = text("""select status, date_done, traceback, task_status.*
from task_status left join celery_taskmeta
on task_status.value = celery_taskmeta.task_id and key = 'celery_task_id'
where entity_id = :entity_id """)

result = model.Session.connection().execute(q, entity_id=id)
Expand Down
11 changes: 8 additions & 3 deletions ckan/model/group.py
Expand Up @@ -166,13 +166,18 @@ def get_children_groups(self, type='group'):
from_statement(HIERARCHY_CTE).params(id=self.id, type=type).all()
return [ { "id":idf, "name": name, "title": title } for idf,name,title in results ]

def active_packages(self, load_eager=True):
def active_packages(self, load_eager=True, with_private=False):
query = Session.query(Package).\
filter_by(state=vdm.sqlalchemy.State.ACTIVE).\
filter(group_table.c.id == self.id).\
filter(member_table.c.state == 'active').\
join(member_table, member_table.c.table_id == Package.id).\
filter(member_table.c.state == 'active')

if not with_private:
query = query.filter(member_table.c.capacity == 'public')

query = query.join(member_table, member_table.c.table_id == Package.id).\
join(group_table, group_table.c.id == member_table.c.group_id)

return query

@classmethod
Expand Down
20 changes: 14 additions & 6 deletions ckan/plugins/core.py
Expand Up @@ -6,11 +6,10 @@
from inspect import isclass
from itertools import chain
from pkg_resources import iter_entry_points
from pyutilib.component.core import PluginGlobals, ExtensionPoint as PluginImplementations, implements
from pyutilib.component.core import PluginGlobals, implements
from pyutilib.component.core import ExtensionPoint as PluginImplementations
from pyutilib.component.core import SingletonPlugin as _pca_SingletonPlugin
from pyutilib.component.core import Plugin as _pca_Plugin
from pyutilib.component.core import PluginEnvironment
from sqlalchemy.orm.interfaces import MapperExtension

from ckan.plugins.interfaces import IPluginObserver

Expand All @@ -23,18 +22,20 @@

log = logging.getLogger(__name__)

# Entry point group.
# Entry point group.
PLUGINS_ENTRY_POINT_GROUP = "ckan.plugins"

# Entry point group for system plugins (those that are part of core ckan and do
# not need to be explicitly enabled by the user)
SYSTEM_PLUGINS_ENTRY_POINT_GROUP = "ckan.system_plugins"


class PluginNotFoundException(Exception):
"""
Raised when a requested plugin cannot be found.
"""


class Plugin(_pca_Plugin):
"""
Base class for plugins which require multiple instances.
Expand All @@ -43,6 +44,7 @@ class Plugin(_pca_Plugin):
probably use SingletonPlugin.
"""


class SingletonPlugin(_pca_SingletonPlugin):
"""
Base class for plugins which are singletons (ie most of them)
Expand All @@ -52,6 +54,7 @@ class SingletonPlugin(_pca_SingletonPlugin):
same singleton instance.
"""


def _get_service(plugin):
"""
Return a service (ie an instance of a plugin class).
Expand Down Expand Up @@ -100,13 +103,15 @@ def load_all(config):
for plugin in plugins:
load(plugin)


def reset():
"""
Clear and reload all configured plugins
"""
from pylons import config
load_all(config)


def load(plugin):
"""
Load a single plugin, given a plugin name, class or instance
Expand All @@ -120,6 +125,7 @@ def load(plugin):
observer_plugin.after_load(service)
return service


def unload_all():
"""
Unload (deactivate) all loaded plugins
Expand All @@ -128,6 +134,7 @@ def unload_all():
for service in env.services.copy():
unload(service)


def unload(plugin):
"""
Unload a single plugin, given a plugin name, class or instance
Expand All @@ -144,6 +151,7 @@ def unload(plugin):

return service


def find_user_plugins(config):
"""
Return all plugins specified by the user in the 'ckan.plugins' config
Expand All @@ -159,15 +167,15 @@ def find_user_plugins(config):
plugins.extend(ep.load() for ep in entry_points)
return plugins


def find_system_plugins():
"""
Return all plugins in the ckan.system_plugins entry point group.
These are essential for operation and therefore cannot be enabled/disabled
through the configuration file.
"""
return (
ep.load()
for ep in iter_entry_points(group=SYSTEM_PLUGINS_ENTRY_POINT_GROUP)
)

0 comments on commit c373cf6

Please sign in to comment.