Skip to content

Commit

Permalink
Merge branch 'master' of github.com:okfn/ckan into 349-old-auth-cleanups
Browse files Browse the repository at this point in the history
  • Loading branch information
Sean Hammond committed Mar 6, 2013
2 parents 2ad056d + b8f1951 commit 8ac24a1
Show file tree
Hide file tree
Showing 151 changed files with 811 additions and 1,420 deletions.
18 changes: 13 additions & 5 deletions ckan/config/routing.py
Expand Up @@ -284,12 +284,15 @@ def make_map():
'follow',
'unfollow',
'admins',
'about',
'activity',
]))
)
m.connect('group_activity', '/group/activity/{id}/{offset}', action='activity'),
m.connect('group_read', '/group/{id}', action='read')
m.connect('group_about', '/group/about/{id}', action='about',
ckan_icon='info-sign'),
m.connect('group_activity', '/group/activity/{id}/{offset}',
action='activity', ckan_icon='time'),
m.connect('group_read', '/group/{id}', action='read',
ckan_icon='sitemap')

# organizations these basically end up being the same as groups
with SubMapper(map, controller='organization') as m:
Expand All @@ -305,11 +308,16 @@ def make_map():
'member_new',
'member_delete',
'history',
'bulk_process',
'about'
'bulk_process'
]))
)
m.connect('organization_activity', '/organization/activity/{id}',
action='activity', ckan_icon='time')
m.connect('organization_read', '/organization/{id}', action='read')
m.connect('organization_about', '/organization/about/{id}',
action='about', ckan_icon='info-sign')
m.connect('organization_read', '/organization/{id}', action='read',
ckan_icon='sitemap')
register_package_plugins(map)
register_group_plugins(map)

Expand Down
7 changes: 5 additions & 2 deletions ckan/controllers/api.py
Expand Up @@ -832,8 +832,11 @@ def make_unicode(entity):
raise ValueError(msg)
cls.log.debug('Retrieved request body: %r' % request.body)
if not request_data:
msg = "No request body data"
raise ValueError(msg)
if not try_url_params:
msg = "No request body data"
raise ValueError(msg)
else:
request_data = {}
if request_data:
try:
request_data = h.json.loads(request_data, encoding='utf8')
Expand Down
45 changes: 39 additions & 6 deletions ckan/controllers/group.py
Expand Up @@ -19,6 +19,12 @@
import ckan.new_authz

from ckan.lib.plugins import lookup_group_plugin
import ckan.plugins as plugins

try:
from collections import OrderedDict # 2.7
except ImportError:
from sqlalchemy.util import OrderedDict

log = logging.getLogger(__name__)

Expand Down Expand Up @@ -62,6 +68,9 @@ def _history_template(self, group_type):
def _edit_template(self, group_type):
return lookup_group_plugin(group_type).edit_template()

def _activity_template(self, group_type):
return lookup_group_plugin(group_type).activity_template()

def _admins_template(self, group_type):
return lookup_group_plugin(group_type).admins_template()

Expand Down Expand Up @@ -268,10 +277,37 @@ def pager_url(q=None, page=None):
fq = ''
context['ignore_capacity_check'] = True

facets = OrderedDict()

default_facet_titles = {'groups': _('Groups'),
'tags': _('Tags'),
'res_format': _('Formats'),
'license': _('Licence'), }

for facet in g.facets:
if facet in default_facet_titles:
facets[facet] = default_facet_titles[facet]
else:
facets[facet] = facet

# Facet titles
for plugin in plugins.PluginImplementations(plugins.IFacets):
if self.group_type == 'organization':
facets = plugin.organization_facets(
facets, self.group_type, None)
else:
facets = plugin.group_facets(
facets, self.group_type, None)

if 'capacity' in facets and (self.group_type != 'organization' or not user_member_of_orgs):
del facets['capacity']

c.facet_titles = facets

data_dict = {
'q': q,
'fq': fq,
'facet.field': g.facets,
'facet.field': facets.keys(),
'rows': limit,
'sort': sort_by,
'start': (page - 1) * limit,
Expand All @@ -294,10 +330,6 @@ def pager_url(q=None, page=None):
'Use `c.search_facets` instead.')

c.search_facets = query['search_facets']
c.facet_titles = {'groups': _('Groups'),
'tags': _('Tags'),
'res_format': _('Formats'),
'license': _('Licence'), }
c.search_facets_limits = {}
for facet in c.facets.keys():
limit = int(request.params.get('_%s_limit' % facet, 10))
Expand Down Expand Up @@ -722,7 +754,8 @@ def activity(self, id, offset=0):
c.group_activity_stream = get_action('group_activity_list_html')(
context, {'id': c.group_dict['id'], 'offset': offset})

return render('group/activity_stream.html')
#return render('group/activity_stream.html')
return render(self._activity_template(c.group_dict['type']))

def follow(self, id):
'''Start following this group.'''
Expand Down
3 changes: 3 additions & 0 deletions ckan/controllers/organization.py
Expand Up @@ -52,5 +52,8 @@ def _history_template(self, group_type):
def _edit_template(self, group_type):
return 'organization/edit.html'

def _activity_template(self, group_type):
return 'organization/activity_stream.html'

def _guess_group_type(self, expecting_name=False):
return 'organization'
39 changes: 30 additions & 9 deletions ckan/controllers/package.py
Expand Up @@ -37,6 +37,12 @@
from ckan.lib.plugins import lookup_package_plugin
import ckan.plugins as p


try:
from collections import OrderedDict # 2.7
except ImportError:
from sqlalchemy.util import OrderedDict

log = logging.getLogger(__name__)


Expand Down Expand Up @@ -227,10 +233,29 @@ def pager_url(q=None, page=None):
if not asbool(config.get('ckan.search.show_all_types', 'False')):
fq += ' +dataset_type:dataset'

facets = OrderedDict()

default_facet_titles = {'groups': _('Groups'),
'tags': _('Tags'),
'res_format': _('Formats'),
'license': _('Licence'), }

for facet in g.facets:
if facet in default_facet_titles:
facets[facet] = default_facet_titles[facet]
else:
facets[facet] = facet

# Facet titles
for plugin in plugins.PluginImplementations(plugins.IFacets):
facets = plugin.dataset_facets(facets, package_type)

c.facet_titles = facets

data_dict = {
'q': q,
'fq': fq.strip(),
'facet.field': g.facets,
'facet.field': facets.keys(),
'rows': limit,
'start': (page - 1) * limit,
'sort': sort_by,
Expand Down Expand Up @@ -260,14 +285,6 @@ def pager_url(q=None, page=None):
limit = int(request.params.get('_%s_limit' % facet, 10))
c.search_facets_limits[facet] = limit

# Facet titles
c.facet_titles = {'groups': _('Groups'),
'tags': _('Tags'),
'res_format': _('Formats'),
'license': _('Licence'), }
for plugin in plugins.PluginImplementations(plugins.IPackageController):
c.facet_titles = plugin.update_facet_titles(c.facet_titles)


maintain.deprecate_context_item(
'facets',
Expand Down Expand Up @@ -1384,6 +1401,10 @@ def resource_datapreview(self, id, resource_id):
on_same_domain = datapreview.resource_is_on_same_domain(data_dict)
data_dict['resource']['on_same_domain'] = on_same_domain

# FIXME this wants to not use plugins as it is an imported name
# and we already import it an p should really only be in
# extensu=ions in my opinion also just make it look nice and be
# readable grrrrrr
plugins = p.PluginImplementations(p.IResourcePreview)
plugins_that_can_preview = [plugin for plugin in plugins
if plugin.can_preview(data_dict)]
Expand Down
4 changes: 4 additions & 0 deletions ckan/lib/app_globals.py
Expand Up @@ -177,6 +177,10 @@ def _init(self):

self.ckan_version = ckan.__version__
self.ckan_base_version = re.sub('[^0-9\.]', '', self.ckan_version)
if self.ckan_base_version == self.ckan_version:
self.ckan_doc_version = 'ckan-{0}'.format(self.ckan_version)
else:
self.ckan_doc_version = 'latest'

# process the config_details to set globals
for name, options in config_details.items():
Expand Down
34 changes: 31 additions & 3 deletions ckan/lib/cli.py
Expand Up @@ -1744,35 +1744,63 @@ class MinifyCommand(CkanCommand):
Usage:
paster minify [FILE|DIRECTORY] ...
paster minify [--clean] <path>
for example:
paster minify ckan/public/base
paster minify ckan/public/base/css/*.css
paster minify ckan/public/base/css/red.css
if the --clean option is provided any minified files will be removed.
'''
summary = __doc__.split('\n')[0]
usage = __doc__
min_args = 1

exclude_dirs = ['vendor']

def __init__(self, name):

super(MinifyCommand, self).__init__(name)

self.parser.add_option('--clean', dest='clean',
action='store_true', default=False, help='remove any minified files in the path')

def command(self):
clean = getattr(self.options, 'clean', False)
self._load_config()
for base_path in self.args:
if os.path.isfile(base_path):
self.minify_file(base_path)
if clean:
self.clear_minifyed(base_path)
else:
self.minify_file(base_path)
elif os.path.isdir(base_path):
for root, dirs, files in os.walk(base_path):
dirs[:] = [d for d in dirs if not d in self.exclude_dirs]
for filename in files:
path = os.path.join(root, filename)
self.minify_file(path)
if clean:
self.clear_minifyed(path)
else:
self.minify_file(path)
else:
# Path is neither a file or a dir?
continue

def clear_minifyed(self, path):
path_only, extension = os.path.splitext(path)

if extension not in ('.css', '.js'):
# This is not a js or css file.
return

if path_only.endswith('.min'):
print 'removing %s' % path
os.remove(path)

def minify_file(self, path):
'''Create the minified version of the given file.
Expand Down
12 changes: 8 additions & 4 deletions ckan/lib/datapreview.py
Expand Up @@ -22,10 +22,14 @@ def compare_domains(urls):
for url in urls:
# all urls are interpreted as absolute urls,
# except for urls that start with a /
if not urlparse.urlparse(url).scheme and not url.startswith('/'):
url = '//' + url
parsed = urlparse.urlparse(url.lower(), 'http')
domain = (parsed.scheme, parsed.hostname, parsed.port)
try:
if not urlparse.urlparse(url).scheme and not url.startswith('/'):
url = '//' + url
parsed = urlparse.urlparse(url.lower(), 'http')
domain = (parsed.scheme, parsed.hostname, parsed.port)
except ValueError:
# URL is so messed up that even urlparse can't stand it
return False

if not first_domain:
first_domain = domain
Expand Down
36 changes: 27 additions & 9 deletions ckan/lib/helpers.py
Expand Up @@ -516,8 +516,9 @@ def unselected_facet_items(facet, limit=10):
return get_facet_items_dict(facet, limit=limit, exclude_active=True)


@maintain.deprecated('h.get_facet_title is deprecated in 2.0 and will be removed.')
def get_facet_title(name):

'''Deprecated in ckan 2.0 '''
# if this is set in the config use this
config_title = config.get('search.facets.%s.title' % name)
if config_title:
Expand Down Expand Up @@ -547,15 +548,28 @@ def _search_url(params):
return _url_with_params(url, params)


def sorted_extras(list_):
''' Used for outputting package extras '''
def sorted_extras(package_extras, auto_clean=False, subs=None):
''' Used for outputting package extras
:param package_extras: the package extras
:type package_extras: dict
:param auto_clean: If true capitalize and replace -_ with spaces
:type auto_clean: bool
:param subs: substitutes to use instead of given keys
:type subs: dict {'key': 'replacement'}
'''

output = []
for extra in sorted(list_, key=lambda x: x['key']):
for extra in sorted(package_extras, key=lambda x: x['key']):
if extra.get('state') == 'deleted':
continue
k, v = extra['key'], extra['value']
if k in g.package_hide_extras:
continue
if subs and k in subs:
k = subs[k]
elif auto_clean:
k = k.replace('_', ' ').replace('-', ' ').title()
if isinstance(v, (list, tuple)):
v = ", ".join(map(unicode, v))
output.append((k, v))
Expand Down Expand Up @@ -1390,10 +1404,9 @@ def resource_preview(resource, pkg_id):
data_dict = {'resource': resource, 'package': c.package}

if not resource['url']:
log.info('No url for resource {0} defined.'.format(resource['id']))
return snippet("dataviewer/snippets/no_preview.html",
resource_type=format_lower,
reason='No valid resource url has been defined.')
reason=_(u'The resource url is not specified.'))
direct_embed = config.get('ckan.preview.direct', '').split()
if not direct_embed:
direct_embed = datapreview.DEFAULT_DIRECT_EMBED
Expand All @@ -1410,10 +1423,15 @@ def resource_preview(resource, pkg_id):
elif format_lower in loadable_in_iframe:
url = resource['url']
else:
log.info(
'No preview handler for resource type {0}'.format(format_lower)
)
reason = None
if format_lower:
log.info(
_(u'No preview handler for resource of type {0}'.format(format_lower))
)
else:
reason = _(u'The resource format is not specified.')
return snippet("dataviewer/snippets/no_preview.html",
reason=reason,
resource_type=format_lower)

return snippet("dataviewer/snippets/data_preview.html",
Expand Down
7 changes: 7 additions & 0 deletions ckan/lib/plugins.py
Expand Up @@ -370,6 +370,13 @@ def edit_template(self):
"""
return 'group/edit.html'

def activity_template(self):
"""
Returns a string representing the location of the template to be
rendered for the activity stream page
"""
return 'group/activity_stream.html'

def admins_template(self):
"""
Returns a string representing the location of the template to be
Expand Down

0 comments on commit 8ac24a1

Please sign in to comment.