]> git.openstreetmap.org Git - osqa.git/commitdiff
Merged FAQ and About into the same template, and added a special folder markdownext...
authorhernani <hernani@0cfe37f9-358a-4d5e-be75-b63607b5c754>
Thu, 13 May 2010 18:24:03 +0000 (18:24 +0000)
committerhernani <hernani@0cfe37f9-358a-4d5e-be75-b63607b5c754>
Thu, 13 May 2010 18:24:03 +0000 (18:24 +0000)
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 [new file with mode: 0644]
forum/markdownext/mdx_limitedsyntax.py [moved from mdx_limitedsyntax.py with 100% similarity]
forum/markdownext/mdx_settingsparser.py [new file with mode: 0644]
forum/settings/faq.py
forum/settings/settingsmarkdown.py [deleted file]
forum/skins/default/templates/about.html [deleted file]
forum/skins/default/templates/faq.html [deleted file]
forum/skins/default/templates/static.html [new file with mode: 0644]
forum/startup.py
forum/urls.py
forum/views/meta.py

diff --git a/forum/markdownext/__init__.py b/forum/markdownext/__init__.py
new file mode 100644 (file)
index 0000000..e69de29
diff --git a/forum/markdownext/mdx_settingsparser.py b/forum/markdownext/mdx_settingsparser.py
new file mode 100644 (file)
index 0000000..9d0c69f
--- /dev/null
@@ -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
index c1741f27ef8b2096f4322f87d29594faeed4fe53..bae9d1163a1b05eed04a7da6b970f2c852e3a11b 100644 (file)
@@ -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.
 
 
 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?**
 
 
 **What is gravatar?**
 
diff --git a/forum/settings/settingsmarkdown.py b/forum/settings/settingsmarkdown.py
deleted file mode 100644 (file)
index 2c151bb..0000000
+++ /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 (file)
index f591d1a..0000000
+++ /dev/null
@@ -1,15 +0,0 @@
-{% extends "base_content.html" %}
-<!-- template about.html -->
-{% load i18n %}
-{% load markup %}
-{% block title %}{% spaceless %}{% trans "About" %}{% endspaceless %}{% endblock %}
-
-{% block content %}
-<div class="headNormal">
-{% trans "About" %}
-</div>
-<div class="content">
-{{ text|markdown }}
-</div>
-{% endblock %}
-<!-- end template about.html -->
diff --git a/forum/skins/default/templates/faq.html b/forum/skins/default/templates/faq.html
deleted file mode 100644 (file)
index 96f7a42..0000000
+++ /dev/null
@@ -1,15 +0,0 @@
-{% extends "base_content.html" %}
-<!-- template faq.html -->
-{% load i18n %}
-{% load markup %}
-{% block title %}{% spaceless %}{% trans "FAQ" %}{% endspaceless %}{% endblock %}
-
-{% block content %}
-<div class="headNormal">
-{% trans "FAQ" %}
-        </div>
-<div class="content">
-{{ text|markdown }}
-</div>
-{% endblock %}
-<!-- end template faq.html -->
diff --git a/forum/skins/default/templates/static.html b/forum/skins/default/templates/static.html
new file mode 100644 (file)
index 0000000..eff93ae
--- /dev/null
@@ -0,0 +1,12 @@
+{% extends "base_content.html" %}
+{% load i18n %}
+{% load markup %}
+{% block title %}{% spaceless %}{{ title }}{% endspaceless %}{% endblock %}
+
+{% block content %}
+<div class="headNormal">{{ title }}</div>
+<div class="content">
+{{ content|markdown:"settingsparser" }}
+</div>
+{% endblock %}
+
index d1388fa8524b038786f1a1596085a15984cc3042..5740b6a3e7233ce849f95e6e45f0562c43f03933 100644 (file)
@@ -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
 import forum.views
 
 import forum.badges
index 534bfcfde18f9b30a4041253bdc0221692ab6b96..71f414947d050227f3c2f936ac130fc9ce9648e2 100644 (file)
@@ -46,8 +46,8 @@ urlpatterns += patterns('',
         name='uploaded_file',
     ),
     #url(r'^%s/$' % _('signin/'), 'django_authopenid.views.signin', name='signin'),
         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'),
     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'),
index 04cfe753b933594e58c3ab932f1bafa23a700454..05bd2f4b8dbffdfc4f4014041c2c6cdee5a85a1c 100644 (file)
@@ -19,15 +19,8 @@ import re
 def favicon(request):
     return HttpResponseRedirect(str(settings.APP_FAVICON))
 
 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))
 
 def opensearch(request):   
     return render_to_response('opensearch.html', {'settings' : settings}, context_instance=RequestContext(request))