Skip to content

Commit

Permalink
[2211] Added groups to schema so that it gets saved
Browse files Browse the repository at this point in the history
  • Loading branch information
rossjones committed Mar 6, 2012
1 parent 3c7c875 commit 1627d6c
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 5 deletions.
11 changes: 8 additions & 3 deletions ckanext/publisher_form/forms.py
Expand Up @@ -187,24 +187,29 @@ def setup_template_variables(self, context, data_dict=None):
then be used within the form
"""
c.licences = [('', '')] + model.Package.get_license_options()
c.publishers = [('Example publisher', 'Example publisher 2')]
c.is_sysadmin = Authorizer().is_sysadmin(c.user)
c.resource_columns = model.Resource.get_columns()
c.groups_available = c.userobj.get_groups('publisher') if c.userobj else []


## This is messy as auths take domain object not data_dict
pkg = context.get('package') or c.pkg
if pkg:
c.auth_for_change_state = Authorizer().am_authorized(
c, model.Action.CHANGE_STATE, pkg)
gps = pkg.get_groups('publisher')
c.parent = gps[0] if gps else None

def form_to_db_schema(self):
"""
Returns the schema for mapping package data from a form to a format
suitable for the database.
"""
return package_form_schema()
schema = package_form_schema()
schema['groups'] = {
'name': [not_empty, val.group_id_or_name_exists, unicode],
'id': [ignore_missing, unicode],
}
return schema

def db_to_form_schema(data):
"""
Expand Down
4 changes: 2 additions & 2 deletions ckanext/publisher_form/templates/dataset_form.html
Expand Up @@ -54,10 +54,10 @@ <h2>Errors in form</h2>
</dt>

<dd class="parent-field">
<select id="parent" name="parent" class="chzn-select" data-placeholder="Please choose a publisher">
<select id="groups__0__name" name="groups__0__name" class="chzn-select" data-placeholder="Please choose a publisher">
<option value=""></option>
<py:for each="pg in c.groups_available">
<option py:attrs="{'selected': 'selected' if c.parent and pg.id == c.parent.id else None}" value="${pg.id}">${pg.title}</option>
<option py:attrs="{'selected': 'selected' if c.parent and pg.name == c.parent.name else None}" value="${pg.name}">${pg.title}</option>
</py:for>
</select>
</dd>
Expand Down

0 comments on commit 1627d6c

Please sign in to comment.