From 5d33b325a606240f9bcc7d704de1af0152c9bd19 Mon Sep 17 00:00:00 2001 From: qw3rty Date: Tue, 4 May 2010 17:07:48 +0000 Subject: [PATCH] It is now possable for users to add tags like "REP_TO_VOTE_UP" to the faq page and they will display the value in settings they are ment to represent. git-svn-id: http://svn.osqa.net/svnroot/osqa/trunk@125 0cfe37f9-358a-4d5e-be75-b63607b5c754 --- forum/settings/settingsmarkdown.py | 52 ++++++++++++++++++++++++++++++ forum/views/meta.py | 7 +++- 2 files changed, 58 insertions(+), 1 deletion(-) create mode 100644 forum/settings/settingsmarkdown.py diff --git a/forum/settings/settingsmarkdown.py b/forum/settings/settingsmarkdown.py new file mode 100644 index 0000000..b4d47d4 --- /dev/null +++ b/forum/settings/settingsmarkdown.py @@ -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) diff --git a/forum/views/meta.py b/forum/views/meta.py index 63ff657..be41bd2 100644 --- a/forum/views/meta.py +++ b/forum/views/meta.py @@ -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": -- 2.39.5