Skip to content

Commit

Permalink
Stops users adding datasets without organizations set.
Browse files Browse the repository at this point in the history
Changes the schema in organization_dataset to make sure that the package
has an organization set, and removes the None option from the dropdown.
  • Loading branch information
rossjones committed Jun 26, 2012
1 parent 2bf11bb commit 6960a0f
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 24 deletions.
30 changes: 11 additions & 19 deletions ckanext/organizations/forms.py
Expand Up @@ -20,6 +20,15 @@

log = logging.getLogger(__name__)


def group_required(key, data, errors, context):
""" We want at least a group in the data we are provided """
has_group = ('groups', 0, 'id') in data
if not has_group:
errors[('Organizations', '')] = \
[_('Please choose an organization to add the dataset to')]


class OrganizationForm(SingletonPlugin):
"""
This plugin implements an IGroupForm for form associated with a
Expand Down Expand Up @@ -221,34 +230,17 @@ def package_form(self):
def db_to_form_schema(self):
'''This is an interface to manipulate data from the database
into a format suitable for the form (optional)'''
#schema = default_package_schema()
#schema['groups']['capacity'] = [ ignore_missing, unicode ]
#return schema

def form_to_db_schema(self):
schema = default_package_schema()
schema['groups']['capacity'] = [ ignore_missing, unicode ]
schema['groups']['capacity'] = [ignore_missing, unicode]
schema['__after'] = [group_required]
return schema

def check_data_dict(self, data_dict, schema=None):
'''Check if the return data is correct, mostly for checking out
if spammers are submitting only part of the form'''

# Resources might not exist yet (eg. Add Dataset)
surplus_keys_schema = ['__extras', '__junk', 'state', 'groups',
'extras_validation', 'save', 'return_to',
'resources', 'type']

# if not schema:
# schema = self.form_to_db_schema()
# schema_keys = schema.keys()
# keys_in_schema = set(schema_keys) - set(surplus_keys_schema)

# missing_keys = keys_in_schema - set(data_dict.keys())
# if missing_keys:
# log.info('incorrect form fields posted, missing %s' % missing_keys)
# raise DataError(data_dict)

def setup_template_variables(self, context, data_dict):
from pylons import config

Expand Down
10 changes: 5 additions & 5 deletions ckanext/organizations/templates/organization_package_form.html
Expand Up @@ -105,24 +105,24 @@ <h2>Errors in form</h2>
?>
<py:if test="c.groups_available and ((not 'name' in organization) or c.is_sysadmin or c.auth_for_change_state)">
<select id="groups__0__id" name="groups__0__id" class="chzn-select">
<option value="">(None)</option>
<py:for each="group in c.groups_available">
<option value="${group['id']}" py:attrs="{'selected':'selected'} if organization.get('id','') == group['id'] else {}">${group['title']}</option>
<!-- if ...-->
<option value="${group['id']}" py:attrs="{'selected':'selected'} if organization and organization.get('id','') == group['id'] else {}">${group['title']}</option>
</py:for>
</select>

<label for='cap_public'>
<input id='cap_public' type='radio' name='groups__0__capacity' value='public' py:attrs="{'checked':'checked'} if organization.get('capacity','') in ['public', ''] else {}"/>
<input id='cap_public' type='radio' name='groups__0__capacity' value='public' py:attrs="{'checked':'checked'} if organization and organization.get('capacity','') in ['public', ''] else {}"/>
Public</label>

<label for='cap_private'>
<input id='cap_private' type='radio' name='groups__0__capacity' value='private' py:attrs="{'checked':'checked'} if organization.get('capacity','') == 'private' else {}"/>
<input id='cap_private' type='radio' name='groups__0__capacity' value='private' py:attrs="{'checked':'checked'} if organization and organization.get('capacity','') == 'private' else {}"/>
Private</label>
</py:if>
<py:if test="not (c.is_sysadmin or c.auth_for_change_state)">
<span>${organization.get('title', '')}</span>
</py:if>
<em py:if="not c.groups_available">Cannot add any organizations.</em>
<em py:if="not c.groups_available">Cannot add to any organizations. Please join an organization</em>
</div>
</div>

Expand Down

0 comments on commit 6960a0f

Please sign in to comment.