From 9e75f1e87c62bdfeba60549f96caf7658c6d1603 Mon Sep 17 00:00:00 2001 From: hernani Date: Thu, 13 May 2010 18:24:03 +0000 Subject: [PATCH 1/1] Merged FAQ and About into the same template, and added a special folder markdownext which gets added to the path dinamically so we can put normal markdown extensions there. Made the settings markdown parser abble to parse any setting. git-svn-id: http://svn.osqa.net/svnroot/osqa/trunk@263 0cfe37f9-358a-4d5e-be75-b63607b5c754 --- forum/markdownext/__init__.py | 0 .../markdownext/mdx_limitedsyntax.py | 0 forum/markdownext/mdx_settingsparser.py | 46 ++++++++++++++++ forum/settings/faq.py | 16 +++--- forum/settings/settingsmarkdown.py | 53 ------------------- forum/skins/default/templates/about.html | 15 ------ forum/skins/default/templates/faq.html | 15 ------ forum/skins/default/templates/static.html | 12 +++++ forum/startup.py | 4 ++ forum/urls.py | 4 +- forum/views/meta.py | 11 +--- 11 files changed, 74 insertions(+), 102 deletions(-) create mode 100644 forum/markdownext/__init__.py rename mdx_limitedsyntax.py => forum/markdownext/mdx_limitedsyntax.py (100%) create mode 100644 forum/markdownext/mdx_settingsparser.py delete mode 100644 forum/settings/settingsmarkdown.py delete mode 100644 forum/skins/default/templates/about.html delete mode 100644 forum/skins/default/templates/faq.html create mode 100644 forum/skins/default/templates/static.html diff --git a/forum/markdownext/__init__.py b/forum/markdownext/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/mdx_limitedsyntax.py b/forum/markdownext/mdx_limitedsyntax.py similarity index 100% rename from mdx_limitedsyntax.py rename to forum/markdownext/mdx_limitedsyntax.py diff --git a/forum/markdownext/mdx_settingsparser.py b/forum/markdownext/mdx_settingsparser.py new file mode 100644 index 0000000..9d0c69f --- /dev/null +++ b/forum/markdownext/mdx_settingsparser.py @@ -0,0 +1,46 @@ +from os import linesep +from csv import reader, QUOTE_NONE +import markdown +from markdown import Extension +from markdown.preprocessors import Preprocessor +import re + +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') + +SETTING_RE = re.compile(r'\|[A-Z_]+\|') + +def setting_rep_callback(m): + setting_name = m.group(0).strip('|') + if hasattr(settings, setting_name): + return unicode(getattr(settings, setting_name)) + else: + return '' + + +class SettingsPre(Preprocessor): + def run(self, lines): + new_lines = [] + for line in lines: + new_lines.append(SETTING_RE.sub(setting_rep_callback, line)) + + return new_lines + + +def makeExtension(configs=None) : + return SettingsExtension(configs=configs) \ No newline at end of file diff --git a/forum/settings/faq.py b/forum/settings/faq.py index c1741f2..bae9d11 100644 --- a/forum/settings/faq.py +++ b/forum/settings/faq.py @@ -31,14 +31,14 @@ When a question or answer is upvoted, the user who posted them will gain some po For example, if you ask an interesting question or give a helpful answer, your input will be upvoted. On the other hand if the answer is misleading - it will be downvoted. Each vote in favor will generate 10 points, each vote against will subtract 2 points. There is a limit of 200 points that can be accumulated per question or answer. The table below explains reputation point requirements for each type of moderation task. -* add comments -> REP_TO_COMMENT -* delete comments -> REP_TO_DELETE_COMMENTS -* close own questions -> REP_TO_CLOSE_OWN -* reopen own questions -> REP_TO_REOPEN_OWN -* retag questions -> REP_TO_RETAG -* edit any answer -> REP_TO_EDIT_OTHERS -* open any closed question -> REP_TO_CLOSE_OTHERS -* delete any comment -> REP_TO_DELETE_COMMENTS +* add comments -> |REP_TO_COMMENT| +* delete comments -> |REP_TO_DELETE_COMMENTS| +* close own questions -> |REP_TO_CLOSE_OWN| +* reopen own questions -> |REP_TO_REOPEN_OWN| +* retag questions -> |REP_TO_RETAG| +* edit any answer -> |REP_TO_EDIT_OTHERS| +* open any closed question -> |REP_TO_CLOSE_OTHERS| +* delete any comment -> |REP_TO_DELETE_COMMENTS| **What is gravatar?** diff --git a/forum/settings/settingsmarkdown.py b/forum/settings/settingsmarkdown.py deleted file mode 100644 index 2c151bb..0000000 --- a/forum/settings/settingsmarkdown.py +++ /dev/null @@ -1,53 +0,0 @@ -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) - line = line.replace('REP_TO_UPLOAD', '%d' % settings.REP_TO_UPLOAD) - - new_lines.append(line) - - return new_lines - -def makeSettingsExtension(configs={}) : - return MinRepExtension(configs=configs) diff --git a/forum/skins/default/templates/about.html b/forum/skins/default/templates/about.html deleted file mode 100644 index f591d1a..0000000 --- a/forum/skins/default/templates/about.html +++ /dev/null @@ -1,15 +0,0 @@ -{% extends "base_content.html" %} - -{% load i18n %} -{% load markup %} -{% block title %}{% spaceless %}{% trans "About" %}{% endspaceless %}{% endblock %} - -{% block content %} -
-{% trans "About" %} -
-
-{{ text|markdown }} -
-{% endblock %} - diff --git a/forum/skins/default/templates/faq.html b/forum/skins/default/templates/faq.html deleted file mode 100644 index 96f7a42..0000000 --- a/forum/skins/default/templates/faq.html +++ /dev/null @@ -1,15 +0,0 @@ -{% extends "base_content.html" %} - -{% load i18n %} -{% load markup %} -{% block title %}{% spaceless %}{% trans "FAQ" %}{% endspaceless %}{% endblock %} - -{% block content %} -
-{% trans "FAQ" %} -
-
-{{ text|markdown }} -
-{% endblock %} - diff --git a/forum/skins/default/templates/static.html b/forum/skins/default/templates/static.html new file mode 100644 index 0000000..eff93ae --- /dev/null +++ b/forum/skins/default/templates/static.html @@ -0,0 +1,12 @@ +{% extends "base_content.html" %} +{% load i18n %} +{% load markup %} +{% block title %}{% spaceless %}{{ title }}{% endspaceless %}{% endblock %} + +{% block content %} +
{{ title }}
+
+{{ content|markdown:"settingsparser" }} +
+{% endblock %} + diff --git a/forum/startup.py b/forum/startup.py index d1388fa..5740b6a 100644 --- a/forum/startup.py +++ b/forum/startup.py @@ -1,3 +1,7 @@ +import sys +import os +sys.path.append(os.path.join(os.path.dirname(__file__),'markdownext')) + import forum.views import forum.badges diff --git a/forum/urls.py b/forum/urls.py index 534bfcf..71f4149 100644 --- a/forum/urls.py +++ b/forum/urls.py @@ -46,8 +46,8 @@ urlpatterns += patterns('', name='uploaded_file', ), #url(r'^%s/$' % _('signin/'), 'django_authopenid.views.signin', name='signin'), - url(r'^%s$' % _('about/'), app.meta.about, name='about'), - url(r'^%s$' % _('faq/'), app.meta.faq, name='faq'), + url(r'^%s$' % _('faq/'), app.meta.static, {'content': settings.FAQ_PAGE_TEXT, 'title': _('FAQ')}, name='faq'), + url(r'^%s$' % _('about/'), app.meta.static, {'content': settings.ABOUT_PAGE_TEXT, 'title': _('About')}, name='about'), url(r'^opensearch\.xml$', app.meta.opensearch, name='opensearch'), url(r'^%s$' % _('privacy/'), app.meta.privacy, name='privacy'), url(r'^%s$' % _('logout/'), app.meta.logout, name='logout'), diff --git a/forum/views/meta.py b/forum/views/meta.py index 04cfe75..05bd2f4 100644 --- a/forum/views/meta.py +++ b/forum/views/meta.py @@ -19,15 +19,8 @@ import re def favicon(request): return HttpResponseRedirect(str(settings.APP_FAVICON)) -def about(request): - return render_to_response('about.html', {'text': settings.ABOUT_PAGE_TEXT.value }, context_instance=RequestContext(request)) - -def faq(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 static(request, title, content): + return render_to_response('static.html', {'content' : content, 'title': title}, context_instance=RequestContext(request)) def opensearch(request): return render_to_response('opensearch.html', {'settings' : settings}, context_instance=RequestContext(request)) -- 2.39.5