[ckan-changes] [okfn/ckan] 7a273e: [2302] Added custom css only once user actually se...

GitHub noreply at github.com
Mon Apr 23 11:42:48 UTC 2012


  Branch: refs/heads/feature-2302-simple-theming
  Home:   https://github.com/okfn/ckan
  Commit: 7a273edea01fa8f1f0715717e87769778747b1b3
      https://github.com/okfn/ckan/commit/7a273edea01fa8f1f0715717e87769778747b1b3
  Author: Ross Jones <rossdjones at gmail.com>
  Date:   2012-04-23 (Mon, 23 Apr 2012)

  Changed paths:
    M .gitignore
    M ckan/controllers/settings.py
    M ckan/lib/base.py
    A ckan/public/css/custom.css.template
    M ckan/templates/layout_base.html

  Log Message:
  -----------
  [2302] Added custom css only once user actually sets the settings from the form


diff --git a/.gitignore b/.gitignore
index 3343614..bf04c75 100644
--- a/.gitignore
+++ b/.gitignore
@@ -9,7 +9,7 @@ sandbox/*
 theme/*
 theme
 dist
-
+ckan/public/css/custom.css
 # pylons
 development.ini*
 sstore/*
diff --git a/ckan/controllers/settings.py b/ckan/controllers/settings.py
index 09c8c7d..b72c605 100644
--- a/ckan/controllers/settings.py
+++ b/ckan/controllers/settings.py
@@ -1,3 +1,4 @@
+import os
 from pylons.i18n import set_lang
 import sqlalchemy.exc
 
@@ -35,6 +36,15 @@ def __before__(self, action, **env):
         if not authz.Authorizer.is_sysadmin(c.user):
             abort(401, _('Not authorized to see this page'))
 
+    def _write_css(self, settings):
+        source = os.path.join(config['pylons.paths']['static_files'],
+                            "css/custom.css.template")
+        path = os.path.join(config['pylons.paths']['static_files'],
+                            "css/custom.css")
+
+        output = render_text(source, settings)
+        with open(path, "wb") as f:
+            f.write(output)
 
     def index(self):
         data, errors, error_summary = {}, {}, {}
@@ -60,13 +70,11 @@ def index(self):
                 for f in fields:
                     model.Setting.set_value( f, data.get(f, ""), c.user )
                     success = True
+                self._apply_settings()
+                self._write_css(data)
         else:
             data = dict(model.Setting.get_values(fields))
 
         extras = { "data" : data, "error_summary" : error_summary,
                    "errors" : errors, "success" : success}
-        self._setup_template_variables()
         return render('settings/index.html',extra_vars=extras)
-
-    def _setup_template_variables(self):
-        pass
\ No newline at end of file
diff --git a/ckan/lib/base.py b/ckan/lib/base.py
index 075029c..eece185 100644
--- a/ckan/lib/base.py
+++ b/ckan/lib/base.py
@@ -153,10 +153,21 @@ class BaseController(WSGIController):
     authorizer = authz.Authorizer()
     log = logging.getLogger(__name__)
 
+    def _apply_settings(self):
+        # Getting configured settings
+        settings = dict( model.Setting.get_values(["name","tagline","image_url"]) )
+        g.site_title = settings.get("name", config.get('ckan.site_title',''))
+        g.site_description = \
+            settings.get("tagline", config.get('ckan.site_description','') )
+        g.site_logo = str( settings.get("image_url",
+                                         config.get('ckan.site_logo',''))
+                         )
+
     def __before__(self, action, **params):
         c.__version__ = ckan.__version__
         self._identify_user()
         i18n.handle_request(request, c)
+        self._apply_settings()
 
     def _identify_user(self):
         '''
diff --git a/ckan/public/css/custom.css.template b/ckan/public/css/custom.css.template
new file mode 100644
index 0000000..e7ca410
--- /dev/null
+++ b/ckan/public/css/custom.css.template
@@ -0,0 +1,21 @@
+.header.outer {
+  background-color: #${ css_header } !important;
+  background-image: none;
+  margin-bottom: 18px;
+     -moz-box-shadow: none;
+  -webkit-box-shadow: none;
+          box-shadow: none;
+  border-bottom: 1px solid #ccc;
+}
+body{
+    background-color: #${ css_background } !important;
+}
+.footer.outer {
+  background-color: #${ css_footer } !important;
+  background-image: none;
+  margin-top: 18px;
+     -moz-box-shadow: none;
+  -webkit-box-shadow: none;
+          box-shadow: none;
+  border-bottom: 1px solid #ccc;
+}
diff --git a/ckan/templates/layout_base.html b/ckan/templates/layout_base.html
index 1518d72..8553e73 100644
--- a/ckan/templates/layout_base.html
+++ b/ckan/templates/layout_base.html
@@ -34,6 +34,7 @@
   <link rel="stylesheet" href="${h.url_for_static('/css/chosen.css')}" type="text/css" />
   <link rel="stylesheet" href="${h.url_for_static('/css/style.css?v=2')}" />
   ${jsConditionalForIe(9, '<script type="text/javascript" src="' + h.url_for_static('/scripts/vendor/html5shiv/html5.js') + '"></script>')}
+  <link rel="stylesheet" href="${h.url_for_static('/css/custom.css')}" type="text/css" media="screen, print" />
 
   <py:if test="defined('optional_head')">
     ${optional_head()}


================================================================



More information about the ckan-changes mailing list