Skip to content

Commit

Permalink
2375 move add dataset form to separate file so errors show
Browse files Browse the repository at this point in the history
  • Loading branch information
tobes committed May 29, 2012
1 parent 89b765a commit c7937b4
Show file tree
Hide file tree
Showing 2 changed files with 88 additions and 84 deletions.
85 changes: 1 addition & 84 deletions ckan/templates/package/new.html
Expand Up @@ -19,90 +19,7 @@
<section class="module">
<div class="content">
${h.snippet('package/new_stages.html', stage=1)}

<form class="dataset-form form-horizontal" method="post" py:with="errors = {}; data = {};">
<div class="alert alert-error error-explanation" py:if="False and error_summary">
<h2>Errors in form</h2>
<p>The form contains invalid entries:</p>
<ul>
<li py:for="key, error in error_summary.items()">${"%s: %s" % (key if not key=='Name' else 'URL', error)}</li>
</ul>
</div>

<div class="control-group control-large control-full" py:with="error = errors.get('title', '')">
<label class="control-label" for="field-title">Title</label>
<div class="controls">
<input id="field-title" name="title" value="${data.get('title', '')}" placeholder="${_('A descriptive title')}" />
<span class="error-block" py:if="error">${error}</span>
</div>
</div>

<div class="control-group control-full" py:with="error = errors.get('name', '')">
<label class="control-label" for="field-name">URL</label>
<div class="controls">
<input id="field-name" name="name" value="${data.get('name', '')}" placeholder="${_('my-dataset')}" />
<span class="error-block" py:if="error">${error}</span>
</div>
</div>

<div class="control-group control-full" py:with="error = errors.get('notes', '')">
<label class="control-label" for="field-notes">Description</label>
<div class="controls editor">
<textarea id="field-notes" name="notes" cols="20" rows="5" placeholder="Some useful notes about the data">${data.get('notes', '')}</textarea>
<span class="info-block">You can use <a href="http://daringfireball.net/projects/markdown/syntax">Markdown</a> editing here</span>
<span class="error-block" py:if="error">${error}</span>
</div>
</div>

<div class="control-group" py:with="error = errors.get('license_id', '')">
<label class="control-label" for="field-license">License</label>
<div class="controls">
<select id="field-license" name="license_id">
<py:for each="licence_desc, licence_id in c.licences">
<option value="${licence_id}" py:attrs="{'selected': 'selected' if data.get('license_id', '') == licence_id else None}" py:if="licence_desc">${licence_desc}</option>
</py:for>
</select>
<span class="error-block" py:if="error">${error}</span>
<span class="info-block">Don't worry if you don't know which license the data has been released under</span>
</div>
</div>

<div class="control-group" py:if="c.groups_available" py:with="groups = data.get('groups',[])">
<label for="field-groups" class="control-label">Add to Groups</label>
<div class="controls">
<select id="field-groups" name="groups__${len(groups)}__id">
<option selected="selected" value="">Select a group...</option>
<py:for each="group in c.groups_available">
<option value="${group['id']}" >${group['name']}</option>
</py:for>
</select>
</div>

<div class="control-group" py:if="len(data.get('groups', []))" py:with="groups = data.get('groups',[])">
<label for="groups__0__id" class="control-label">Member of Groups</label>
<div class="controls">
<py:for each="num, group in enumerate(groups)">
<?python
authorized_group = [group_authz for group_authz in c.groups_authz if group_authz['id'] == group['id']]
authorized_group = authorized_group[0] if authorized_group else None
?>
<div class="checkbox" py:if="'id' in group">
<label for="groups__${num}__checked">
<input type="${'checkbox' if authorized_group else 'hidden'}" name="groups__${num}__id" checked="checked" value="${group['id']}"/>
${group.get('name', authorized_group['name'] if authorized_group else '')}
</label>
<input type="hidden" name="groups__${num}__name" value="${group.get('name', authorized_group['name'] if authorized_group else '')}" />
</div>
</py:for>
</div>
</div>
</div>

<div class="form-actions">
<a class="btn" href="">Cancel</a>
<button class="btn btn-primary" type="submit" name="save">Next: Add Data</button>
</div>
</form>
${c.form}
</div>
</section>
</div>
Expand Down
87 changes: 87 additions & 0 deletions ckan/templates/package/new_package_form.html
@@ -0,0 +1,87 @@
<form
xmlns:i18n="http://genshi.edgewall.org/i18n"
xmlns:py="http://genshi.edgewall.org/"
xmlns:xi="http://www.w3.org/2001/XInclude"
class="dataset-form form-horizontal" method="post" py:with="errors = {}; data = {};">
<div class="alert alert-error error-explanation" py:if="error_summary">
<h2>Errors in form</h2>
<p>The form contains invalid entries:</p>
<ul>
<li py:for="key, error in error_summary.items()">${"%s: %s" % (key if not key=='Name' else 'URL', error)}</li>
</ul>
</div>

<div class="control-group control-large control-full" py:with="error = errors.get('title', '')">
<label class="control-label" for="field-title">Title</label>
<div class="controls">
<input id="field-title" name="title" value="${data.get('title', '')}" placeholder="${_('A descriptive title')}" />
<span class="error-block" py:if="error">${error}</span>
</div>
</div>

<div class="control-group control-full" py:with="error = errors.get('name', '')">
<label class="control-label" for="field-name">URL</label>
<div class="controls">
<input id="field-name" name="name" value="${data.get('name', '')}" placeholder="${_('my-dataset')}" />
<span class="error-block" py:if="error">${error}</span>
</div>
</div>

<div class="control-group control-full" py:with="error = errors.get('notes', '')">
<label class="control-label" for="field-notes">Description</label>
<div class="controls editor">
<textarea id="field-notes" name="notes" cols="20" rows="5" placeholder="Some useful notes about the data">${data.get('notes', '')}</textarea>
<span class="info-block">You can use <a href="http://daringfireball.net/projects/markdown/syntax">Markdown</a> editing here</span>
<span class="error-block" py:if="error">${error}</span>
</div>
</div>

<div class="control-group" py:with="error = errors.get('license_id', '')">
<label class="control-label" for="field-license">License</label>
<div class="controls">
<select id="field-license" name="license_id">
<py:for each="licence_desc, licence_id in c.licences">
<option value="${licence_id}" py:attrs="{'selected': 'selected' if data.get('license_id', '') == licence_id else None}" py:if="licence_desc">${licence_desc}</option>
</py:for>
</select>
<span class="error-block" py:if="error">${error}</span>
<span class="info-block">Don't worry if you don't know which license the data has been released under</span>
</div>
</div>

<div class="control-group" py:if="c.groups_available" py:with="groups = data.get('groups',[])">
<label for="field-groups" class="control-label">Add to Groups</label>
<div class="controls">
<select id="field-groups" name="groups__${len(groups)}__id">
<option selected="selected" value="">Select a group...</option>
<py:for each="group in c.groups_available">
<option value="${group['id']}" >${group['name']}</option>
</py:for>
</select>
</div>

<div class="control-group" py:if="len(data.get('groups', []))" py:with="groups = data.get('groups',[])">
<label for="groups__0__id" class="control-label">Member of Groups</label>
<div class="controls">
<py:for each="num, group in enumerate(groups)">
<?python
authorized_group = [group_authz for group_authz in c.groups_authz if group_authz['id'] == group['id']]
authorized_group = authorized_group[0] if authorized_group else None
?>
<div class="checkbox" py:if="'id' in group">
<label for="groups__${num}__checked">
<input type="${'checkbox' if authorized_group else 'hidden'}" name="groups__${num}__id" checked="checked" value="${group['id']}"/>
${group.get('name', authorized_group['name'] if authorized_group else '')}
</label>
<input type="hidden" name="groups__${num}__name" value="${group.get('name', authorized_group['name'] if authorized_group else '')}" />
</div>
</py:for>
</div>
</div>
</div>

<div class="form-actions">
<a class="btn" href="">Cancel</a>
<button class="btn btn-primary" type="submit" name="save">Next: Add Data</button>
</div>
</form>

0 comments on commit c7937b4

Please sign in to comment.