]> git.openstreetmap.org Git - osqa.git/commitdiff
It is now possable for users to add tags like "REP_TO_VOTE_UP" to the faq page and...
authorqw3rty <qw3rty@0cfe37f9-358a-4d5e-be75-b63607b5c754>
Tue, 4 May 2010 17:07:48 +0000 (17:07 +0000)
committerqw3rty <qw3rty@0cfe37f9-358a-4d5e-be75-b63607b5c754>
Tue, 4 May 2010 17:07:48 +0000 (17:07 +0000)
git-svn-id: http://svn.osqa.net/svnroot/osqa/trunk@125 0cfe37f9-358a-4d5e-be75-b63607b5c754

forum/settings/settingsmarkdown.py [new file with mode: 0644]
forum/views/meta.py

diff --git a/forum/settings/settingsmarkdown.py b/forum/settings/settingsmarkdown.py
new file mode 100644 (file)
index 0000000..b4d47d4
--- /dev/null
@@ -0,0 +1,52 @@
+from os import linesep
+from csv import reader, QUOTE_NONE
+import markdown
+from markdown import Extension
+from markdown.preprocessors import Preprocessor
+import re
+
+#from django.conf import settings
+from forum import settings
+
+class SettingsExtension(markdown.Extension):
+    def __init__(self, configs):
+        self.configs = {} # settings.REP_TO_VOTE_UP}
+        for key, value in configs:
+            self.config[key] = value
+
+        # self.extendMarkdown(markdown.Markdown()., config)
+
+    def reset(self):
+        pass
+
+    def extendMarkdown(self, md, md_globals):
+        md.registerExtension(self)
+        self.parser = md.parser
+        md.preprocessors.add('MinRep', SettingsPre(self), '_begin')
+
+class SettingsPre(Preprocessor):
+    def run(self, lines):
+        new_lines = []
+        for line in lines:
+
+            # tags relating to the minrip.py settings
+            line = line.replace('REP_TO_VOTE_UP', '%d' % settings.REP_TO_VOTE_UP)
+            line = line.replace('REP_TO_VOTE_DOWN', '%d' % settings.REP_TO_VOTE_DOWN)
+            line = line.replace('REP_TO_FLAG', '%d' % settings.REP_TO_FLAG)
+            line = line.replace('REP_TO_COMMENT', '%d' % settings.REP_TO_COMMENT)
+            line = line.replace('REP_TO_LIKE_COMMENT', '%d' % settings.REP_TO_LIKE_COMMENT)
+            line = line.replace('REP_TO_CLOSE_OWN', '%d' % settings.REP_TO_CLOSE_OWN)
+            line = line.replace('REP_TO_REOPEN_OWN', '%d' % settings.REP_TO_REOPEN_OWN)
+            line = line.replace('REP_TO_RETAG', '%d' % settings.REP_TO_RETAG)
+            line = line.replace('REP_TO_EDIT_WIKI', '%d' % settings.REP_TO_EDIT_WIKI)
+            line = line.replace('REP_TO_EDIT_OTHERS', '%d' % settings.REP_TO_EDIT_OTHERS)
+            line = line.replace('REP_TO_CLOSE_OTHERS', '%d' % settings.REP_TO_CLOSE_OTHERS)
+            line = line.replace('REP_TO_DELETE_COMMENTS', '%d' % settings.REP_TO_DELETE_COMMENTS)
+            line = line.replace('REP_TO_VIEW_FLAGS', '%d' % settings.REP_TO_VIEW_FLAGS)
+
+            new_lines.append(line)
+
+        return new_lines
+
+def makeSettingsExtension(configs={}) :
+    return MinRepExtension(configs=configs)
index 63ff65723c24c2fb05c24f2bd6ab0a3f5773d035..be41bd29530ea2702c7aedd3683d7edbcd220620 100644 (file)
@@ -12,6 +12,8 @@ from forum.models import Badge, Award, User
 from forum.badges import ALL_BADGES
 from forum import settings
 from forum.utils.mail import send_email
+from forum.settings.settingsmarkdown import *
+
 import re
 
 def favicon(request):
@@ -21,7 +23,10 @@ def about(request):
     return render_to_response('about.html', {'text': settings.ABOUT_PAGE_TEXT.value }, context_instance=RequestContext(request))
 
 def faq(request):
-    return render_to_response('faq.html', {'text': settings.FAQ_PAGE_TEXT.value }, context_instance=RequestContext(request))
+    md = markdown.Markdown([SettingsExtension({})])
+    text = md.convert(settings.FAQ_PAGE_TEXT.value)
+
+    return render_to_response('faq.html', {'text' : text}, context_instance=RequestContext(request))
 
 def feedback(request):
     if request.method == "POST":