changeset 2846:f9bccf2e3d1e

fix #376 combine sitemap with references view
author RogerHaase <haaserd@gmail.com>
date Tue, 28 Oct 2014 20:56:27 -0700
parents 1006d2d15d70
children 09e05a641722
files MoinMoin/apps/frontend/_tests/test_frontend.py MoinMoin/apps/frontend/views.py MoinMoin/config/default.py MoinMoin/templates/refs.html MoinMoin/templates/sitemap.html
diffstat 5 files changed, 42 insertions(+), 58 deletions(-) [+]
line wrap: on
line diff
--- a/MoinMoin/apps/frontend/_tests/test_frontend.py	Mon Oct 27 11:32:55 2014 -0700
+++ b/MoinMoin/apps/frontend/_tests/test_frontend.py	Tue Oct 28 20:56:27 2014 -0700
@@ -126,9 +126,6 @@
     def test_index(self):
         self._test_view('frontend.index', status='200 OK', viewopts=dict(item_name='DoesntExist'))
 
-    def test_refs(self):
-        self._test_view('frontend.refs', status='200 OK', viewopts=dict(item_name='DoesntExist'))
-
     def test_forwardrefs(self):
         self._test_view('frontend.forwardrefs', status='200 OK', viewopts=dict(item_name='DoesntExist'))
 
--- a/MoinMoin/apps/frontend/views.py	Mon Oct 27 11:32:55 2014 -0700
+++ b/MoinMoin/apps/frontend/views.py	Tue Oct 28 20:56:27 2014 -0700
@@ -109,7 +109,6 @@
 Disallow: /+similar_names/
 Disallow: /+quicklink/
 Disallow: /+subscribe/
-Disallow: /+refs/
 Disallow: /+forwardrefs/
 Disallow: /+backrefs/
 Disallow: /+wanteds/
@@ -997,25 +996,6 @@
     return history
 
 
-@frontend.route('/+refs/<itemname:item_name>')
-def refs(item_name):
-    """
-    Returns the list of all incoming/outgoing links or transclusions of item item_name
-
-    :param item_name: the name of the current item
-    :type item_name: unicode
-    :returns: a page with all incoming/outgoing item links of this item
-    """
-    refs = _forwardrefs(item_name)
-    backrefs = _backrefs(item_name)
-    return render_template('refs.html',
-                           item_name=item_name,
-                           fqname=split_fqname(item_name),
-                           refs=split_fqname_list(refs),
-                           backrefs=backrefs
-    )
-
-
 @frontend.route('/+forwardrefs/<itemname:item_name>')
 def forwardrefs(item_name):
     """
@@ -2137,10 +2117,13 @@
     fq_name = split_fqname(item_name)
     if not flaskg.storage.get_item(**fq_name.query):
         abort(404, item_name)
+    backrefs = NestedItemListBuilder().recurse_build([fq_name], backrefs=True)
+    del backrefs[0]  # don't show current item name as sole toplevel list item
     sitemap = NestedItemListBuilder().recurse_build([fq_name])
     del sitemap[0]  # don't show current item name as sole toplevel list item
     return render_template('sitemap.html',
                            item_name=item_name,  # XXX no item
+                           backrefs=backrefs,
                            sitemap=sitemap,
                            fqname=fq_name,
     )
@@ -2152,27 +2135,30 @@
         self.numnodes = 0
         self.maxnodes = 35  # approx. max count of nodes, not strict
 
-    def recurse_build(self, fq_names):
+    def recurse_build(self, fq_names, backrefs=False):
         result = []
         if self.numnodes < self.maxnodes:
             for fq_name in fq_names:
                 self.children.add(fq_name)
                 result.append(fq_name)
                 self.numnodes += 1
-                childs = self.childs(fq_name)
+                childs = self.childs(fq_name, backrefs=backrefs)
                 if childs:
-                    childs = self.recurse_build(childs)
+                    childs = self.recurse_build(childs, backrefs=backrefs)
                     result.append(childs)
         return result
 
-    def childs(self, fq_name):
+    def childs(self, fq_name, backrefs=False):
         # does not recurse
         try:
             item = flaskg.storage.get_item(**fq_name.query)
             rev = item[CURRENT]
         except (AccessDenied, KeyError):
             return []
-        itemlinks = set(split_fqname_list(rev.meta.get(ITEMLINKS, [])))
+        if backrefs:
+            itemlinks = _backrefs(fq_name.value)
+        else:
+            itemlinks = set(split_fqname_list(rev.meta.get(ITEMLINKS, []) + rev.meta.get(ITEMTRANSCLUSIONS, [])))
         return [child for child in itemlinks if self.is_ok(child)]
 
     def is_ok(self, child):
--- a/MoinMoin/config/default.py	Mon Oct 27 11:32:55 2014 -0700
+++ b/MoinMoin/config/default.py	Tue Oct 28 20:56:27 2014 -0700
@@ -412,7 +412,6 @@
             ('frontend.rename_item', L_('Rename'), L_('Rename this item'), True, ),
             ('frontend.delete_item', L_('Delete'), L_('Delete this item'), True, ),
             ('frontend.destroy_item', L_('Destroy'), L_('Completely destroy this item'), True, ),
-            ('frontend.refs', L_('References'), L_('Show incoming and outgoing references'), False, ),
             ('frontend.sitemap', L_('Site Map'), L_('Local Site Map of this item'), True, ),
             ('frontend.similar_names', L_('Similar'), L_('Items with similar names'), False, ),
         ], 'list of edit bar entries (list of tuples (endpoint, label))'),
--- a/MoinMoin/templates/refs.html	Mon Oct 27 11:32:55 2014 -0700
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,18 +0,0 @@
-{% extends theme("show.html") %}
-{% block content %}
-    <h1>{{ _('Item References') }}</h1>
-    <h2>{{ _('Outgoing') }}</h2>
-    <ul class="moin-link-list">
-        {% for fq_name in refs|sort(attribute='value') %}
-            <li><a class="moin-fqname" href="{{ url_for('frontend.show_item', item_name=fq_name) }}" data-fqname="{{fq_name}}">{{ fq_name.value }}</a></li>
-
-        {% endfor %}
-    </ul>
-    <h2>{{ _('Incoming') }}</h2>
-    <ul class="moin-link-list">
-        {% for fq_name in backrefs|sort(attribute='value') %}
-            <li><a class="moin-fqname" href="{{ url_for('frontend.show_item', item_name=fq_name) }}" data-fqname="{{fq_name}}">{{ fq_name.value }}</a></li>
-
-        {% endfor %}
-    </ul>
-{% endblock %}
--- a/MoinMoin/templates/sitemap.html	Mon Oct 27 11:32:55 2014 -0700
+++ b/MoinMoin/templates/sitemap.html	Tue Oct 28 20:56:27 2014 -0700
@@ -2,17 +2,37 @@
 
 {% set title = _("SiteMap of '%(item_name)s'", item_name=item_name) %}
 
+{% macro showtree(sitemap) %}
+    <ul>
+        {% for entry in sitemap recursive %}
+            {% if isinstance(entry, list) %}
+                {% if loop.first %}
+                    {{ loop(entry) }}
+                {% else %}
+                    <li style="list-style-type: none;">
+                        <ul class="moin-link-list">
+                            {{ loop(entry) }}
+                        </ul>
+                    </li>
+                {% endif %}
+            {% else %}
+                <li>
+                    <a href="{{ url_for('frontend.sitemap', item_name=entry) }}">
+                        <span class="fa fa-sitemap"></span>
+                    </a>
+                    <a class="moin-fqname" href="{{ url_for('frontend.show_item', item_name=entry) }}" data-fqname="{{entry}}">
+                        {{ entry.value }}
+                    </a>
+                </li>
+            {% endif %}
+        {% endfor %}
+    </ul>
+{% endmacro %}
+
 {% block content %}
     <h1>{{ title }}</h1>
-    {% for entry in sitemap recursive %}
-        {% if isinstance(entry, list) %}
-            <ul>
-                {{ loop(entry) }}
-            </ul>
-        {% else %}
-            <li>
-                <a class="moin-fqname" href="{{ url_for('frontend.show_item', item_name=entry) }}" data-fqname="{{entry}}">{{ entry.value }}</a>
-            </li>
-        {% endif %}
-    {% endfor %}
+    <h2>{{ _('Outgoing') }}</h2>
+    {{ showtree(sitemap) }}
+    <h2>{{ _('Incoming') }}</h2>
+    {{ showtree(backrefs) }}
 {% endblock %}