Skip to content

Commit

Permalink
Merge branch 'master' of github.com:okfn/ckan into 255-update-api-docs
Browse files Browse the repository at this point in the history
  • Loading branch information
Sean Hammond committed Feb 14, 2013
2 parents 755b91f + 0e9f1b9 commit 2600f57
Show file tree
Hide file tree
Showing 107 changed files with 35,729 additions and 7,059 deletions.
5 changes: 2 additions & 3 deletions ckan/controllers/group.py
Expand Up @@ -628,9 +628,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
63 changes: 62 additions & 1 deletion ckan/controllers/user.py
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
2 changes: 1 addition & 1 deletion ckan/lib/app_globals.py
Expand Up @@ -49,7 +49,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
2 changes: 2 additions & 0 deletions ckan/lib/dictization/model_dictize.py
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
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 2600f57

Please sign in to comment.