view website/issues/html/query.edit.html @ 5525:bb7865241f8a

Make CSV import/export compatible across Python versions (also RDBMS journals) (issue 2550976, issue 2550975). The roundup-admin export and import commands are used for migrating between different database backends. It is desirable that they should be usable also for migrations between Python 2 and Python 3, and in some cases (e.g. with the anydbm backend) this may be required. To be usable for such migrations, the format of the generated CSV files needs to be stable, meaning the same as currently used with Python 2. The export process uses repr() to produce the fields in the CSV files and eval() to convert them back to Python data structures. repr() of strings with non-ASCII characters produces different results for Python 2 and Python 3. This patch adds repr_export and eval_import functions to roundup/anypy/strings.py which provide the required operations that are just repr() and eval() in Python 2, but are more complicated in Python 3 to use data representations compatible with Python 2. These functions are then used in the required places for export and import. repr() and eval() are also used in storing the dict of changed values in the journal for the RDBMS backends. It is similarly desirable that the database be compatible between Python 2 and Python 3, so that export and import do not need to be used for a migration between Python versions for non-anydbm back ends. Thus, this patch changes rdbms_common.py in the places involved in storing journals in the database, not just in those involved in import/export. Given this patch, import/export with non-ASCII characters appear based on some limited testing to work across Python versions, and an instance using the sqlite backend appears to be compatible between Python versions without needing import/export, *if* the sessions/otks databases (which use anydbm) are deleted when changing Python version.
author Joseph Myers <jsm@polyomino.org.uk>
date Sun, 02 Sep 2018 23:48:04 +0000
parents 58c52057418d
children
line wrap: on
line source

<!-- dollarId: user.item,v 1.7 2002/08/16 04:29:04 richard Exp dollar-->
<tal:block metal:use-macro="templates/page/macros/icing">
<title metal:fill-slot="head_title" i18n:translate=""
 >"Your Queries" Editing - <span tal:replace="config/TRACKER_NAME"
 i18n:name="tracker" /></title>
<span metal:fill-slot="body_title" tal:omit-tag="python:1"
 i18n:translate="">"Your Queries" Editing</span>

<td class="content" metal:fill-slot="content"
    tal:define="anti_csrf_this_page python:utils.anti_csrf_nonce()" >

<span tal:condition="not:context/is_edit_ok"
 i18n:translate="">You are not allowed to edit queries.</span>

<script tal:attributes="nonce request/client/client_nonce"
	language="javascript">
// This allows us to make the delete button an immediate action.
// The post_to_url function comes from:
//    http://stackoverflow.com/questions/133925/javascript-post-request-like-a-form-submit
function retire(qid, csrf) {
    post_to_url('query'+qid, {'@action': 'retire', '@template':'edit',
                '@csrf': csrf});
}

function restore(qid, csrf) {
    post_to_url('query'+qid, {'@action': 'restore', '@template': 'edit',
                '@csrf': csrf});
}
function post_to_url(path, params, method) {
    method = method || "post"; // Set method to post by default if not specified.

    var form = document.createElement("form");
    form.setAttribute("method", method);
    form.setAttribute("action", path);

    for(var key in params) {
        if(params.hasOwnProperty(key)) {
            var hiddenField = document.createElement("input");
            hiddenField.setAttribute("type", "hidden");
            hiddenField.setAttribute("name", key);
            hiddenField.setAttribute("value", params[key]);

            form.appendChild(hiddenField);
         }
    }

    document.body.appendChild(form);
    form.submit();
}
</script>

<form method="POST" onSubmit="return submit_once()" action="query"
      enctype="multipart/form-data" tal:condition="context/is_edit_ok">

<table class="list" width="100%"
       tal:define="uid request/user/id; mine request/user/queries">

<tr><th i18n:translate="">Query</th>
    <th i18n:translate="">Include in "Your Queries"</th>
    <th i18n:translate="">Edit</th>
    <th i18n:translate="">Private to you?</th>
    <th i18n:translate="">delete/restore<br> (javascript<br>required)</th>
</tr>
<tr>
 <td colspan="5"><b i18n:translate="">Queries I created</b></td>
</tr>

<tr tal:define="queries python:db.query.filter(filterspec={'creator': uid})"
    tal:repeat="query queries">
 <tal:block>
 <td><a tal:attributes="href string:${query/klass}?${query/url}"
        tal:content="query/name">query</a></td>

 <td metal:define-macro="include">
  <select tal:condition="python:query.id not in mine"
          tal:attributes="name string:user${uid}@add@queries">
    <option value="" i18n:translate="">leave out</option>
    <option tal:attributes="value query/id" i18n:translate="">include</option>
  </select>
  <select tal:condition="python:query.id in mine"
          tal:attributes="name string:user${uid}@remove@queries">
    <option value="" i18n:translate="">leave in</option>
    <option tal:attributes="value query/id" i18n:translate="">remove</option>
  </select>
 </td>

 <td><a tal:attributes="href string:query${query/id}" i18n:translate="">edit</a></td>

 <td>
  <select tal:attributes="name string:query${query/id}@private_for">
   <option tal:attributes="selected python:query.private_for == uid;
           value uid" i18n:translate="">yes</option>
   <option tal:attributes="selected python:not query.private_for"
           value="-1" i18n:translate="">no</option>
  </select>
 </td>

 <td>
  <input type="button" value="Delete" i18n:attributes="value"
  tal:attributes="onClick python:'''retire('%s','%s')'''%(query.id,anti_csrf_this_page)">
  </td>
  </tal:block>
</tr>
<tr>
 <td colspan="4"><b i18n:translate="">Queries others created</b></td>
 <td colspan="4"><b i18n:translate="">Owner</b></td>
</tr>

<tr tal:define="queries
		python:db.query.filter(filterspec={'private_for': None})"
     tal:repeat="query queries">
 <tal:block tal:condition="python:not query.creator == uid">
 <td><a tal:attributes="href string:${query/klass}?${query/url}"
        tal:content="query/name">query</a></td>

 <td metal:use-macro="template/macros/include" />

 <td colspan="2" tal:condition="not:query/is_edit_ok"
    i18n:translate="">[not yours to edit]</td>
 <td colspan="2" tal:condition="query/is_edit_ok"
    i18n:translate=""><a tal:attributes="href string:query${query/id}" i18n:translate="">edit</a></td>
 <td colspan="2"
    tal:content="query/creator" i18n:translate="">put query owner here</td>
 </tal:block>
</tr>

<tr>
 <td colspan="5"><b i18n:translate="">Active retired/private queries</b></td>
</tr>
<tal:block tal:repeat="query request/user/queries">
<tr>
 <tal:block condition="python:path('query/is_retired')">
 <td><a tal:attributes="href string:${query/klass}?${query/url}"
        tal:content="query/name">query</a></td>
 <tal:block tal:condition="python: not query.creator == uid">
    <td metal:use-macro="template/macros/include"> </td>
 </tal:block>
 <td colspan="2" tal:condition="python: not query.creator == uid" i18n:translate="">[query is retired]</td>
 <td colspan="3" tal:condition="python:  query.creator == uid" i18n:translate="">[query is retired]</td>
 <td tal:condition="python:query.creator == uid">
  <input type="button" value="Restore" i18n:attributes="value"
  tal:attributes="onClick python:'''restore('%s','%s')'''%(query.id,anti_csrf_this_page)">
  </td>
 <td colspan="1" tal:condition="python:not query.creator == uid" tal:content="query/creator" i18n:translate="">put query owner here</td>
 </tal:block>
</tr>
<tr>
 <tal:block condition="python:path('query/private_for') and (not query.creator == uid)">
 <td><a tal:attributes="href string:${query/klass}?${query/url}"
        tal:content="query/name">query</a></td>
 <tal:block tal:condition="python: not query.creator == uid">
    <td metal:use-macro="template/macros/include"> </td>
 </tal:block>
 <td colspan="2" i18n:translate="">[query is private]</td>
 <td tal:condition="python:query.creator == uid">
  <input type="button" value="Restore" i18n:attributes="value"
  tal:attributes="onClick python:'''restore('%s','%s')'''%(query.id,anti_csrf_this_page)">
   </td>
 <td colspan="1" tal:content="query/creator" i18n:translate="">put query owner here</td>
 </tal:block>
</tr>
</tal:block>
<tr><td colspan="5">
   <input type="hidden" name="@action" value="edit">
   <input type="hidden" name="@template" value="edit">
   <input name="@csrf" type="hidden"
          tal:attributes="value anti_csrf_this_page">
   <input type="submit" value="Save Selection" i18n:attributes="value">
</td></tr>

</table>

</form>
</td>
</tal:block>

Roundup Issue Tracker: http://roundup-tracker.org/