Commits

Thomas Waldmann  committed 9d4dad9

add +forwardrefs view to complement +backrefs view

  • Participants
  • Parent commits c97b585

Comments (0)

Files changed (2)

File MoinMoin/apps/frontend/_tests/test_frontend.py

     def test_index(self):
         self._test_view('frontend.index', 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'))
+
     def test_backrefs(self):
         self._test_view('frontend.backrefs', status='200 OK', viewopts=dict(item_name='DoesntExist'))
 

File MoinMoin/apps/frontend/views.py

 Disallow: /+similar_names/
 Disallow: /+quicklink/
 Disallow: /+subscribe/
+Disallow: /+forwardrefs/
 Disallow: /+backrefs/
 Disallow: /+wanteds/
 Disallow: /+orphans/
     return [rev.name for rev in revs]
 
 
+@frontend.route('/+forwardrefs/<itemname:item_name>')
+def forwardrefs(item_name):
+    """
+    Returns the list of all 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 the items linked from this item
+    """
+    refs = _forwardrefs(item_name)
+    return render_template('link_list_item_panel.html',
+                           item_name=item_name,
+                           headline=_(u"Items that are referred by '%(item_name)s'", item_name=item_name),
+                           item_names=refs
+    )
+
+
+def _forwardrefs(item_name):
+    """
+    Returns a list with all names of items that get referenced from item_name
+
+    :param item_name: the name of the current item
+    :type item_name: unicode
+    :returns: the list of all items which are referenced from this item
+    """
+    q = {WIKINAME: app.cfg.interwikiname,
+         NAME_EXACT: item_name,
+        }
+    rev = flaskg.storage.document(**q)
+    if rev is None:
+        refs = []
+    else:
+        refs = rev.meta.get(ITEMLINKS, []) + rev.meta.get(ITEMTRANSCLUSIONS, [])
+    return refs
+
+
 @frontend.route('/+backrefs/<itemname:item_name>')
 def backrefs(item_name):
     """