Skip to content

Commit

Permalink
[1669, xl] Publisher profile changes, see full commit message.
Browse files Browse the repository at this point in the history
* Added the chosen library from http://harvesthq.github.com/chosen/ to provide useful selects and multi-selects. Was/will be used for choosing the parent groups of the publisher.

* Added internal plugin/extension for the basic publisher form.  Uses IGroupForm interface to provide a publisher group which a form for creating/editing publishers which supports:

	1. Adding users with a capacity

	2. Adding datasets

* Updated setup.py to include the publisher form plugin

* Removed IGroupForm route checking (check existence of url before setting) as it caused problems with this version of Routes.

* Fixed redirect to /{{type}}/name instead of /group/name

* Updated users key in group schema to allow it to specify capacity

* Fixed the group model filtering within get_groups to not cache if capacity is used as a filter

* Implemented an autocomplete call in application.js for users within a publisher form (behaves differently from the current user autocomplete)

* Fixed publisher_form template to ensure object__num__field naming was consistent for users.

* Temporarily removed publisher parent for the simple case.
  • Loading branch information
rossjones committed Jan 26, 2012
1 parent 60b06f3 commit aed0668
Show file tree
Hide file tree
Showing 17 changed files with 1,625 additions and 24 deletions.
2 changes: 1 addition & 1 deletion ckan/config/routing.py
Original file line number Diff line number Diff line change
Expand Up @@ -244,9 +244,9 @@ def make_map():
)
map.connect('group_read', '/group/{id}', controller='group', action='read')


register_package_behaviour(map)
register_group_behaviour(map)


# authz group
map.redirect("/authorizationgroups", "/authorizationgroup")
Expand Down
17 changes: 6 additions & 11 deletions ckan/controllers/group.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,13 +50,9 @@ def register_pluggable_behaviour(map):
# Our version of routes doesn't allow the environ to be passed into the match call
# and so we have to set it on the map instead. This looks like a threading problem
# waiting to happen but it is executed sequentially from instead the routing setup
e = map.environ
map.environ = {'REQUEST_METHOD': 'GET'}
match = map.match('/%s/new' % (group_type,))
map.environ = e
if match:
raise Exception, "Plugin %r would overwrite existing urls" % plugin


map.connect('%s_index' % (group_type,),
'/%s' % (group_type,), controller='group', action='index')
map.connect('%s_new' % (group_type,),
'/%s/new' % (group_type,), controller='group', action='new')
map.connect('%s_read' % (group_type,),
Expand Down Expand Up @@ -303,7 +299,6 @@ def edit(self, id, data=None, errors=None, error_summary=None):
group = context.get("group")
c.group = group


try:
check_access('group_update',context)
except NotAuthorized, e:
Expand Down Expand Up @@ -363,17 +358,17 @@ def _save_new(self, context, group_type=None):
return self.new(data_dict, errors, error_summary)

def _save_edit(self, id, context):
try:
try:
data_dict = clean_dict(unflatten(
tuplize_dict(parse_params(request.params))))
context['message'] = data_dict.get('log_message', '')
data_dict['id'] = id
group = get_action('group_update')(context, data_dict)
h.redirect_to(controller='group', action='read', id=group['name'])
h.redirect_to('%s_read' % group['type'], id=group['name'])
except NotAuthorized:
abort(401, _('Unauthorized to read group %s') % id)
except NotFound, e:
abort(404, _('Package not found'))
abort(404, _('Group not found'))
except DataError:
abort(400, _(u'Integrity Error'))
except ValidationError, e:
Expand Down
3 changes: 1 addition & 2 deletions ckan/lib/dictization/model_save.py
Original file line number Diff line number Diff line change
Expand Up @@ -285,7 +285,6 @@ def package_dict_save(pkg_dict, context):
return pkg

def group_member_save(context, group_dict, member_table_name):

model = context["model"]
session = context["session"]
group = context['group']
Expand Down Expand Up @@ -336,7 +335,7 @@ def group_dict_save(group_dict, context):

group = table_dict_save(group_dict, Group, context)
context['group'] = group

print group_dict
group_member_save(context, group_dict, 'packages')
group_member_save(context, group_dict, 'users')
group_member_save(context, group_dict, 'groups')
Expand Down
1 change: 1 addition & 0 deletions ckan/logic/action/create.py
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,7 @@ def group_create(context, data_dict):

group = group_dict_save(data, context)

# TODO: Refactor to use new member for admin
if user:
admins = [model.User.by_name(user.decode('utf8'))]
else:
Expand Down
5 changes: 5 additions & 0 deletions ckan/logic/schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,11 @@ def group_form_schema():
"name": [not_empty, unicode],
"__extras": [ignore]
}
schema['users'] = {
"name": [not_empty, unicode],
"capacity": [ignore_missing],
"__extras": [ignore]
}
return schema


Expand Down
7 changes: 5 additions & 2 deletions ckan/model/group.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
from package import *
from types import make_uuid
import vdm.sqlalchemy
from ckan.model import extension
from ckan.model import extension, User
from sqlalchemy.ext.associationproxy import association_proxy

__all__ = ['group_table', 'Group', 'package_revision_table',
Expand Down Expand Up @@ -123,11 +123,14 @@ def search_by_name(cls, text_query):

def as_dict(self, ref_package_by='name'):
_dict = DomainObject.as_dict(self)
_dict['packages'] = [getattr(package, ref_package_by) for package in self.packages]
_dict['packages'] = [getattr(package, ref_package_by) for package in self.packages]
_dict['extras'] = dict([(key, value) for key, value in self.extras.items()])
if ( self.type == 'publisher' ):
_dict['users'] = [getattr(user, "name") for user in self.members_of_type(User)]
return _dict

def add_package_by_name(self, package_name):
from pdb import set_trace; set_trace()
if not package_name:
return
package = Package.by_name(package_name)
Expand Down
18 changes: 11 additions & 7 deletions ckan/model/user.py
Original file line number Diff line number Diff line change
Expand Up @@ -150,19 +150,23 @@ def is_in_group(self, group):

def get_groups(self, group_type=None, capacity=None):
import ckan.model as model
if '_groups' not in self.__dict__:
self._groups = model.Session.query(model.Group).\
join(model.Member, model.Member.group_id == model.Group.id and\
model.Member.table_name == 'user' ).\

q = model.Session.query(model.Group)\
.join(model.Member, model.Member.group_id == model.Group.id and \
model.Member.table_name == 'user' ).\
join(model.User, model.User.id == model.Member.table_id).\
filter(model.Member.state == 'active').\
filter(model.Member.table_id == self.id).all()
filter(model.Member.table_id == self.id)
if capacity:
q = q.filter( model.Member.capacity == capacity )
return q.all()

if '_groups' not in self.__dict__:
self._groups = q.all()

groups = self._groups
if group_type:
groups = [g for g in groups if g.type == group_type]
if capacity:
groups = [g for g in groups if g.capacity == capacity]
return groups


Expand Down

0 comments on commit aed0668

Please sign in to comment.