Skip to content

Commit

Permalink
Merge branch 'master' of github.com:okfn/ckan
Browse files Browse the repository at this point in the history
  • Loading branch information
Sean Hammond committed Jun 29, 2012
2 parents 47f2aa5 + a719c13 commit db21610
Show file tree
Hide file tree
Showing 17 changed files with 1,828 additions and 93 deletions.
2 changes: 2 additions & 0 deletions ckan/config/solr/CHANGELOG.txt
Expand Up @@ -8,6 +8,8 @@ v1.4 - (ckan>=1.7)
* Add title_string so you can sort alphabetically on title.
* Fields related to analytics, access and view counts.
* Add data_dict field for the whole package_dict.
* Add vocab_* dynamic field so it is possible to facet by vocabulary tags
* Add copyField for text with source vocab_*

v1.3 - (ckan>=1.5.1)
--------------------
Expand Down
2 changes: 2 additions & 0 deletions ckan/config/solr/schema-1.4.xml
Expand Up @@ -153,6 +153,7 @@
<field name="data_dict" type="string" indexed="false" stored="true" />

<dynamicField name="extras_*" type="text" indexed="true" stored="true" multiValued="false"/>
<dynamicField name="vocab_*" type="string" indexed="true" stored="true" multiValued="true"/>
<dynamicField name="*" type="string" indexed="true" stored="false"/>
</fields>

Expand All @@ -165,6 +166,7 @@
<copyField source="download_url" dest="urls"/>
<copyField source="res_url" dest="urls"/>
<copyField source="extras_*" dest="text"/>
<copyField source="vocab_*" dest="text"/>
<copyField source="urls" dest="text"/>
<copyField source="name" dest="text"/>
<copyField source="title" dest="text"/>
Expand Down
5 changes: 2 additions & 3 deletions ckan/controllers/package.py
Expand Up @@ -594,8 +594,7 @@ def _save_new(self, context, package_type=None):
except DataError:
abort(400, _(u'Integrity Error'))
except SearchIndexError, e:
abort(500, _(u'Unable to add package to search index.') +
repr(e.args))
abort(500, _(u'Unable to add package to search index.'))
except ValidationError, e:
errors = e.error_dict
error_summary = e.error_summary
Expand Down Expand Up @@ -627,7 +626,7 @@ def _save_edit(self, name_or_id, context):
except DataError:
abort(400, _(u'Integrity Error'))
except SearchIndexError, e:
abort(500, _(u'Unable to update search index.') + repr(e.args))
abort(500, _(u'Unable to update search index.'))
except ValidationError, e:
errors = e.error_dict
error_summary = e.error_summary
Expand Down
26 changes: 21 additions & 5 deletions ckan/lib/search/index.py
@@ -1,7 +1,6 @@
import socket
import string
import logging
import itertools
import collections
import json

Expand All @@ -14,6 +13,7 @@
import ckan.model as model
from ckan.plugins import (PluginImplementations,
IPackageController)
import ckan.logic as logic

log = logging.getLogger(__name__)

Expand Down Expand Up @@ -122,10 +122,27 @@ def index_package(self, pkg_dict):
pkg_dict[key] = value
pkg_dict.pop('extras', None)

#Add tags and groups
# add tags, removing vocab tags from 'tags' list and adding them as
# vocab_<tag name> so that they can be used in facets
non_vocab_tag_names = []
tags = pkg_dict.pop('tags', [])
pkg_dict['tags'] = [tag['name'] for tag in tags]

context = {'model': model}

for tag in tags:
if tag.get('vocabulary_id'):
data = {'id': tag['vocabulary_id']}
vocab = logic.get_action('vocabulary_show')(context, data)
key = u'vocab_%s' % vocab['name']
if key in pkg_dict:
pkg_dict[key].append(tag['name'])
else:
pkg_dict[key] = [tag['name']]
else:
non_vocab_tag_names.append(tag['name'])

pkg_dict['tags'] = non_vocab_tag_names

# add groups
groups = pkg_dict.pop('groups', [])

# Capacity is different to the default only if using organizations
Expand Down Expand Up @@ -197,7 +214,6 @@ def index_package(self, pkg_dict):
import hashlib
pkg_dict['index_id'] = hashlib.md5('%s%s' % (pkg_dict['id'],config.get('ckan.site_id'))).hexdigest()


for item in PluginImplementations(IPackageController):
pkg_dict = item.before_index(pkg_dict)

Expand Down
44 changes: 42 additions & 2 deletions ckan/logic/action/create.py
Expand Up @@ -534,7 +534,8 @@ def group_create(context, data_dict):
'defer_commit':True,
'session': session
}
activity_create(activity_create_context, activity_dict, ignore_auth=True)
logic.get_action('activity_create')(activity_create_context,
activity_dict, ignore_auth=True)

if not context.get('defer_commit'):
model.repo.commit()
Expand Down Expand Up @@ -648,7 +649,8 @@ def user_create(context, data_dict):
'object_id': user.id,
'activity_type': 'new user',
}
activity_create(activity_create_context, activity_dict, ignore_auth=True)
logic.get_action('activity_create')(activity_create_context,
activity_dict, ignore_auth=True)

if not context.get('defer_commit'):
model.repo.commit()
Expand Down Expand Up @@ -842,6 +844,7 @@ def follow_user(context, data_dict):
raise logic.NotAuthorized

model = context['model']
session = context['session']

userobj = model.User.get(context['user'])
if not userobj:
Expand Down Expand Up @@ -869,6 +872,24 @@ def follow_user(context, data_dict):

follower = model_save.user_following_user_dict_save(data_dict, context)

activity_dict = {
'user_id': userobj.id,
'object_id': data_dict['id'],
'activity_type': 'follow user',
}
activity_dict['data'] = {
'user': ckan.lib.dictization.table_dictize(
model.User.get(data_dict['id']), context),
}
activity_create_context = {
'model': model,
'user': userobj,
'defer_commit':True,
'session': session
}
logic.get_action('activity_create')(activity_create_context,
activity_dict, ignore_auth=True)

if not context.get('defer_commit'):
model.repo.commit()

Expand All @@ -895,6 +916,7 @@ def follow_dataset(context, data_dict):
raise logic.NotAuthorized

model = context['model']
session = context['session']

userobj = model.User.get(context['user'])
if not userobj:
Expand All @@ -918,6 +940,24 @@ def follow_dataset(context, data_dict):

follower = model_save.user_following_dataset_dict_save(data_dict, context)

activity_dict = {
'user_id': userobj.id,
'object_id': data_dict['id'],
'activity_type': 'follow dataset',
}
activity_dict['data'] = {
'dataset': ckan.lib.dictization.table_dictize(
model.Package.get(data_dict['id']), context),
}
activity_create_context = {
'model': model,
'user': userobj,
'defer_commit':True,
'session': session
}
logic.get_action('activity_create')(activity_create_context,
activity_dict, ignore_auth=True)

if not context.get('defer_commit'):
model.repo.commit()

Expand Down
17 changes: 14 additions & 3 deletions ckan/logic/action/get.py
Expand Up @@ -1746,6 +1746,14 @@ def _render_deleted_group_activity(context, activity):
return _render('activity_streams/deleted_group.html',
extra_vars = {'activity': activity})

def _render_follow_dataset_activity(context, activity):
return _render('activity_streams/follow_dataset.html',
extra_vars = {'activity': activity})

def _render_follow_user_activity(context, activity):
return _render('activity_streams/follow_user.html',
extra_vars = {'activity': activity})

# Global dictionary mapping activity types to functions that render activity
# dicts to HTML snippets for including in HTML pages.
activity_renderers = {
Expand All @@ -1757,6 +1765,8 @@ def _render_deleted_group_activity(context, activity):
'new group' : _render_new_group_activity,
'changed group' : _render_changed_group_activity,
'deleted group' : _render_deleted_group_activity,
'follow dataset': _render_follow_dataset_activity,
'follow user': _render_follow_user_activity,
}

def _activity_list_to_html(context, activity_stream):
Expand Down Expand Up @@ -2057,15 +2067,16 @@ def dashboard_activity_list(context, data_dict):
user_id = _get_or_bust(data_dict, 'id')

activity_query = model.Session.query(model.Activity)
user_query = activity_query;
user_followees_query = activity_query.join(model.UserFollowingUser, model.UserFollowingUser.object_id == model.Activity.user_id)
dataset_followees_query = activity_query.join(model.UserFollowingDataset, model.UserFollowingDataset.object_id == model.Activity.object_id)

user_query = user_query.filter(model.Activity.user_id==user_id)
from_user_query = activity_query.filter(model.Activity.user_id==user_id)
about_user_query = activity_query.filter(model.Activity.object_id==user_id)
user_followees_query = user_followees_query.filter(model.UserFollowingUser.follower_id==user_id)
dataset_followees_query = dataset_followees_query.filter(model.UserFollowingDataset.follower_id==user_id)

query = user_query.union(user_followees_query).union(dataset_followees_query)
query = from_user_query.union(about_user_query).union(
user_followees_query).union(dataset_followees_query)
query = query.order_by(_desc(model.Activity.timestamp))
query = query.limit(15)
activity_objects = query.all()
Expand Down
2 changes: 2 additions & 0 deletions ckan/logic/validators.py
Expand Up @@ -152,8 +152,10 @@ def activity_type_exists(activity_type):
'new package' : package_id_exists,
'changed package' : package_id_exists,
'deleted package' : package_id_exists,
'follow dataset' : package_id_exists,
'new user' : user_id_exists,
'changed user' : user_id_exists,
'follow user' : user_id_exists,
'new group' : group_id_exists,
'changed group' : group_id_exists,
'deleted group' : group_id_exists,
Expand Down
6 changes: 3 additions & 3 deletions ckan/public/scripts/application.js
Expand Up @@ -1443,7 +1443,7 @@ CKAN.Utils = function($, my) {
return;
}
var data = JSON.stringify({
id: object_id,
id: object_id
});
var nextState = 'unfollow';
var nextString = CKAN.Strings.unfollow;
Expand All @@ -1457,7 +1457,7 @@ CKAN.Utils = function($, my) {
return;
}
var data = JSON.stringify({
id: object_id,
id: object_id
});
var nextState = 'follow';
var nextString = CKAN.Strings.follow;
Expand All @@ -1476,7 +1476,7 @@ CKAN.Utils = function($, my) {
success: function(data) {
button.setAttribute('data-state', nextState);
button.innerHTML = nextString;
},
}
});
};

Expand Down

0 comments on commit db21610

Please sign in to comment.