Skip to content

Commit

Permalink
Merge branch 'master' into 278-bulk-updates
Browse files Browse the repository at this point in the history
  • Loading branch information
tobes committed Feb 15, 2013
2 parents 296bc04 + 2fce451 commit fdc0e30
Show file tree
Hide file tree
Showing 147 changed files with 36,381 additions and 4,271 deletions.
5 changes: 2 additions & 3 deletions ckan/controllers/group.py
Original file line number Diff line number Diff line change
Expand Up @@ -701,9 +701,8 @@ def activity(self, id, offset=0):

# Add the group's activity stream (already rendered to HTML) to the
# template context for the group/read.html template to retrieve later.
c.group_activity_stream = \
get_action('group_activity_list_html')(context,
{'id': c.group_dict['id'], 'offset': offset})
c.group_activity_stream = get_action('group_activity_list_html')(
context, {'id': c.group_dict['id'], 'offset': offset})

return render('group/activity_stream.html')

Expand Down
2 changes: 1 addition & 1 deletion ckan/controllers/related.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ def pager_url(q=None, page=None):
page=page,
url=pager_url,
item_count=query.count(),
items_per_page=8
items_per_page=9
)

c.filters = dict(params_nopage)
Expand Down
63 changes: 62 additions & 1 deletion ckan/controllers/user.py
Original file line number Diff line number Diff line change
Expand Up @@ -503,13 +503,74 @@ def activity(self, id, offset=0):

return render('user/activity_stream.html')

def _get_dashboard_context(self, filter_type=None, filter_id=None,
q=None):
'''Return a dict needed by the dashboard view to determine context.'''

def display_name(followee):
'''Return a display name for a user, group or dataset dict.'''
display_name = followee.get('display_name')
fullname = followee.get('fullname')
title = followee.get('title')
name = followee.get('name')
return display_name or fullname or title or name

if (filter_type and filter_id):
context = {'model': model, 'session': model.Session,
'user': c.user or c.author, 'for_view': True}
data_dict = {'id': filter_id}
followee = None

action_functions = {
'dataset': 'package_show',
'user': 'user_show',
'group': 'group_show'
}
action_function = logic.get_action(action_functions.get(filter_type))
# Is this a valid type?
if action_function is None:
raise abort(404, _('Follow item not found'))
try:
followee = action_function(context, data_dict)
except NotFound:
abort(404, _('{0} not found').format(filter_type))
except NotAuthorized:
abort(401, _('Unauthorized to read {0} {1}').format(
filter_type, id))

if followee is not None:
return {
'filter_type': filter_type,
'q': q,
'context': display_name(followee),
'selected_id': followee.get('id'),
'dict': followee,
}

return {
'filter_type': filter_type,
'q': q,
'context': _('Everything'),
'selected_id': False,
'dict': None,
}

def dashboard(self, id=None, offset=0):
context = {'model': model, 'session': model.Session,
'user': c.user or c.author, 'for_view': True}
data_dict = {'id': id, 'user_obj': c.userobj, 'offset': offset}
self._setup_template_variables(context, data_dict)

c.dashboard_activity_stream = h.dashboard_activity_stream(id, offset)
q = request.params.get('q', u'')
filter_type = request.params.get('type', u'')
filter_id = request.params.get('name', u'')

c.followee_list = get_action('followee_list')(
context, {'id': c.userobj.id, 'q': q})
c.dashboard_activity_stream_context = self._get_dashboard_context(
filter_type, filter_id, q)
c.dashboard_activity_stream = h.dashboard_activity_stream(
id, filter_type, filter_id, offset)

# Mark the user's new activities as old whenever they view their
# dashboard page.
Expand Down
16 changes: 8 additions & 8 deletions ckan/lib/activity_streams.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,29 +13,29 @@
# etc.

def get_snippet_actor(activity, detail):
return literal('''<span class="actor" data-module="popover-context" data-module-type="user" data-module-id="%s">%s</span>'''
% (activity['user_id'], h.linked_user(activity['user_id'], 0, 30))
return literal('''<span class="actor">%s</span>'''
% (h.linked_user(activity['user_id'], 0, 30))
)

def get_snippet_user(activity, detail):
return literal('''<span data-module="popover-context" data-module-type="user" data-module-id="%s">%s</span>'''
% (activity['object_id'], h.linked_user(activity['object_id'], 0, 20))
return literal('''<span>%s</span>'''
% (h.linked_user(activity['object_id'], 0, 20))
)

def get_snippet_dataset(activity, detail):
data = activity['data']
link = h.dataset_link(data.get('package') or data.get('dataset'))
return literal('''<span data-module="popover-context" data-module-type="dataset" data-module-id="%s">%s</span>'''
% (activity['object_id'], link)
return literal('''<span>%s</span>'''
% (link)
)

def get_snippet_tag(activity, detail):
return h.tag_link(detail['data']['tag'])

def get_snippet_group(activity, detail):
link = h.group_link(activity['data']['group'])
return literal('''<span data-module="popover-context" data-module-type="group" data-module-id="%s">%s</span>'''
% (activity['object_id'], link)
return literal('''<span>%s</span>'''
% (link)
)

def get_snippet_organization(activity, detail):
Expand Down
8 changes: 7 additions & 1 deletion ckan/lib/app_globals.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,12 @@
import logging
import time
from threading import Lock
import re

from paste.deploy.converters import asbool
from pylons import config

import ckan
import ckan.model as model

log = logging.getLogger(__name__)
Expand Down Expand Up @@ -49,7 +51,7 @@
'type': 'split',
'name': 'facets'},
'package_hide_extras': {'type': 'split'},
'plugins': {'type': 'split'},
'ckan.plugins': {'type': 'split'},

# bool
'openid_enabled': {'default': 'true', 'type' : 'bool'},
Expand Down Expand Up @@ -172,6 +174,10 @@ def _check_uptodate(self):
self._mutex.release()

def _init(self):

self.ckan_version = ckan.__version__
self.ckan_base_version = re.sub('[^0-9\.]', '', self.ckan_version)

# process the config_details to set globals
for name, options in config_details.items():
if 'name' in options:
Expand Down
3 changes: 3 additions & 0 deletions ckan/lib/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -1757,13 +1757,16 @@ class MinifyCommand(CkanCommand):
usage = __doc__
min_args = 1

exclude_dirs = ['vendor']

def command(self):
self._load_config()
for base_path in self.args:
if os.path.isfile(base_path):
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)
Expand Down
2 changes: 2 additions & 0 deletions ckan/lib/dictization/model_dictize.py
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,7 @@ def package_dictize(pkg, context):
q = q.where(resource_group.c.package_id == pkg.id)
result = _execute_with_revision(q, res_rev, context)
result_dict["resources"] = resource_list_dictize(result, context)
result_dict['num_resources'] = len(result_dict.get('resources', []))

#tags
tag_rev = model.package_tag_revision_table
Expand All @@ -229,6 +230,7 @@ def package_dictize(pkg, context):
).where(tag_rev.c.package_id == pkg.id)
result = _execute_with_revision(q, tag_rev, context)
result_dict["tags"] = d.obj_list_dictize(result, context, lambda x: x["name"])
result_dict['num_tags'] = len(result_dict.get('tags', []))

# Add display_names to tags. At first a tag's display_name is just the
# same as its name, but the display_name might get changed later (e.g.
Expand Down
57 changes: 35 additions & 22 deletions ckan/lib/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -1257,21 +1257,37 @@ def user_in_org_or_group(group_id):
return len(query.all()) != 0


def dashboard_activity_stream(user_id, offset=0):
def dashboard_activity_stream(user_id, filter_type=None, filter_id=None,
offset=0):
'''Return the dashboard activity stream of the given user.
:param user_id: the id of the user
:type user_id: string
:param filter_type: the type of thing to filter by
:type filter_type: string
:param filter_id: the id of item to filter by
:type filter_id: string
:returns: an activity stream as an HTML snippet
:rtype: string
'''
import ckan.logic as logic
context = {'model': model, 'session': model.Session, 'user': c.user}
return logic.get_action('dashboard_activity_list_html')(context,
{'id': user_id,
'offset': offset})

if filter_type:
action_functions = {
'dataset': 'package_activity_list_html',
'user': 'user_activity_list_html',
'group': 'group_activity_list_html'
}
action_function = logic.get_action(action_functions.get(filter_type))
return action_function(context, {'id': filter_id, 'offset': offset})
else:
return logic.get_action('dashboard_activity_list_html')(
context, {'id': user_id, 'offset': offset})


def recently_changed_packages_activity_stream():
Expand Down Expand Up @@ -1364,8 +1380,8 @@ def resource_preview(resource, pkg_id):
Returns a rendered snippet for a embedded resource preview.
Depending on the type, different previews are loaded.
This could be an img tag where the image is loaded directly or an iframe that
embeds a web page, recline or a pdf preview.
This could be an img tag where the image is loaded directly or an iframe
that embeds a web page, recline or a pdf preview.
'''

format_lower = resource['format'].lower()
Expand All @@ -1376,11 +1392,9 @@ def resource_preview(resource, pkg_id):

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.'
)
return snippet("dataviewer/snippets/no_preview.html",
resource_type=format_lower,
reason='No valid resource url has been defined.')
direct_embed = config.get('ckan.preview.direct', '').split()
if not direct_embed:
direct_embed = datapreview.DEFAULT_DIRECT_EMBED
Expand All @@ -1390,24 +1404,23 @@ def resource_preview(resource, pkg_id):

if datapreview.can_be_previewed(data_dict):
url = url_for(controller='package', action='resource_datapreview',
resource_id=resource['id'], id=pkg_id, qualified=True)
resource_id=resource['id'], id=pkg_id, qualified=True)
elif format_lower in direct_embed:
directly = True
url = resource['url']
elif format_lower in loadable_in_iframe:
url = resource['url']
else:
log.info('No preview handler for resource type {0}'.format(format_lower))
return snippet(
"dataviewer/snippets/no_preview.html",
resource_type=format_lower
)

return snippet(
"dataviewer/snippets/data_preview.html",
embed=directly,
resource_url=url
log.info(
'No preview handler for resource type {0}'.format(format_lower)
)
return snippet("dataviewer/snippets/no_preview.html",
resource_type=format_lower)

return snippet("dataviewer/snippets/data_preview.html",
embed=directly,
resource_url=url,
raw_resource_url=resource.get('url'))


def SI_number_span(number):
Expand Down

0 comments on commit fdc0e30

Please sign in to comment.