]> git.openstreetmap.org Git - osqa.git/commitdiff
Adds the habillity to opt for a rendering mode in the static content settings.
authorhernani <hernani@0cfe37f9-358a-4d5e-be75-b63607b5c754>
Wed, 10 Nov 2010 15:48:20 +0000 (15:48 +0000)
committerhernani <hernani@0cfe37f9-358a-4d5e-be75-b63607b5c754>
Wed, 10 Nov 2010 15:48:20 +0000 (15:48 +0000)
git-svn-id: http://svn.osqa.net/svnroot/osqa/trunk@617 0cfe37f9-358a-4d5e-be75-b63607b5c754

forum/settings/sidebar.py
forum/settings/static.py
forum/skins/default/templates/base_content.html
forum/skins/default/templates/header.html
forum/skins/default/templates/sidebar/user_blocks.html
forum/templatetags/extra_filters.py
forum/templatetags/general_sidebar_tags.py

index a2b3f231a7df14e9b97ebcd4328289054fd5104b..ee7529397b42dcea4c35538a7a8d3b6e44d0e11b 100644 (file)
@@ -1,7 +1,9 @@
 from base import Setting, SettingSet
-from django.forms.widgets import Textarea
+from django.forms.widgets import Textarea, Select
 from django.utils.translation import ugettext_lazy as _
 
+from static import RENDER_CHOICES
+
 SIDEBAR_SET = SettingSet('sidebar', 'Sidebar content', "Enter contents to display in the sidebar. You can use markdown and some basic html tags.", 10, True)
 
 SHOW_WELCOME_BOX = Setting('SHOW_WELCOME_BOX', True, SIDEBAR_SET, dict(
@@ -40,6 +42,12 @@ label = "Upper Block Content",
 help_text = " The upper sidebar block. ",
 widget=Textarea(attrs={'rows': '10'})))
 
+SIDEBAR_UPPER_RENDER_MODE = Setting('SIDEBAR_UPPER_RENDER_MODE', 'markdown', SIDEBAR_SET, dict(
+label = _("Upper block rendering mode"),
+help_text = _("How to render your upper block code."),
+widget=Select(choices=RENDER_CHOICES),
+required=False))
+
 
 SIDEBAR_LOWER_SHOW = Setting('SIDEBAR_LOWER_SHOW', True, SIDEBAR_SET, dict(
 label = "Show Lower Block",
@@ -61,4 +69,10 @@ are great resources to help you learn more about the OSQA open source Q&A system
 """, SIDEBAR_SET, dict(
 label = "Lower Block Content",
 help_text = " The lower sidebar block. ",
-widget=Textarea(attrs={'rows': '10'})))
\ No newline at end of file
+widget=Textarea(attrs={'rows': '10'})))
+
+SIDEBAR_LOWER_RENDER_MODE = Setting('SIDEBAR_LOWER_RENDER_MODE', 'markdown', SIDEBAR_SET, dict(
+label = _("Lower block rendering mode"),
+help_text = _("How to render your lower block code."),
+widget=Select(choices=RENDER_CHOICES),
+required=False))
\ No newline at end of file
index 97b595252769a6ccbc34b630bc8ba062bcdd564c..9eb5d39405a6d62fbcc80a29c7738a792de3e688 100644 (file)
@@ -1,7 +1,13 @@
 from base import Setting, SettingSet
-from django.forms.widgets import Textarea, RadioSelect
+from django.forms.widgets import Textarea, RadioSelect, Select
 from django.utils.translation import ugettext_lazy as _
 
+RENDER_CHOICES = (
+('markdown', _('Markdown')),
+('html', _('HTML')),
+('escape', _('Escaped'))
+)
+
 STATIC_PAGE_REGISTRY = Setting('STATIC_PAGE_REGISTRY', {})
 
 CSS_SET = SettingSet('css', 'Custom CSS', "Define some custom css you can use to override the default css.", 2000,
@@ -32,6 +38,12 @@ CUSTOM_HEADER = Setting('CUSTOM_HEADER', '', HEAD_AND_FOOT_SET, dict(
         widget=Textarea(attrs={'rows': '25'}),
         required=False))
 
+CUSTOM_HEADER_RENDER_MODE = Setting('CUSTOM_HEADER_RENDER_MODE', 'markdown', HEAD_AND_FOOT_SET, dict(
+        label = _("Custom Header rendering mode"),
+        help_text = _("How to render your custom header code."),
+        widget=Select(choices=RENDER_CHOICES),
+        required=False))
+
 USE_ANNOUNCEMENT_BAR = Setting('USE_ANNOUNCEMENT_BAR', False, HEAD_AND_FOOT_SET, dict(
         label = _("Show announcement bar"),
         help_text = _("Some piece of content that goes under the search bar and can be used for announcements, etc."),
@@ -43,6 +55,12 @@ ANNOUNCEMENT_BAR = Setting('ANNOUNCEMENT_BAR', '', HEAD_AND_FOOT_SET, dict(
         widget=Textarea(attrs={'rows': '25'}),
         required=False))
 
+ANNOUNCEMENT_BAR_RENDER_MODE = Setting('ANNOUNCEMENT_BAR_RENDER_MODE', 'markdown', HEAD_AND_FOOT_SET, dict(
+        label = _("Announcement bar rendering mode"),
+        help_text = _("How to render your announcement bar code."),
+        widget=Select(choices=RENDER_CHOICES),
+        required=False))
+
 USE_CUSTOM_FOOTER = Setting('USE_CUSTOM_FOOTER', False, HEAD_AND_FOOT_SET, dict(
         label = _("Use custom footer"),
         help_text = _("Do you want to use a custom footer."),
@@ -54,6 +72,12 @@ CUSTOM_FOOTER = Setting('CUSTOM_FOOTER', '', HEAD_AND_FOOT_SET, dict(
         widget=Textarea(attrs={'rows': '25'}),
         required=False))
 
+CUSTOM_FOOTER_RENDER_MODE = Setting('CUSTOM_FOOTER_RENDER_MODE', 'markdown', HEAD_AND_FOOT_SET, dict(
+        label = _("Custom footer rendering mode"),
+        help_text = _("How to render your custom footer code."),
+        widget=Select(choices=RENDER_CHOICES),
+        required=False))
+
 CUSTOM_FOOTER_MODE_CHOICES = (
 ('replace', _('Replace default footer')),
 ('above', _('Above default footer')),
index 76eec6e2923469d760ee99fe02cb9b76812cdb45..0fbcc5d0c386b2d39a34a77505899d09be298f1b 100644 (file)
@@ -56,7 +56,7 @@
         </script>
         {% endif %}
         {% if settings.USE_CUSTOM_HEAD|or_preview:request %}
-            {{ settings.CUSTOM_HEAD|or_preview:request|markdown:"settingsparser" }}
+            {{ settings.CUSTOM_HEAD|or_preview:request|safe }}
         {% endif %}
         {% block forejs %}{% endblock %}
         <link rel="search" type="application/opensearchdescription+xml" href="{% url opensearch %}" title="{{ settings.APP_SHORT_NAME }} Search" />
@@ -75,7 +75,7 @@
         </div>
         {% if settings.USE_CUSTOM_HEADER|or_preview:request %}
             <div id="custom_header">
-                {{ settings.CUSTOM_HEADER|or_preview:request|safe }}
+                {{ settings.CUSTOM_HEADER|or_preview:request|static_content:settings.CUSTOM_HEADER_RENDER_MODE }}
             </div>
         {% endif %}
         {% include "header.html" %}
         {% if settings.USE_CUSTOM_FOOTER|or_preview:request %}
             {% ifequal settings.CUSTOM_FOOTER_MODE|or_preview:request "above" %}
                 <div id="custom_footer">
-                    {{ settings.CUSTOM_FOOTER|or_preview:request|markdown:"settingsparser" }}
+                    {{ settings.CUSTOM_FOOTER|or_preview:request|static_content:settings.CUSTOM_FOOTER_RENDER_MODE }}
                 </div>
             {% endifequal %}
             <div id="ground">
                 {% ifequal settings.CUSTOM_FOOTER_MODE|or_preview:request "replace" %}
-                    {{ settings.CUSTOM_FOOTER|or_preview:request|markdown:"settingsparser" }}
+                    {{ settings.CUSTOM_FOOTER|or_preview:request|static_content:settings.CUSTOM_FOOTER_RENDER_MODE }}
                 {% else %}
                     {% include "footer.html" %}
                 {% endifequal %}
             </div>
             {% ifequal settings.CUSTOM_FOOTER_MODE|or_preview:request "below" %}
                 <div id="custom_footer">
-                    {{ settings.CUSTOM_FOOTER|or_preview:request|markdown:"settingsparser" }}
+                    {{ settings.CUSTOM_FOOTER|or_preview:request|static_content:settings.CUSTOM_FOOTER_RENDER_MODE }}
                 </div>
             {% endifequal %}
         {% else %}
index 7afaffc2e682ccdb100a11cd33f0c585e7fb155e..0e2d28c6c2d36014f0aafd98be7519b516503249 100644 (file)
@@ -40,7 +40,7 @@
 
        {% if settings.USE_ANNOUNCEMENT_BAR|or_preview:request %}
   <div id="announcement">
-      {{ settings.ANNOUNCEMENT_BAR|or_preview:request|markdown:"settingsparser" }}
+      {{ settings.ANNOUNCEMENT_BAR|or_preview:request|static_content:settings.ANNOUNCEMENT_BAR_RENDER_MODE }}
   </div>
   {% endif %}
 
index 9bf843cb01ebf1970e14a4b7d267f8ff3a6e2d87..d3d98cc27ac925ea2e1fccde5dbbf0bb721dc598 100644 (file)
@@ -3,7 +3,7 @@
 {% if show %}
 {% if wrap %}<div id="{{ blockid }}" class="boxC">
     <div class="body">{% endif %}
-        {{ content|markdown }}
+        {{ content }}
      {% if wrap %}</div>
 </div>{% endif %}
 {% endif %}
index 590f5550012cfd23bddb48773b9d7e6552d9da00..b9fb4b350905eddfe0d62beb4e8c351164513d91 100644 (file)
@@ -1,6 +1,7 @@
 from django import template
 from django.utils.safestring import mark_safe
 import logging
+import markdown
 
 register = template.Library()
 
@@ -46,4 +47,13 @@ def getval(map, key):
 
 @register.filter
 def contained_in(item, container):
-    return item in container
\ No newline at end of file
+    return item in container
+
+@register.filter
+def static_content(content, render_mode):
+    if render_mode == 'markdown':
+        return mark_safe(markdown.markdown(unicode(content), ["settingsparser"]))
+    elif render_mode == "html":
+        return mark_safe(unicode(content))
+    else:
+        return unicode(content)
\ No newline at end of file
index 4493f329110d3e0118bb09b9f6edfda22f6e30c8..2f70fa2c62fa2b31dde5137646dde20bfcd7f232 100644 (file)
@@ -2,6 +2,8 @@ from django import template
 from forum.models import Tag, Award\r
 from forum import settings\r
 \r
+from extra_filters import static_content\r
+\r
 register = template.Library()\r
 \r
 @register.inclusion_tag('sidebar/markdown_help.html')\r
@@ -16,7 +18,7 @@ def recent_awards():
 def sidebar_upper():\r
     return {\r
         'show': settings.SIDEBAR_UPPER_SHOW,\r
-        'content': settings.SIDEBAR_UPPER_TEXT,\r
+        'content': static_content(settings.SIDEBAR_UPPER_TEXT, settings.SIDEBAR_UPPER_RENDER_MODE),\r
         'wrap': not settings.SIDEBAR_UPPER_DONT_WRAP,\r
         'blockid': 'sidebar-upper'\r
     }\r
@@ -25,7 +27,7 @@ def sidebar_upper():
 def sidebar_lower():\r
     return {\r
         'show': settings.SIDEBAR_LOWER_SHOW,\r
-        'content': settings.SIDEBAR_LOWER_TEXT,\r
+        'content': static_content(settings.SIDEBAR_LOWER_TEXT, settings.SIDEBAR_LOWER_RENDER_MODE),\r
         'wrap': not settings.SIDEBAR_LOWER_DONT_WRAP,\r
         'blockid': 'sidebar-lower'\r
     }\r