← Back to team overview

widelands-dev team mailing list archive

[Merge] lp:~franku/widelands-website/fix-redirect-links-coloring into lp:widelands-website

 

kaputtnik has proposed merging lp:~franku/widelands-website/fix-redirect-links-coloring into lp:widelands-website.

Requested reviews:
  Widelands Developers (widelands-dev)

For more details, see:
https://code.launchpad.net/~franku/widelands-website/fix-redirect-links-coloring/+merge/251168

This branch fixes failures for link coloring which comes with https://code.launchpad.net/~franku/widelands-website/added-css-link-classes

The old branch did not take care of redirects, so they are colored in yellow (misspelled link). This branch correct this and provide a Tooltip "This is a redirect and points to \"" + act_t + "\"" where act_t is the currently actual title for the article.

There are two db-querys needed, but i hope this do not slow the article rendering as much.
-- 
Your team Widelands Developers is requested to review the proposed merge of lp:~franku/widelands-website/fix-redirect-links-coloring into lp:widelands-website.
=== modified file 'mainpage/templatetags/wl_markdown.py'
--- mainpage/templatetags/wl_markdown.py	2015-01-08 21:40:25 +0000
+++ mainpage/templatetags/wl_markdown.py	2015-02-26 20:39:19 +0000
@@ -27,7 +27,7 @@
 # will check for internal wikipages links in all internal
 # links starting with /wiki/
 try:
-    from widelands.wiki.models import Article
+    from widelands.wiki.models import Article, ChangeSet
     check_for_missing_wikipages = True
 except ImportError:
     check_for_missing_wikipages = False
@@ -125,6 +125,20 @@
         if pn in ["list","search","history","feeds","observe","edit" ]:
             return { 'class': "specialLink" }
         
+        # Check for a redirect
+        try:
+            # try to get the article id; if this fails an IndexError is raised
+            a_id = ChangeSet.objects.filter( old_title=pn ).values_list('article_id')[0]
+            
+            # get actual title of article
+            act_t = Article.objects.get( id=a_id[0] ).title
+            if pn != act_t:
+                return { 'title': "This is a redirect and points to \"" + act_t + "\"" }
+            else:
+                return None
+        except IndexError:
+            pass
+        
         # article missing (or misspelled)
         if Article.objects.filter(title=pn).count() == 0:
             return { 'class': "missingLink", 'title': "This Link is misspelled or missing. Click to create it anyway." }


Follow ups