From 9e40b5e5d7e26f4b8d3250cfbde23540a6205fd6 Mon Sep 17 00:00:00 2001 From: hernani Date: Mon, 7 Jun 2010 02:38:20 +0000 Subject: [PATCH] Adds the hability to create custom css. Fixes a small issue with admin area forms. git-svn-id: http://svn.osqa.net/svnroot/osqa/trunk@382 0cfe37f9-358a-4d5e-be75-b63607b5c754 --- forum/context.py | 26 +------------------ forum/settings/__init__.py | 6 +++-- forum/settings/forms.py | 6 +++-- forum/settings/static.py | 19 ++++++++++++++ .../skins/default/templates/base_content.html | 3 +++ .../templates/osqaadmin/djstyle_base.html | 1 + forum/urls.py | 1 + forum/views/admin.py | 2 +- forum/views/meta.py | 3 +++ 9 files changed, 37 insertions(+), 30 deletions(-) create mode 100644 forum/settings/static.py diff --git a/forum/context.py b/forum/context.py index e937810..ce7d1b1 100644 --- a/forum/context.py +++ b/forum/context.py @@ -1,31 +1,7 @@ from forum import settings -from django.conf import settings as djsettings def application_settings(context): - my_settings = { - 'APP_TITLE' : settings.APP_TITLE, - 'APP_SHORT_NAME' : settings.APP_SHORT_NAME, - 'SHOW_WELCOME_BOX' : settings.SHOW_WELCOME_BOX, - 'APP_URL' : settings.APP_URL, - 'APP_KEYWORDS' : settings.APP_KEYWORDS, - 'APP_DESCRIPTION' : settings.APP_DESCRIPTION, - 'APP_INTRO' : settings.APP_INTRO, - 'APP_LOGO' : settings.APP_LOGO, - 'EMAIL_VALIDATION': 'off', - 'SUPPORT_URL': settings.SUPPORT_URL, - 'CONTACT_URL': settings.CONTACT_URL, - 'FORUM_SCRIPT_ALIAS': djsettings.FORUM_SCRIPT_ALIAS, - 'LANGUAGE_CODE': djsettings.LANGUAGE_CODE, - 'GOOGLE_SITEMAP_CODE':settings.GOOGLE_SITEMAP_CODE, - 'GOOGLE_ANALYTICS_KEY':settings.GOOGLE_ANALYTICS_KEY, - 'WIKI_ON':settings.WIKI_ON, - 'OSQA_SKIN':djsettings.OSQA_DEFAULT_SKIN, - 'APP_FAVICON':settings.APP_FAVICON, - 'OSQA_VERSION': settings.OSQA_VERSION, - 'ADMIN_MEDIA_PREFIX': djsettings.ADMIN_MEDIA_PREFIX, - 'SVN_REVISION': settings.SVN_REVISION, - } - return {'settings':my_settings} + return {'settings': settings} def auth_processor(request): """ diff --git a/forum/settings/__init__.py b/forum/settings/__init__.py index addab2d..9880c5f 100644 --- a/forum/settings/__init__.py +++ b/forum/settings/__init__.py @@ -16,8 +16,9 @@ DJSTYLE_ADMIN_INTERFACE = Setting('DJSTYLE_ADMIN_INTERFACE', True) APP_URL = djsettings.APP_URL FORUM_SCRIPT_ALIAS = djsettings.FORUM_SCRIPT_ALIAS - -STATIC_PAGE_REGISTRY = Setting('STATIC_PAGE_REGISTRY', {}) +OSQA_SKIN = djsettings.OSQA_DEFAULT_SKIN +LANGUAGE_CODE = djsettings.LANGUAGE_CODE +ADMIN_MEDIA_PREFIX = djsettings.ADMIN_MEDIA_PREFIX from basic import * @@ -33,6 +34,7 @@ from faq import * from form import * from moderation import * from users import * +from static import * BADGES_SET = SettingSet('badges', _('Badges config'), _("Configure badges on your OSQA site."), 500) diff --git a/forum/settings/forms.py b/forum/settings/forms.py index 432ba0b..c0d3a49 100644 --- a/forum/settings/forms.py +++ b/forum/settings/forms.py @@ -16,9 +16,11 @@ class UnfilteredField(forms.CharField): class SettingsSetForm(forms.Form): def __init__(self, set, data=None, *args, **kwargs): if data is None: - data = dict([(setting.name, setting.value) for setting in set]) + initial = dict([(setting.name, setting.value) for setting in set]) + else: + initial = None - super(SettingsSetForm, self).__init__(data, *args, **kwargs) + super(SettingsSetForm, self).__init__(data, initial=initial, *args, **kwargs) for setting in set: if isinstance(setting, (Setting.emulators.get(str, DummySetting), Setting.emulators.get(unicode, DummySetting))): diff --git a/forum/settings/static.py b/forum/settings/static.py new file mode 100644 index 0000000..2ba412a --- /dev/null +++ b/forum/settings/static.py @@ -0,0 +1,19 @@ +from base import Setting, SettingSet +from django.forms.widgets import Textarea +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) + +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)) + +CUSTOM_CSS = Setting('CUSTOM_CSS', '', CSS_SET, dict( +label = _("Custom CSS"), +help_text = _("Your custom CSS."), +widget=Textarea(attrs={'rows': '25'}), +required=False)) + diff --git a/forum/skins/default/templates/base_content.html b/forum/skins/default/templates/base_content.html index ac6b9da..c434d66 100644 --- a/forum/skins/default/templates/base_content.html +++ b/forum/skins/default/templates/base_content.html @@ -14,6 +14,9 @@ {% endif %} + {% if settings.USE_CUSTOM_CSS %} + + {% endif %} {% block forestyle %}{% endblock %} diff --git a/forum/skins/default/templates/osqaadmin/djstyle_base.html b/forum/skins/default/templates/osqaadmin/djstyle_base.html index 7798b49..9a7cf74 100644 --- a/forum/skins/default/templates/osqaadmin/djstyle_base.html +++ b/forum/skins/default/templates/osqaadmin/djstyle_base.html @@ -86,6 +86,7 @@
  • {{ allsets.about.title }}
  • {{ allsets.faq.title }}
  • {{ allsets.sidebar.title }}
  • +
  • {{ allsets.css.title }}
  • diff --git a/forum/urls.py b/forum/urls.py index e517ddb..5c784d3 100644 --- a/forum/urls.py +++ b/forum/urls.py @@ -37,6 +37,7 @@ urlpatterns += patterns('', url(r'^sitemap.xml$', 'django.contrib.sitemaps.views.sitemap', {'sitemaps': sitemaps}, name='sitemap'), (r'^favicon\.ico$', app.meta.favicon), + url(r'^cstyle\.css$', app.meta.custom_css, name="custom_css"), url(r'^m/(?P\w+)/media/(?P.*)$', app.meta.media , name='osqa_media'), url(r'^%s(?P.*)$' % _('upfiles/'), 'django.views.static.serve', diff --git a/forum/views/admin.py b/forum/views/admin.py index 800e59f..9fd08f2 100644 --- a/forum/views/admin.py +++ b/forum/views/admin.py @@ -36,7 +36,7 @@ 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')] + 'form', 'moderation', 'css')] , lambda s1, s2: s1.weight - s2.weight) return render_to_response(template, context, context_instance=RequestContext(request)) else: diff --git a/forum/views/meta.py b/forum/views/meta.py index 608d1cb..781fcd2 100644 --- a/forum/views/meta.py +++ b/forum/views/meta.py @@ -21,6 +21,9 @@ import re def favicon(request): return HttpResponseRedirect(str(settings.APP_FAVICON)) +def custom_css(request): + return HttpResponse(unicode(settings.CUSTOM_CSS), mimetype="text/css") + def static(request, title, content): return render_to_response('static.html', {'content' : content, 'title': title}, context_instance=RequestContext(request)) -- 2.39.5