Commits

Ashutosh Singla committed 980b4f2

Moved trash view under admin.

Comments (0)

Files changed (4)

MoinMoin/apps/admin/templates/admin/index.html

     <li><a href="{{ url_for('admin.userbrowser') }}">{{ _("Users") }}</a></li>
     <li><a href="{{ url_for('admin.wikiconfig') }}">{{ _("Show Wiki Configuration") }}</a></li>
     <li><a href="{{ url_for('admin.wikiconfighelp') }}">{{ _("Wiki Configuration Help") }}</a></li>
+    <li><a href="{{ url_for('admin.trash', namespace='all') }}">{{ _("Trash") }}</a></li>
 </ul>
 {% endblock %}

MoinMoin/apps/admin/templates/admin/trash.html

+{% 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 %}

MoinMoin/apps/admin/views.py

 
 This shows the user interface for wiki admins.
 """
-
+from collections import namedtuple
 from flask import request, url_for, flash, redirect
 from flask import current_app as app
 from flask import g as flaskg
-
+from whoosh.query import Term, And
 from MoinMoin.i18n import _, L_, N_
-from MoinMoin.themes import render_template
+from MoinMoin.themes import render_template, get_editor_info
 from MoinMoin.apps.admin import admin
 from MoinMoin import user
-from MoinMoin.constants.keys import NAME, ITEMID, SIZE, EMAIL, DISABLED, NAME_EXACT
-from MoinMoin.constants.namespaces import NAMESPACE_USERPROFILES
+from MoinMoin.constants.keys import NAME, ITEMID, SIZE, EMAIL, DISABLED, NAME_EXACT, WIKINAME, TRASH, NAMESPACE, NAME_OLD, REVID, MTIME, COMMENT
+from MoinMoin.constants.namespaces import NAMESPACE_USERPROFILES, NAMESPACE_DEFAULT, NAMESPACE_ALL
 from MoinMoin.constants.rights import SUPERUSER
 from MoinMoin.security import require_permission
 from MoinMoin.util.interwiki import CompositeName
                            title_name=_(u"Item Sizes"),
                            headings=headings,
                            rows=rows)
+
+
+@admin.route('/trash', defaults=dict(namespace=NAMESPACE_DEFAULT), methods=['GET'])
+@admin.route('/<namespace>/trash')
+def trash(namespace):
+    """
+    Returns the trashed items.
+    """
+    trash = _trashed(namespace)
+    return render_template('admin/trash.html',
+                           headline=_(u'Trashed Items'),
+                           title_name=_(u'Trashed Items'),
+                           results=trash)
+
+
+def _trashed(namespace):
+    q = And([Term(WIKINAME, app.cfg.interwikiname), Term(TRASH, True)])
+    if not namespace == NAMESPACE_ALL:
+        q = And([q, Term(NAMESPACE, namespace), ])
+    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

MoinMoin/templates/trash.html

-{% 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 %}