changeset 2239:d5ad38a42754

Code and template for trash view.
author Ashutosh Singla <ashu1461@gmail.com>
date Sun, 18 Aug 2013 01:06:00 +0530
parents 913c1b908070
children 608bf77ca90f
files MoinMoin/apps/frontend/views.py MoinMoin/constants/keys.py MoinMoin/items/__init__.py MoinMoin/items/_tests/test_Item.py MoinMoin/templates/trash.html
diffstat 5 files changed, 72 insertions(+), 6 deletions(-) [+]
line wrap: on
line diff
--- a/MoinMoin/apps/frontend/views.py	Mon Aug 12 20:49:37 2013 +0530
+++ b/MoinMoin/apps/frontend/views.py	Sun Aug 18 01:06:00 2013 +0530
@@ -829,6 +829,28 @@
     )
 
 
+@frontend.route('/+trash')
+def trash():
+    """
+    Returns the trashed items.
+    """
+    trash = _trashed()
+    return render_template('trash.html',
+                           headline=_(u'Trashed Items'),
+                           title_name=_(u'Trashed Items'),
+                           results=trash)
+
+
+def _trashed():
+    q = And([Term(WIKINAME, app.cfg.interwikiname), Term(TRASH, True)])
+    trashedEntry = namedtuple('trashedEntry', 'fqname oldname revid mtime comment editor')
+    results = []
+    for rev in flaskg.storage.search(q, limit=None):
+        meta = rev.meta
+        results.append(trashedEntry(rev.fqname, meta[NAME_OLD], meta[REVID], meta[MTIME], meta[COMMENT], get_editor_info(meta)))
+    return results
+
+
 @frontend.route('/+mychanges')
 def mychanges():
     """
--- a/MoinMoin/constants/keys.py	Mon Aug 12 20:49:37 2013 +0530
+++ b/MoinMoin/constants/keys.py	Sun Aug 18 01:06:00 2013 +0530
@@ -39,6 +39,7 @@
 EXTRA = u"extra"
 COMMENT = u"comment"
 SUMMARY = u"summary"
+TRASH = u"trash"
 
 # we need a specific hash algorithm to store hashes of revision data into meta
 # data. meta[HASH_ALGORITHM] = hash(rev_data, HASH_ALGORITHM)
--- a/MoinMoin/items/__init__.py	Mon Aug 12 20:49:37 2013 +0530
+++ b/MoinMoin/items/__init__.py	Sun Aug 18 01:06:00 2013 +0530
@@ -49,7 +49,7 @@
     NAME, NAME_OLD, NAME_EXACT, WIKINAME, MTIME, ITEMTYPE,
     CONTENTTYPE, SIZE, ACTION, ADDRESS, HOSTNAME, USERID, COMMENT,
     HASH_ALGORITHM, ITEMID, REVID, DATAID, CURRENT, PARENTID, NAMESPACE,
-    UFIELDS_TYPELIST, UFIELDS
+    UFIELDS_TYPELIST, UFIELDS, TRASH,
 )
 from MoinMoin.constants.contenttypes import CHARSET, CONTENTTYPE_NONEXISTENT
 from MoinMoin.constants.itemtypes import (
@@ -530,7 +530,6 @@
                 if not isinstance(oldname, list):
                     oldname = [oldname]
                 if delete or name not in oldname:  # this is a delete or rename
-                    meta[NAME_OLD] = oldname[:]
                     try:
                         oldname.remove(self.name)
                     except ValueError:
@@ -538,12 +537,19 @@
                     if not delete:
                         oldname.append(name)
                     meta[NAME] = oldname
-            else:
-                meta[NAME] = [name]
 
         if comment is not None:
             meta[COMMENT] = unicode(comment)
 
+        if currentrev:
+            current_names = currentrev.meta.get(NAME, [])
+            new_names = meta.get(NAME, [])
+            deleted_names = set(current_names) - set(new_names)
+            if deleted_names:  # some names have been deleted.
+                meta[NAME_OLD] = current_names
+                if not new_names:  # if no names left, then set the trash flag.
+                    meta[TRASH] = True
+
         if not overwrite and REVID in meta:
             # we usually want to create a new revision, thus we must remove the existing REVID
             del meta[REVID]
--- a/MoinMoin/items/_tests/test_Item.py	Mon Aug 12 20:49:37 2013 +0530
+++ b/MoinMoin/items/_tests/test_Item.py	Sun Aug 18 01:06:00 2013 +0530
@@ -12,7 +12,7 @@
 
 from MoinMoin._tests import become_trusted, update_item
 from MoinMoin.items import Item, NonExistent, IndexEntry, MixedIndexEntry
-from MoinMoin.constants.keys import ITEMTYPE, CONTENTTYPE, NAME, NAME_OLD, COMMENT, ACTION, ADDRESS
+from MoinMoin.constants.keys import ITEMTYPE, CONTENTTYPE, NAME, NAME_OLD, COMMENT, ACTION, ADDRESS, TRASH, ITEMID
 from MoinMoin.constants.contenttypes import CONTENTTYPE_NONEXISTENT
 from MoinMoin.constants.itemtypes import ITEMTYPE_NONEXISTENT
 
@@ -372,5 +372,4 @@
         assert item.meta['new_test_key'] == update_meta['new_test_key']
         assert 'none_test_key' not in item.meta
 
-
 coverage_modules = ['MoinMoin.items']
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/MoinMoin/templates/trash.html	Sun Aug 18 01:06:00 2013 +0530
@@ -0,0 +1,38 @@
+{% extends theme("layout.html") %}
+{% import "utils.html" as utils %}
+{% block content %}
+{% if headline %}
+<h1>{{ headline }}</h1>
+{% endif %}
+Total: {{ results|count }}
+    {% if results %}
+        <table class="zebra">
+            <thead>
+                <tr>
+                    <th>{{ _("Old Name") }}</th>
+                    <th>{{ _("Rev.") }}</th>
+                    <th>{{ _("Timestamp") }}</th>
+                    <th>{{ _("Editor") }}</th>
+                    <th>{{ _("Comment") }}</th>
+                    <th colspan="3">{{ _("Actions") }}</th>
+                </tr>
+            </thead>
+            <tbody>
+                {% for result in results| sort(attribute='mtime', reverse=True)%}
+                <tr>
+                    <td class="moin-wordbreak">{{ result.oldname|join(' | ') }}</td>
+                    <td>{{ result.revid | shorten_id }}</td>
+                    <td>{{ result.mtime|datetimeformat }}</td>
+                    <td class="moin-wordbreak">{{ utils.show_editor_info(result.editor)  }}</td>
+                    <td class="moin-wordbreak">{{ result.comment }}</td>
+                    <td><a href="{{ url_for('frontend.show_item', item_name=result.fqname) }}">{{ _('show') }}</a></td>
+                    {% if user.may.write(result.fqname) -%}
+                    <td><a href="{{ url_for('frontend.show_item', item_name=result.fqname) }}">{{ _('History') }}</a></td>
+                    <td><a href="{{ url_for('frontend.destroy_item', item_name=result.fqname) }}">{{ _('Destroy') }}</a></td>
+                    {%- endif %}
+                </tr>
+                {% endfor %}
+            </tbody>
+        </table>
+    {% endif %}
+{% endblock %}