]> git.openstreetmap.org Git - osqa.git/commitdiff
Adds custom <head> elements and mimetype to the custom pages.
authorhernani <hernani@0cfe37f9-358a-4d5e-be75-b63607b5c754>
Mon, 7 Jun 2010 14:54:41 +0000 (14:54 +0000)
committerhernani <hernani@0cfe37f9-358a-4d5e-be75-b63607b5c754>
Mon, 7 Jun 2010 14:54:41 +0000 (14:54 +0000)
git-svn-id: http://svn.osqa.net/svnroot/osqa/trunk@385 0cfe37f9-358a-4d5e-be75-b63607b5c754

forum/forms/admin.py
forum/settings/static.py
forum/skins/default/templates/base_content.html
forum/skins/default/templates/osqaadmin/djstyle_base.html
forum/views/admin.py
forum/views/meta.py

index eabeb5743aef6fc9084854a038f7298ceaaf57c2..791f5ec7e50de12859588c9bdaa0dd8e522411cc 100644 (file)
@@ -37,30 +37,30 @@ class MaintenanceModeForm(forms.Form):
 
 
 TEMPLATE_CHOICES = (
-    ('default', _('Default')),
-    ('sidebar', _('Default with sidebar')),
-    ('none', _('None')),
+('default', _('Default')),
+('sidebar', _('Default with sidebar')),
+('none', _('None')),
 )
 
 RENDER_CHOICES = (
-    ('markdown', _('Markdown')),
-    ('html', _('HTML')),
-    ('escape', _('Escaped'))
+('markdown', _('Markdown')),
+('html', _('HTML')),
+('escape', _('Escaped'))
 )
 
 class UrlFieldWidget(forms.TextInput):
     def render(self, name, value, attrs=None):
         if not value:
             value = ''
-            
+
         return """
                 <input class="url_field" type="text" name="%(name)s" value="%(value)s" />
                 <a class="url_field_anchor" target="_blank" href="%(app_url)s%(script_alias)s"></a>
-            """  % {'name': name, 'value': value, 'app_url': settings.APP_URL, 'script_alias': settings.FORUM_SCRIPT_ALIAS}
+            """  % {'name': name, 'value': value, 'app_url': settings.APP_URL,
+                    'script_alias': settings.FORUM_SCRIPT_ALIAS}
 
 
 class PageForm(forms.Form):
-
     def __init__(self, page, *args, **kwargs):
         if page:
             initial = page.extra
@@ -70,16 +70,22 @@ class PageForm(forms.Form):
             super(PageForm, self).__init__(*args, **kwargs)
 
 
-    title  = forms.CharField(label=_('Title'), max_length=255, widget=forms.TextInput(attrs={'class': 'longstring'}), initial='New page')
+    title  = forms.CharField(label=_('Title'), max_length=255, widget=forms.TextInput(attrs={'class': 'longstring'}),
+                             initial='New page')
     path  = forms.CharField(label=_('Page URL'), widget=UrlFieldWidget, initial='pages/new/')
 
     content = forms.CharField(label=_('Page Content'), widget=forms.Textarea(attrs={'rows': 30}))
-    render = forms.ChoiceField(widget=forms.RadioSelect, choices=RENDER_CHOICES, initial='markdown', label=_('Render Mode'))
+    mimetype = forms.CharField(label=_('Mime Type'), initial='text/html')
+
+    render = forms.ChoiceField(widget=forms.RadioSelect, choices=RENDER_CHOICES, initial='markdown',
+                               label=_('Render Mode'))
 
-    template = forms.ChoiceField(widget=forms.RadioSelect, choices=TEMPLATE_CHOICES, initial='default', label=_('Template'))
+    template = forms.ChoiceField(widget=forms.RadioSelect, choices=TEMPLATE_CHOICES, initial='default',
+                                 label=_('Template'))
     sidebar = forms.CharField(label=_('Sidebar Content'), widget=forms.Textarea(attrs={'rows': 20}), required=False)
-    sidebar_wrap = forms.BooleanField(label=_("Wrap sidebar block"), initial=True, required=False) 
-    sidebar_render = forms.ChoiceField(widget=forms.RadioSelect, choices=RENDER_CHOICES, initial='markdown', label=_('Sidebar Render Mode'))
+    sidebar_wrap = forms.BooleanField(label=_("Wrap sidebar block"), initial=True, required=False)
+    sidebar_render = forms.ChoiceField(widget=forms.RadioSelect, choices=RENDER_CHOICES, initial='markdown',
+                                       label=_('Sidebar Render Mode'))
 
     comments = forms.BooleanField(label=_("Allow comments"), initial=False, required=False)
 
index 3cc7602c86bf7016d915f7ec548622e69a5ff20b..4d6fb8ca0b1eb673f4c86d592913704259a71725 100644 (file)
@@ -4,53 +4,68 @@ from django.utils.translation import ugettext_lazy as _
 
 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, can_preview=True)
+CSS_SET = SettingSet('css', 'Custom CSS', "Define some custom css you can use to override the default css.", 2000,
+                     can_preview=True)
 
 USE_CUSTOM_CSS = Setting('USE_CUSTOM_CSS', False, CSS_SET, dict(
-label = _("Use custom CSS"),
-help_text = _("Do you want to use custom CSS."),
-required=False))
+        label = _("Use custom CSS"),
+        help_text = _("Do you want to use custom CSS."),
+        required=False))
 
 CUSTOM_CSS = Setting('CUSTOM_CSS', '', CSS_SET, dict(
-label = _("Custom CSS"),
-help_text = _("Your custom CSS."),
-widget=Textarea(attrs={'rows': '25'}),
-required=False))
+        label = _("Custom CSS"),
+        help_text = _("Your custom CSS."),
+        widget=Textarea(attrs={'rows': '25'}),
+        required=False))
 
-
-HEAD_AND_FOOT_SET = SettingSet('headandfoot', 'Header and Footer', "Adds a custom header and/or footer to your page", 2000, can_preview=True)
+HEAD_AND_FOOT_SET = SettingSet('headandfoot', 'Header and Footer', "Adds a custom header and/or footer to your page",
+                               2000, can_preview=True)
 
 USE_CUSTOM_HEADER = Setting('USE_CUSTOM_HEADER', False, HEAD_AND_FOOT_SET, dict(
-label = _("Use custom header"),
-help_text = _("Do you want to use a custom header."),
-required=False))
+        label = _("Use custom header"),
+        help_text = _("Do you want to use a custom header."),
+        required=False))
 
 CUSTOM_HEADER = Setting('CUSTOM_HEADER', '', HEAD_AND_FOOT_SET, dict(
-label = _("Custom Header"),
-help_text = _("Your custom header."),
-widget=Textarea(attrs={'rows': '25'}),
-required=False))
+        label = _("Custom Header"),
+        help_text = _("Your custom header."),
+        widget=Textarea(attrs={'rows': '25'}),
+        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."),
-required=False))
+        label = _("Use custom footer"),
+        help_text = _("Do you want to use a custom footer."),
+        required=False))
 
 CUSTOM_FOOTER = Setting('CUSTOM_FOOTER', '', HEAD_AND_FOOT_SET, dict(
-label = _("Custom Footer"),
-help_text = _("Your custom footer."),
-widget=Textarea(attrs={'rows': '25'}),
-required=False))
+        label = _("Custom Footer"),
+        help_text = _("Your custom footer."),
+        widget=Textarea(attrs={'rows': '25'}),
+        required=False))
 
 CUSTOM_FOOTER_MODE_CHOICES = (
-    ('replace', _('Replace default footer')),
-    ('above', _('Above default footer')),
-    ('below', _('Below default footer')),
+('replace', _('Replace default footer')),
+('above', _('Above default footer')),
+('below', _('Below default footer')),
 )
 
 CUSTOM_FOOTER_MODE = Setting('CUSTOM_FOOTER_MODE', 'replace', HEAD_AND_FOOT_SET, dict(
-label = _("Custom Footer Mode"),
-help_text = _("How your custom footer will appear."),
-widget=RadioSelect,
-choices=CUSTOM_FOOTER_MODE_CHOICES,
-required=False))
\ No newline at end of file
+        label = _("Custom Footer Mode"),
+        help_text = _("How your custom footer will appear."),
+        widget=RadioSelect,
+        choices=CUSTOM_FOOTER_MODE_CHOICES,
+        required=False))
+
+HEAD_SET = SettingSet('head', '<head>', "Define some custom elements to include in the head section of every page.",
+                      2000, can_preview=True)
+
+USE_CUSTOM_HEAD = Setting('USE_CUSTOM_HEAD', False, HEAD_SET, dict(
+        label = _("Use custom Head elements"),
+        help_text = _("Do you want to use custom head elements."),
+        required=False))
+
+CUSTOM_HEAD = Setting('CUSTOM_HEAD', '', HEAD_SET, dict(
+        label = _("Custom Head"),
+        help_text = _("Your custom Head elements."),
+        widget=Textarea(attrs={'rows': '25'}),
+        required=False))
\ No newline at end of file
index 79c85dc4282340609a537908f43edec2e22fa4cf..4f0aa301524da663875aa67bf236c8f0ac814dfa 100644 (file)
@@ -50,6 +50,9 @@
             });
         </script>
         {% endif %}
+        {% if settings.USE_CUSTOM_HEAD|or_preview:request %}
+            {{ 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" />
     </head>
index 2ddbcbf3c41d2c7a13a11ef7c4a97245147bcf20..3f09125bc3f9ae8649ca06574b31ae9482999d8c 100644 (file)
                             <a href="{% url admin_set allsets.headandfoot.name %}">{{ allsets.headandfoot.title }}</a>
                             {% if "headandfoot" in unsaved %}<img width="12" height="12" src="{{ settings.ADMIN_MEDIA_PREFIX }}img/admin/icon_alert.gif" alt="{% trans "Unsaved changes" %}" />{% endif %}
                         </li>
+                        <li>
+                            <a href="{% url admin_set allsets.head.name %}">{{ allsets.head.title }}</a>
+                            {% if "head" in unsaved %}<img width="12" height="12" src="{{ settings.ADMIN_MEDIA_PREFIX }}img/admin/icon_alert.gif" alt="{% trans "Unsaved changes" %}" />{% endif %}
+                        </li>
                     </ul>
                 </div>
                 <div id="other-sets-menu" class="module">
index ddb4852b060c16dbaa53037fc327fafafce2110a..fe2782538df2c85e4d37b07fd4424b1bd7556410 100644 (file)
@@ -36,13 +36,12 @@ def admin_page(fn):
             context['othersets'] = sorted(
                     [s for s in Setting.sets.values() if not s.name in
                     ('basic', 'users', 'email', 'paths', 'extkeys', 'repgain', 'minrep', 'voting', 'badges', 'about', 'faq', 'sidebar',
-                    'form', 'moderation', 'css', 'headandfoot')]
+                    'form', 'moderation', 'css', 'headandfoot', 'head')]
                     , lambda s1, s2: s1.weight - s2.weight)
 
             unsaved = request.session.get('previewing_settings', {})
             context['unsaved'] = set([getattr(settings, s).set.name for s in unsaved.keys() if hasattr(settings, s)])
 
-
             return render_to_response(template, context, context_instance=RequestContext(request))
         else:
             return res
@@ -52,10 +51,10 @@ def admin_page(fn):
 @admin_page
 def dashboard(request):
     return ('osqaadmin/dashboard.html', {
-        'settings_pack': unicode(settings.SETTINGS_PACK),
-        'statistics': get_statistics(),
-        'recent_activity': get_recent_activity(),
-        'flagged_posts': get_flagged_posts(),
+    'settings_pack': unicode(settings.SETTINGS_PACK),
+    'statistics': get_statistics(),
+    'recent_activity': get_recent_activity(),
+    'flagged_posts': get_flagged_posts(),
     })
 
 @super_user_required
@@ -71,36 +70,37 @@ def statistics(request):
     last_month = today - timedelta(days=30)
 
     last_month_questions = Question.objects.filter_state(deleted=False).filter(added_at__gt=last_month
-                                                  ).order_by('added_at').values_list('added_at', flat=True)
+                                                                               ).order_by('added_at').values_list(
+            'added_at', flat=True)
 
     last_month_n_questions = Question.objects.filter_state(deleted=False).filter(added_at__lt=last_month).count()
     qgraph_data = simplejson.dumps([
-            (time.mktime(d.timetuple()) * 1000, i + last_month_n_questions)
-            for i, d in enumerate(last_month_questions)
+    (time.mktime(d.timetuple()) * 1000, i + last_month_n_questions)
+    for i, d in enumerate(last_month_questions)
     ])
 
     last_month_users = User.objects.filter(date_joined__gt=last_month
-                                                  ).order_by('date_joined').values_list('date_joined', flat=True)
+                                           ).order_by('date_joined').values_list('date_joined', flat=True)
 
     last_month_n_users = User.objects.filter(date_joined__lt=last_month).count()
 
     ugraph_data = simplejson.dumps([
-            (time.mktime(d.timetuple()) * 1000, i + last_month_n_users)
-            for i, d in enumerate(last_month_users)
+    (time.mktime(d.timetuple()) * 1000, i + last_month_n_users)
+    for i, d in enumerate(last_month_users)
     ])
 
     return 'osqaadmin/statistics.html', {
-        'graphs': [
+    'graphs': [
             {
-                'id': 'questions_graph',
-                'caption': _("Questions Graph"),
-                'data': qgraph_data
-            },{
-                'id': 'userss_graph',
-                'caption': _("Users Graph"),
-                'data': ugraph_data
+            'id': 'questions_graph',
+            'caption': _("Questions Graph"),
+            'data': qgraph_data
+            }, {
+            'id': 'userss_graph',
+            'caption': _("Users Graph"),
+            'data': ugraph_data
             }
-        ]
+            ]
     }
 
 
@@ -139,8 +139,8 @@ def settings_set(request, set_name):
         form = SettingsSetForm(set, unsaved=current_preview)
 
     return 'osqaadmin/set.html', {
-        'form': form,
-        'markdown': set.markdown,
+    'form': form,
+    'markdown': set.markdown,
     }
 
 @super_user_required
@@ -167,17 +167,19 @@ def get_flagged_posts():
 
 def get_statistics():
     return {
-        'total_users': User.objects.all().count(),
-        'users_last_24': User.objects.filter(date_joined__gt=(datetime.now() - timedelta(days=1))).count(),
-        'total_questions': Question.objects.filter_state(deleted=False).count(),
-        'questions_last_24': Question.objects.filter_state(deleted=False).filter(added_at__gt=(datetime.now() - timedelta(days=1))).count(),
-        'total_answers': Answer.objects.filter_state(deleted=False).count(),
-        'answers_last_24': Answer.objects.filter_state(deleted=False).filter(added_at__gt=(datetime.now() - timedelta(days=1))).count(),
+    'total_users': User.objects.all().count(),
+    'users_last_24': User.objects.filter(date_joined__gt=(datetime.now() - timedelta(days=1))).count(),
+    'total_questions': Question.objects.filter_state(deleted=False).count(),
+    'questions_last_24': Question.objects.filter_state(deleted=False).filter(
+            added_at__gt=(datetime.now() - timedelta(days=1))).count(),
+    'total_answers': Answer.objects.filter_state(deleted=False).count(),
+    'answers_last_24': Answer.objects.filter_state(deleted=False).filter(
+            added_at__gt=(datetime.now() - timedelta(days=1))).count(),
     }
 
 @super_user_required
 def go_bootstrap(request):
-    #todo: this is the quick and dirty way of implementing a bootstrap mode
+#todo: this is the quick and dirty way of implementing a bootstrap mode
     try:
         from forum_modules.default_badges import settings as dbsets
         dbsets.POPULAR_QUESTION_VIEWS.set_value(100)
@@ -275,8 +277,8 @@ def maintenance(request):
 
             if form.is_valid():
                 settings.MAINTAINANCE_MODE.set_value({
-                    'allow_ips': form.cleaned_data['ips'],
-                    'message': form.cleaned_data['message']})
+                'allow_ips': form.cleaned_data['ips'],
+                'message': form.cleaned_data['message']})
 
                 if 'close' in request.POST:
                     message = _('Maintenance mode enabled')
@@ -294,13 +296,14 @@ def maintenance(request):
         form = MaintenanceModeForm(initial={'ips': request.META['REMOTE_ADDR'],
                                             'message': _('Currently down for maintenance. We\'ll be back soon')})
 
-    return ('osqaadmin/maintenance.html', {'form': form, 'in_maintenance': settings.MAINTAINANCE_MODE.value is not None})
+    return ('osqaadmin/maintenance.html', {'form': form, 'in_maintenance': settings.MAINTAINANCE_MODE.value is not None
+                                           })
 
 
 @admin_page
 def flagged_posts(request):
     return ('osqaadmin/flagged_posts.html', {
-        'flagged_posts': get_flagged_posts(),
+    'flagged_posts': get_flagged_posts(),
     })
 
 @admin_page
@@ -308,7 +311,7 @@ def static_pages(request):
     pages = Page.objects.all()
 
     return ('osqaadmin/static_pages.html', {
-        'pages': pages,
+    'pages': pages,
     })
 
 @admin_page
@@ -324,9 +327,11 @@ def edit_page(request, id=None):
         if form.is_valid():
             if form.has_changed():
                 if not page:
-                    page = NewPageAction(user=request.user, ip=request.META['REMOTE_ADDR']).save(data=form.cleaned_data).node
+                    page = NewPageAction(user=request.user, ip=request.META['REMOTE_ADDR']).save(data=form.cleaned_data
+                                                                                                 ).node
                 else:
-                    EditPageAction(user=request.user, node=page, ip=request.META['REMOTE_ADDR']).save(data=form.cleaned_data)
+                    EditPageAction(user=request.user, node=page, ip=request.META['REMOTE_ADDR']).save(
+                            data=form.cleaned_data)
 
             if ('publish' in request.POST) and (not page.published):
                 PublishAction(user=request.user, node=page, ip=request.META['REMOTE_ADDR']).save()
@@ -344,9 +349,9 @@ def edit_page(request, id=None):
         published = False
 
     return ('osqaadmin/edit_page.html', {
-        'page': page,
-        'form': form,
-        'published': published
+    'page': page,
+    'form': form,
+    'published': published
     })
 
 
index 105bec7a98274c79adc04c2c5e0f1ab735abcdae..932c627a123d6b9637707395ccd3a6a86b96468a 100644 (file)
@@ -26,19 +26,20 @@ def custom_css(request):
     return HttpResponse(or_preview(settings.CUSTOM_CSS, request), mimetype="text/css")
 
 def static(request, title, content):
-    return render_to_response('static.html', {'content' : content, 'title': title}, context_instance=RequestContext(request))
+    return render_to_response('static.html', {'content' : content, 'title': title},
+                              context_instance=RequestContext(request))
 
 def media(request, skin, path):
-    return serve(request, "%s/media/%s" % (skin, path), 
-                 document_root=os.path.join(os.path.dirname(os.path.dirname(__file__)),'skins').replace('\\','/'))
+    return serve(request, "%s/media/%s" % (skin, path),
+                 document_root=os.path.join(os.path.dirname(os.path.dirname(__file__)), 'skins').replace('\\', '/'))
 
 def markdown_help(request):
     return render_to_response('markdown_help.html', context_instance=RequestContext(request))
 
 
-def opensearch(request):   
+def opensearch(request):
     return render_to_response('opensearch.html', {'settings' : settings}, context_instance=RequestContext(request))
-    
+
 
 def feedback(request):
     if request.method == "POST":
@@ -47,14 +48,14 @@ def feedback(request):
             context = {'user': request.user}
 
             if not request.user.is_authenticated:
-                context['email'] = form.cleaned_data.get('email',None)
+                context['email'] = form.cleaned_data.get('email', None)
             context['message'] = form.cleaned_data['message']
-            context['name'] = form.cleaned_data.get('name',None)
+            context['name'] = form.cleaned_data.get('name', None)
             context['ip'] = request.META['REMOTE_ADDR']
 
             recipients = User.objects.filter(is_superuser=True)
             send_template_email(recipients, "notifications/feedback.html", context)
-            
+
             msg = _('Thanks for the feedback!')
             request.user.message_set.create(message=msg)
             return HttpResponseRedirect(get_next_url(request))
@@ -62,6 +63,7 @@ def feedback(request):
         form = FeedbackForm(initial={'next':get_next_url(request)})
 
     return render_to_response('feedback.html', {'form': form}, context_instance=RequestContext(request))
+
 feedback.CANCEL_MESSAGE=_('We look forward to hearing your feedback! Please, give it next time :)')
 
 def privacy(request):
@@ -69,34 +71,34 @@ def privacy(request):
 
 def logout(request):
     return render_to_response('logout.html', {
-        'next' : get_next_url(request),
+    'next' : get_next_url(request),
     }, context_instance=RequestContext(request))
 
 def badges(request):
     badges = [b.ondb for b in sorted(BadgesMeta.by_id.values(), lambda b1, b2: cmp(b1.name, b2.name))]
-    
+
     if request.user.is_authenticated():
         my_badges = Award.objects.filter(user=request.user).values('badge_id').distinct()
     else:
         my_badges = []
 
     return render_to_response('badges.html', {
-        'badges' : badges,
-        'mybadges' : my_badges,
+    'badges' : badges,
+    'mybadges' : my_badges,
     }, context_instance=RequestContext(request))
 
 def badge(request, id, slug):
     badge = Badge.objects.get(id=id)
     awards = list(Award.objects.filter(badge=badge).order_by('user', 'awarded_at'))
     award_count = len(awards)
-    
+
     awards = sorted([dict(count=len(list(g)), user=k) for k, g in groupby(awards, lambda a: a.user)],
                     lambda c1, c2: c2['count'] - c1['count'])
 
     return render_to_response('badge.html', {
-        'award_count': award_count,
-        'awards' : awards,
-        'badge' : badge,
+    'award_count': award_count,
+    'awards' : awards,
+    'badge' : badge,
     }, context_instance=RequestContext(request))
 
 def page(request, path):
@@ -104,7 +106,7 @@ def page(request, path):
         try:
             page = Page.objects.get(id=settings.STATIC_PAGE_REGISTRY[path])
 
-            if not page.published or request.user.is_superuser:
+            if (not page.published) and (not request.user.is_superuser):
                 raise Http404
         except:
             raise Http404
@@ -127,7 +129,7 @@ def page(request, path):
             sidebar = mark_safe(sidebar)
 
     else:
-        return HttpResponse(page.body)
+        return HttpResponse(page.body, mimetype=page.extra.get('mimetype', 'text/html'))
 
     render = page.extra.get('render', 'markdown')
 
@@ -139,10 +141,10 @@ def page(request, path):
         body = page.body
 
     return render_to_response('page.html', {
-        'page' : page,
-        'body' : body,
-        'sidebar': sidebar,
-        'base': base,        
-        }, context_instance=RequestContext(request))
+    'page' : page,
+    'body' : body,
+    'sidebar': sidebar,
+    'base': base,
+    }, context_instance=RequestContext(request))