Skip to content

Commit

Permalink
[2474] Add new form "pages" for group forms
Browse files Browse the repository at this point in the history
This makes it easier for the new and edit forms to share the same
templates by simply overriding blocks.
  • Loading branch information
aron committed Jun 5, 2012
1 parent 31fc3ec commit 6e272c5
Show file tree
Hide file tree
Showing 2 changed files with 115 additions and 0 deletions.
80 changes: 80 additions & 0 deletions ckan/templates/group/pages/form.html
@@ -0,0 +1,80 @@
{% import 'macros/form.html' as form %}

<form class="dataset-form form-horizontal" method="post">
{% block error_summary %}
{% if error_summary %}
<div class="error-explanation">
<h2>{{ _('Errors in form') }}</h2>
<p>{{ _('The form contains invalid entries:') }}</p>
<ul>
{% for key, error in error_summary.items() %}
<li>{{ key }} {{ error }}</li>
{% endfor %}
</ul>
</div>
{% endif %}
{% endblock %}

{% block basic_fields %}
{{ form.input('title', label=_('Title'), id='field-title', placeholder=_('My Group'), data=data, errors=errors, classes=['control-full']) }}
{{ form.prepend('name', label=_('URL'), prepend=h.url(controller='group', action='index') ~ '/', id='field-url', placeholder=_('my-group'), data=data, errors=errors) }}
{{ form.markdown('description', label=_('Description'), id='field-description', placeholder=_('A little information about my group...'), data=data, errors=errors) }}
{{ form.input('image_url', label=_('Image URL'), id='field-url', type='url', placeholder=_('http://example.com/my-image.jpg'), data=data, errors=errors, classes=['control-full']) }}
{% if c.is_sysadmin or c.auth_for_change_state %}
{{ form.select('state', label=_('State'), id='field-state', selected=data.state, options={active: _('Active'), deleted: _('Deleted')}, errors=errors) }}
{% endif %}
{% endblock %}

{% block custom_fields %}
{% for extra in data.extras %}
{% set prefix = 'extras__%d__' % loop.index0 %}
{{ form.keyvalue(
names=(prefix ~ 'key', prefix ~ 'value', prefix ~ 'deleted'),
id='field-extras-%d' % loop.index,
label=_('Custom Field'),
values=(extra.key, extra.value, extra.deleted),
error=errors[prefix ~ 'key'] or errors[prefix ~ 'value']
) }}
{% endfor %}

{# Add a max if 3 empty columns #}
{% for extra in range(data.extras|count, 3) %}
{% set index = (loop.index0 + data.extras|count) %}
{% set prefix = 'extras__%d__' % index %}
{{ form.keyvalue(
names=(prefix ~ 'key', prefix ~ 'value', prefix ~ 'deleted'),
id='field-extras-%d' % index,
label=_('Custom Field'),
values=(extra.key, extra.value, extra.deleted),
error=errors[prefix ~ 'key'] or errors[prefix ~ 'value']
) }}
{% endfor %}
{% endblock %}

{% block dataset_fields %}
{% if data.packages %}
<div class="control-group">
<label class="control-label">{{ _('Datasets') }}</label>
<div class="controls">
{% for dataset in data.packages %}
<label class="checkbox" for="field-dataset-{{ loop.index }}">
<input id="field-dataset-{{ loop.index }}" type="checkbox" name="packages__{{ loop.index }}__name" value="{{ dataset.name }}" checked="checked" />
{{ dataset.title }}
</label>
{% endfor %}
</div>
</div>
{% endif %}

{% set dataset_name = 'packages__%s__name' % data.packages|length %}
{{ form.input(dataset_name, label=_('Add Dataset'), id="field-dataset", value=data[dataset_name]) }}
{% endblock %}

<div class="form-actions">
{% if action == 'edit' %}
<button class="btn btn-primary" name="save">{{ _('Edit Group') }}</button>
{% else %}
<button class="btn btn-primary" name="save">{{ _('Create Group') }}</button>
{% endif %}
</div>
</form>
35 changes: 35 additions & 0 deletions ckan/templates/group/pages/form_page.html
@@ -0,0 +1,35 @@
{% extends "page.jinja.html" %}

{% block title %}{{ _('Add a Group') }} - {{ super() }}{% endblock %}

{% block breadcrumb %}
<ol class="breadcrumb">
<li>{{ h.nav_link(_('Groups'), controller='group', action='index') }}</li>
<li class="current">{% block breadcrumb_link %}{{ h.nav_link(_('Add a Group'), controller='group', action='new') }}{% endblock %}</li>
</ol>
{% endblock %}

{% block primary_content %}
<div class="module">
<div class="content">
<h1 class="page-heading">{{ _('Add a Group') }}</h1>
{% block form %}
{{ c.form | safe }}
{% endblock %}
</div>
</div>
{% endblock %}

{% block secondary_content %}
<div class="module info">
<h2 class="heading"><i class="ckan-icon ckan-icon-info"></i> {{ _('What are Groups?') }}</h2>
<div class="content">
{% trans %}
<p>Whilst tags are great at collecting datasets together, there are
occasions when you want to restrict users from editing a collection.</p>
<p>A group can be set-up to specify which users have permission to add or
remove datasets from it.</p>
{% endtrans %}
</div>
</div>
{% endblock %}

0 comments on commit 6e272c5

Please sign in to comment.