Allow usage of a custom static configuration for a given view by setting a request attribute
authorThierry Florac <thierry.florac@onf.fr>
Wed, 14 Jan 2015 15:52:59 +0100
changeset 101 8364fb15bfe5
parent 100 7b1498967eb9
child 102 80888b607fe7
Allow usage of a custom static configuration for a given view by setting a request attribute
src/ztfy/myams/interfaces/configuration.py
src/ztfy/myams/resources/css/myams.css
src/ztfy/myams/resources/less/typo.less
src/ztfy/myams/tal/api.py
src/ztfy/myams/tal/interfaces.py
src/ztfy/myams/templates/fullpage-layout.pt
src/ztfy/myams/templates/fullpage-modal-layout.pt
src/ztfy/myams/templates/layout.pt
--- a/src/ztfy/myams/interfaces/configuration.py	Tue Dec 16 11:04:53 2014 +0100
+++ b/src/ztfy/myams/interfaces/configuration.py	Wed Jan 14 15:52:59 2015 +0100
@@ -20,6 +20,9 @@
 from ztfy.myams import _
 
 
+MYAMS_CONFIGURATION_NAME_KEY = 'ztfy.myams.configuration.name'
+
+
 class IMyAMSStaticConfiguration(Interface):
     """MyAMS static configuration"""
 
--- a/src/ztfy/myams/resources/css/myams.css	Tue Dec 16 11:04:53 2014 +0100
+++ b/src/ztfy/myams/resources/css/myams.css	Wed Jan 14 15:52:59 2015 +0100
@@ -3492,6 +3492,9 @@
     margin: 0 -5px !important;
   }
 }
+.no-height {
+  line-height: 0;
+}
 .clearfix,
 .inner-space:after {
   zoom: 1;
--- a/src/ztfy/myams/resources/less/typo.less	Tue Dec 16 11:04:53 2014 +0100
+++ b/src/ztfy/myams/resources/less/typo.less	Wed Jan 14 15:52:59 2015 +0100
@@ -513,6 +513,10 @@
 	}
 }
 
+.no-height {
+	line-height: 0;
+}
+
 .clearfix,
 .inner-space:after {
 	zoom: 1;
--- a/src/ztfy/myams/tal/api.py	Tue Dec 16 11:04:53 2014 +0100
+++ b/src/ztfy/myams/tal/api.py	Wed Jan 14 15:52:59 2015 +0100
@@ -12,15 +12,17 @@
 
 # import local interfaces
 from ztfy.myams.interfaces import IMyAMSApplication, IObjectData
-from ztfy.myams.interfaces.configuration import IMyAMSConfiguration
+from ztfy.myams.interfaces.configuration import IMyAMSConfiguration, IMyAMSStaticConfiguration, \
+    MYAMS_CONFIGURATION_NAME_KEY
 from ztfy.myams.tal.interfaces import IMyAMSTalesAPI
 
 # import Zope3 packages
-from zope.component import getUtility
+from zope.component import getUtility, queryUtility
 from zope.interface import implements
 from zope.security.proxy import removeSecurityProxy
 
 # import local packages
+from ztfy.utils.request import getRequestData
 from ztfy.utils.traversing import getParent
 
 
@@ -41,11 +43,25 @@
             writer = getUtility(IJSONWriter)
             return writer.write(data.object_data)
 
+    @property
+    def application(self):
+        return getParent(self.context, IMyAMSApplication)
+
     def configuration(self):
-        application = getParent(self.context, IMyAMSApplication)
+        application = self.application
         if application is not None:
             return IMyAMSConfiguration(application, None)
 
+    def static_configuration(self):
+        configuration_name = getRequestData(MYAMS_CONFIGURATION_NAME_KEY, self.request)
+        if configuration_name:
+            configuration = queryUtility(IMyAMSStaticConfiguration, name=configuration_name)
+            if configuration is not None:
+                return configuration
+        configuration = self.configuration()
+        if configuration is not None:
+            return configuration.static_configuration
+
     def resources(self):
         application = getParent(self.context, IMyAMSApplication)
         if application is not None:
--- a/src/ztfy/myams/tal/interfaces.py	Tue Dec 16 11:04:53 2014 +0100
+++ b/src/ztfy/myams/tal/interfaces.py	Wed Jan 14 15:52:59 2015 +0100
@@ -25,5 +25,8 @@
     def configuration(self):
         """Get application configuration"""
 
+    def static_configuration(self):
+        """Get application static configuration"""
+
     def resources(self):
         """Include application's Fanstatic resources"""
--- a/src/ztfy/myams/templates/fullpage-layout.pt	Tue Dec 16 11:04:53 2014 +0100
+++ b/src/ztfy/myams/templates/fullpage-layout.pt	Wed Jan 14 15:52:59 2015 +0100
@@ -1,6 +1,6 @@
 <!DOCTYPE html>
 <html lang="fr-FR"
-	  tal:define="config context/myams:configuration; static config/static_configuration;">
+	  tal:define="config context/myams:configuration; static context/myams:static_configuration;">
 <head>
 	<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
 	<meta charset="utf-8">
--- a/src/ztfy/myams/templates/fullpage-modal-layout.pt	Tue Dec 16 11:04:53 2014 +0100
+++ b/src/ztfy/myams/templates/fullpage-modal-layout.pt	Wed Jan 14 15:52:59 2015 +0100
@@ -1,6 +1,6 @@
 <!DOCTYPE html>
 <html lang="fr-FR"
-	  tal:define="config context/myams:configuration; static config/static_configuration;">
+	  tal:define="config context/myams:configuration; static context/myams:static_configuration;">
 <head>
 	<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
 	<meta charset="utf-8">
--- a/src/ztfy/myams/templates/layout.pt	Tue Dec 16 11:04:53 2014 +0100
+++ b/src/ztfy/myams/templates/layout.pt	Wed Jan 14 15:52:59 2015 +0100
@@ -1,6 +1,6 @@
 <!DOCTYPE html>
 <html lang="fr-FR"
-	  tal:define="config context/myams:configuration; static config/static_configuration;">
+	  tal:define="config context/myams:configuration; static context/myams:static_configuration;">
 <head>
 	<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
 	<meta charset="utf-8">
@@ -29,8 +29,10 @@
 		<!-- Logo -->
 		<div id="logo-group">
 			<span id="logo" tal:condition="config/logo">
-				<img tal:attributes="src string:${config/logo/@@absolute_url}/++display++w200.png;
-									 alt config/logo_title;" />
+				<a tal:attributes="href string:${context/@@absolute_url}/@@index.html">
+					<img tal:attributes="src string:${config/logo/@@absolute_url}/++display++w200.png;
+										 alt config/logo_title;" />
+				</a>
 			</span>
 		</div>
 		<!-- end logo -->