From 9f667283bba8efa50209cf8f435ef0aae629a8d4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20P=C3=A9ters?= Date: Tue, 26 May 2015 16:34:58 +0200 Subject: [PATCH] shared theme infrastructure (#7136) --- template.ezt | 91 ------------------------------ template.py | 91 ++++++++++++++++++++++++++++++ templates/base.html | 17 ++++-- templates/combo/page_template.html | 31 +++++++++- templates/theme.html | 16 ++++-- templates/theme_sekizai.html | 71 ----------------------- wcs.css | 11 ++-- 7 files changed, 147 insertions(+), 181 deletions(-) delete mode 100644 template.ezt create mode 100644 template.py delete mode 100644 templates/theme_sekizai.html diff --git a/template.ezt b/template.ezt deleted file mode 100644 index d3aef77..0000000 --- a/template.ezt +++ /dev/null @@ -1,91 +0,0 @@ - - - - [page_title] - - - - [script] - - [if-any css_variant] - - [end] -[""] - - - - -
- - -
- - - -
- -
- - [if-any gauche] -
- [gauche] -
- [end] - - [if-any bigdiv]
[end] - - [if-any title]

[title]

[end] - [body] - [if-any bigdiv]
[end] -
- -
- -
-
-
- - - - diff --git a/template.py b/template.py new file mode 100644 index 0000000..9360309 --- /dev/null +++ b/template.py @@ -0,0 +1,91 @@ +#! /usr/bin/env python + +class RemoteTemplate(object): + def __init__(self, source): + self.source = source + from wcs.qommon.misc import simplify + import os, urlparse + self.cache_key = simplify(urlparse.urlunparse(urlparse.urlparse(self.source)[:3] + ('', '', ''))) + self.cache_dirpath = os.path.join(publisher.app_dir, 'skeleton-cache') + self.cache_filepath = os.path.join(self.cache_dirpath, self.cache_key) + + def get_template_content(self): + import time, os, threading + CACHE_REFRESH_TIMEOUT = 300 + try: + cache_filepath_mtime = os.stat(self.cache_filepath).st_mtime + except OSError: # missing file + return self.update_content() + else: + template_content = open(self.cache_filepath).read() + if time.time() > (cache_filepath_mtime + CACHE_REFRESH_TIMEOUT): + threading.Thread(target=self.update_content).start() + return template_content + + def update_content(self): + import requests + theme_skeleton_url = publisher.get_site_option('theme_skeleton_url') + + r = requests.get(theme_skeleton_url, params={'source': self.source, 'format': 'ezt'}) + + body = """ + [if-any gauche] +
+ [gauche] +
+ [end] + + [if-any bigdiv]
[end] + + [if-any title]

[title]

[end] + [body] + [if-any bigdiv]
[end] + """ + + extra_head = """ +[script] + + +""" + + extra_top_head = """ + +""" + + user_info = """ + [if-any user] + + [session_user_display_name] + Déconnexion + + [else] + Connexion / Inscription + [end] + + [if-any user] + [is session_user_admin_access "True"] + Administration + [else] + [is session_user_backoffice_access "True"] + Back office + [end] + [end] + [end] + """ + + template_content = r.text.encode('utf-8') + template_content = template_content.replace('[if-any content][content][end]', body) + template_content = template_content.replace('[if-any extra-top-head][extra-top-head][end]', extra_top_head) + template_content = template_content.replace('[if-any extra-head][extra-head][end]', extra_head) + template_content = template_content.replace('[if-any user-info][user-info][end]', user_info) + self.cache(template_content) + return template_content + + def cache(self, template_body): + import os + from qommon.storage import atomic_write + if not os.path.exists(self.cache_dirpath): + os.mkdir(self.cache_dirpath) + atomic_write(self.cache_filepath, template_body) + +template_content = RemoteTemplate(request.get_url()).get_template_content() diff --git a/templates/base.html b/templates/base.html index d794574..7362f17 100644 --- a/templates/base.html +++ b/templates/base.html @@ -1,6 +1,15 @@ -{% extends "theme_sekizai.html" %} -{% load i18n static sekizai_tags %} +{% extends theme_base %} -{% block extra_css %} - +{% block extra-body-args %} +{% block bodyargs %} +{% endblock %} +{% endblock %} + +{% block user-info %} + {% if user.is_authenticated %} + + {{user.first_name}} {{user.last_name}} + Déconnexion + + {% endif %} {% endblock %} diff --git a/templates/combo/page_template.html b/templates/combo/page_template.html index 238a797..ac0318c 100644 --- a/templates/combo/page_template.html +++ b/templates/combo/page_template.html @@ -2,16 +2,27 @@ {% load static i18n combo gadjo %} {% block extra_css %} - + +{% endblock %} + +{% block extra_top_head %} +{% skeleton_extra_placeholder 'extra-top-head' %} {% endblock %} {% block extra_scripts %} - - + + +{% skeleton_extra_placeholder 'extra-head' %} {% endblock %} {% block bodyargs %} class="page-{{ page.slug }}" +{% skeleton_extra_placeholder 'extra-body-args' %} +{% endblock %} + +{% block menu %} +{% show_menu %} +{% placeholder "menu_right" %} {% endblock %} {% block content %} @@ -21,3 +32,17 @@ class="page-{{ page.slug }}" {% endblock %} {% endblock %} {% endblock %} + +{% block footer %} + {% placeholder "footer" %} +{% endblock %} + +{% block user-info %} + {% if user.is_authenticated %} + + {{user.first_name}} {{user.last_name}} + Déconnexion + + {% endif %} +{% skeleton_extra_placeholder 'user-info' %} +{% endblock %} diff --git a/templates/theme.html b/templates/theme.html index 92f8b56..43f8696 100644 --- a/templates/theme.html +++ b/templates/theme.html @@ -7,15 +7,17 @@ Compte Citoyen {% block title %}{% endblock %} - - - {% if css_variant %} - - {% endif %} + + {% block extra_top_head %} + {% endblock %} + {% block extra_css %} {% endblock %} {% block extra_scripts %} {% endblock %} + {% if css_variant %} + + {% endif %} @@ -24,12 +26,14 @@

{{ site_title }}

@@ -63,7 +67,9 @@ diff --git a/templates/theme_sekizai.html b/templates/theme_sekizai.html deleted file mode 100644 index 3ca046e..0000000 --- a/templates/theme_sekizai.html +++ /dev/null @@ -1,71 +0,0 @@ - -{% load i18n static sekizai_tags %} - - - - - - - Compte Citoyen {% block title %}{% endblock %} - - {% if css_variant %} - - {% endif %} - {% block extra_css %} - {% endblock %} - {% render_block "css" %} - {% block extra_scripts %} - {% endblock %} - {% render_block "js" %} - - - -
- - -
- - - -
- -
- {% block content %} - {% endblock %} -
- -
- -
-
-
- - - - diff --git a/wcs.css b/wcs.css index 081e2b4..9c2d487 100644 --- a/wcs.css +++ b/wcs.css @@ -1,9 +1,4 @@ @import url(/qo/css/qommon.css); -@import url(static/style.css); - -div#content { - margin:0; -} div#sidebox h3 { margin: 0 0 1em 0; @@ -27,18 +22,20 @@ div#rub_agenda, div#rub_annonce, div#rub_consultation, div#rub_service, +div#gauche + div#rub_service, div#centre, div#profile { width: 79.5%; float: right; background: white; margin-top: 15px; + clear: none; } div#breadcrumb, div#profile, -div.large div#rub_service, -div.large div#centre { +div#rub_service, +div#centre { width: 100%; float: none; clear: both;