<form id="package-edit" class="package_create_form ckan" method="post" 
  py:attrs="{'class':'has-errors'} if errors else {}"
  xmlns:i18n="http://genshi.edgewall.org/i18n"
  xmlns:py="http://genshi.edgewall.org/"
  xmlns:xi="http://www.w3.org/2001/XInclude">


<div class="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, error)}</li>
</ul>
</div>

<fieldset id="basic-information">
  <legend> Basic information</legend>
  <dl>
    <dt><label class="field_opt" for="title">Title</label></dt>
    <dd><input id="title" name="title" type="text" value="${data.get('title', '')}"/></dd>
    <dd class="instructions basic">A short descriptive title for the data set.</dd>
    <dd class="instructions further">It should not be a description though - save that for the Notes field. Do not give a trailing full stop.</dd>
    <dd class="field_error" py:if="errors.get('title', '')">${errors.get('title', '')}</dd>

    <dt><label class="field_req" for="name">Name *</label></dt>
    <dd><input id="name" maxlength="100" name="name" type="text" value="${data.get('name', '')}" /></dd>
    <dd class="instructions basic">A unique identifier for the package.</dd>
    <dd class="instructions further">It should be broadly humanly readable, in the spirit of Semantic Web URIs. Only use an acronym if it is widely recognised. Renaming is possible but discouraged.</dd>
    <dd class="hints">2+ characters, lowercase, using only 'a-z0-9' and '-_'</dd>
    <dd class="field_error" py:if="errors.get('name', '')">${errors.get('name', '')}</dd>

    <dt><label class="field_opt" for="url">URL</label></dt>
    <dd><input id="url" name="url" type="text" value="${data.get('url', '')}"/></dd>
    <dd class="instructions basic">The URL for the web page describing the data (not the data itself).</dd>
    <dd class="hints">e.g. http://www.example.com/growth-figures.html</dd>
    <dd class="field_error" py:if="errors.get('url', '')">${errors.get('url', '')}</dd>

    <dt><label class="field_opt" for="notes">Notes</label></dt>
    <dd><textarea cols="60" id="notes" name="notes" rows="15">${data.get('notes', '')}</textarea></dd>
    <dd class="instructions basic">The main description of the dataset</dd>
    <dd class="instructions further">It is often displayed with the package title. In particular, it should start with a short sentence that describes the data set succinctly, because the first few words alone may be used in some views of the data sets.</dd>
    <dd class="hints">You can use <a href="http://daringfireball.net/projects/markdown/syntax">Markdown formatting</a> here.</dd>

    <dt><label class="field_opt" for="license_id">Licence</label></dt>
    <dd>
      <select id="license_id" 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}" >${licence_desc}</option>
        </py:for>
      </select>
    </dd>
    <dd class="instructions basic">The licence under which the dataset is released.</dd>

    <dt><label class="field_opt" for="tags">Tags</label></dt>
    <dd>
      <input class="long tagComplete" data-tagcomplete-queryparam="incomplete" 
               data-tagcomplete-url="/api/2/util/tag/autocomplete" id="tag_string" name="tag_string" size="60" type="text" 
               value="${data.get('tag_string') or ' '.join([tag['name'] for tag in data.get('tags', [])])}" />
    </dd>
    <dd class="instructions basic">Terms that may link this dataset to similar ones. For more information on conventions, see <a href="http://wiki.okfn.org/ckan/doc/faq#TagConventions">this wiki page</a>.</dd>
    <dd class="hints">e.g. pollution rivers water-quality</dd>
    <dd class="field_error" py:if="errors.get('tag_string', '')">${errors.get('tag_string', '')}</dd>
  </dl>
</fieldset>

<fieldset id="resources">
  <legend>Resources</legend>
  <table class="flexitable">
    <thead>
      <tr>
        <th class="field_req resource-url">URL*</th>
        <th class="field_opt resource-format">Format</th>
        <th class="field_opt resource-description">Description</th>
        <th class="field_opt resource-hash">Hash</th>
      </tr>
    </thead>
    <tbody>
      <py:for each="num, res in enumerate(data.get('resources', []) + [{}])">
      <tr>
        <py:for each="col in c.resource_columns">
        <td class="resource-${col}">
          <input name="resources__${num}__${col}" type="text" value="${res.get(col, '')}" class="${'medium-width' if col=='description' else 'short'}" />
        </td>
        </py:for>
        <td class="resource-id"><input name="resources__${num}__id" type="hidden" value="${res.get('id', '')}" /></td>
      </tr>
      </py:for>
    </tbody>
  </table>

  <div class="instructions basic">The files containing the data or address of the APIs for accessing it.</div>
  <div class="instructions further"><br />These can be repeated as required. For example if the data is being supplied in multiple formats, or split into different areas or time periods, each file is a different 'resource' which should be described differently. They will all appear on the dataset page on CKAN together.<br /><br /> <b>URL:</b> This is the Internet link directly to the data - by selecting this link in a web browser, the user will immediately download the full data set. Note that datasets are not hosted on this site, but by the publisher of the data. Alternatively the URL can point to an API server such as a SPARQL endpoint or JSON-P service.<br /> <b>Format:</b> This should give the file format in which the data is supplied. <br /><b>Description</b> Any information you want to add to describe the resource.<br /></div>
  <div class="hints">Format choices: CSV | RDF | XML | XBRL | SDMX | HTML+RDFa | Other as appropriate</div>
  <div class="field_error" py:if="errors.get('resources', '')">Package resource(s) incomplete.</div>
</fieldset>

<fieldset id="groups">
  <legend>Groups</legend>
  <dl>
    <py:for each="num, group in enumerate(data.get('groups', []))">
      <dt py:if="'id' in group">
      <input type="${'checkbox' if group['id'] in c.groups_authz else 'hidden'}" name="groups__${num}__id" checked="checked" value="${group['id']}" />
      <input type="hidden" name="groups__${num}__name" value="${group.get('name', c.groups_authz.get(group['id']))}" />
      </dt>     
      <dd py:if="'id' in group"><label for="groups__${num}__checked">${group.get('name', c.groups_authz.get(group['id']))}</label></dd>
    </py:for>

    <dt>Group</dt>
    <dd py:if="c.groups"> 
      <select id="groups__${len(data.get('groups', []))}__id" name="groups__${len(data.get('groups', []))}__id">
        <option selected="selected" value="">(None)</option>
        <py:for each="group_id, group_name in c.groups">
          <option value="${group_id}" py:if="group_id in c.groups_authz">${group_name}</option>
        </py:for>
      </select>
    </dd> 
    <dd py:if="not c.groups">Cannot add any groups.</dd>
  </dl>
</fieldset>
<fieldset id='detail'>
  <legend>Detail</legend>
  <dl>
    <dt><label class="field_opt" for="author">Author</label></dt>
    <dd><input id="author" name="author" type="text" value="${data.get('author', '')}" /></dd>
    <dd class="instructions basic">The name of the main contact, for enquiries about this particular dataset, using the e-mail address in the following field.</dd>

    <dt><label class="field_opt" for="author_email">Author email</label></dt>
    <dd><input id="author_email" name="author_email" type="text" value="${data.get('author_email', '')}" /></dd>

    <dt><label class="field_opt" for="maintainer">Maintainer</label></dt>
    <dd><input id="maintainer" name="maintainer" type="text" value="${data.get('maintainer', '')}" /></dd>
    <dd class="instructions basic">If there is another important contact person (in addition to the person in the Author field) then provide details here.</dd>

    <dt><label class="field_opt" for="maintainer_email">Maintainer email</label></dt>
    <dd><input id="maintainer_email" name="maintainer_email" type="text" value="${data.get('maintainer_email', '')}" /></dd>

    <dt><label class="field_opt" for="version">Version</label></dt>
    <dd><input id="version" maxlength="100" name="version" type="text" value="${data.get('version', '')}" /></dd>
    <dd class="instructions basic">A number representing the version (if applicable)</dd>
    <dd class="hints">e.g. 1.2.0</dd>

    <dt py:if="c.is_sysadmin or c.auth_for_change_state"><label class="field_opt" for="state">State</label></dt>
    <dd py:if="c.is_sysadmin or c.auth_for_change_state">
    <select id="state" name="state" >
      <option py:attrs="{'selected': 'selected' if data.get('state') == 'active' else None}" value="active">active</option>
      <option py:attrs="{'selected': 'selected' if data.get('state') == 'deleted' else None}" value="deleted">deleted</option>
    </select>
    </dd>

  </dl>
</fieldset>

<fieldset id='extras'>
  <legend>Extras</legend>
  <dl>
    <py:with vars="extras = data.get('extras', [])">
    <py:for each="num, extra in enumerate(data.get('extras', []))">
    <dt><label for="extras__${num}__value">${extra.get('key')}</label></dt>
    <dd>
      <input id="extras__${num}__key" name="extras__${num}__key" type="hidden" value="${extra.get('key')}" />
      <input id="extras__${num}__value" name="extras__${num}__value" type="text" value="${extra.get('value')}" />
      <input type="checkbox" name="extras__${num}__deleted" checked="${extra.get('deleted')}">Delete</input>
    </dd>
    </py:for>

    <py:for each="num in range(len(extras), len(extras) + 4)">
    <dt><label for="extras__${num}__key">New key</label></dt>
    <dd>
      <input class="medium-width" id="extras__${num}__key" name="extras__${num}__key" type="text" />
      with value
      <input class="medium-width" id="extras__${num}__value" name="extras__${num}__value" type="text" />
    </dd>
    </py:for>
    </py:with>
  </dl>
</fieldset>
<hr />

<label for="log_message">Edit summary (briefly describe the changes you have made)</label>
<textarea id="log_message" name="log_message" class="short wide">${data.get('log_message', '')}</textarea>

<div class="ckan-logged-in" style="display: none;">
  <p>Author: ${c.author}</p>
</div>
<div class="ckan-logged-out">
  <label>Author: ${c.author}</label>
  <p class="hints">
  Since you have not signed in this will just be your IP address.
  <a href="${h.url_for(controller='user', action='login', id=None)}" target="_blank">Click here to sign in</a> before saving (opens in new window).
  </p>
</div>

<div class="submit">
  <input name="preview" type="submit" value="Preview" />
  <input id="save" name="save" type="submit" value="Save" />
</div>

<p class="hints">
<strong>Important:</strong> By submitting content, you agree to release your contributions
  under the open license specified on the <a href="/license">license page</a>. Please <strong>refrain</strong> from editing this page if you are <strong>not</strong> happy to do this.
</p>


</form>
