Skip to content

Commit

Permalink
Merged FAQ and About into the same template, and added a special fold…
Browse files Browse the repository at this point in the history
…er 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
  • Loading branch information
hernani committed May 13, 2010
1 parent ea47e47 commit 9e75f1e
Show file tree
Hide file tree
Showing 11 changed files with 74 additions and 102 deletions.
Empty file added forum/markdownext/__init__.py
Empty file.
File renamed without changes.
46 changes: 46 additions & 0 deletions forum/markdownext/mdx_settingsparser.py
Original file line number Diff line number Diff line change
@@ -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)
16 changes: 8 additions & 8 deletions forum/settings/faq.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,14 +31,14 @@
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?**
Expand Down
53 changes: 0 additions & 53 deletions forum/settings/settingsmarkdown.py

This file was deleted.

15 changes: 0 additions & 15 deletions forum/skins/default/templates/about.html

This file was deleted.

15 changes: 0 additions & 15 deletions forum/skins/default/templates/faq.html

This file was deleted.

12 changes: 12 additions & 0 deletions forum/skins/default/templates/static.html
Original file line number Diff line number Diff line change
@@ -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 %}

4 changes: 4 additions & 0 deletions forum/startup.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down
4 changes: 2 additions & 2 deletions forum/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,8 @@
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'),
Expand Down
11 changes: 2 additions & 9 deletions forum/views/meta.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,8 @@
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))
Expand Down

0 comments on commit 9e75f1e

Please sign in to comment.