shared theme infrastructure (#7136)

This commit is contained in:
Frédéric Péters 2015-05-26 16:34:58 +02:00
parent ebd0f92895
commit 9f667283bb
7 changed files with 147 additions and 181 deletions

View File

@ -1,91 +0,0 @@
<!DOCTYPE html>
<html>
<head>
<title>[page_title]</title>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="shortcut icon" href="{% static "favicon.ico" %}" />
<script type="text/javascript" src="/qo/js/jquery.js"></script>
[script]
<link rel="stylesheet" type="text/css" href="[css]"/>
[if-any css_variant]
<link rel="stylesheet" type"text/css" href="[theme_url]/static/custom-[css_variant]/style.css"/>
[end]
["<!--[if lt IE 10]>"]<style>
div#services > ul > li { width: 48%; float: left; height: 18em; }
div#centre { padding-top: 45px; margin-top: 0px; }
</style>["<![endif]-->"]
<script type="text/javascript" src="[theme_url]/static/dataview.js"></script>
</head>
<body class="wcs" [if-any onload] onload="[onload]"[end]>
<div id="page">
<div id="header">
<div id="top">
<h1 id="logo"><a href="/">[site_title]</a></h1>
<div id="toplinks">
[if-any user]
<span class="logged-in">
<!--<a class="myspace" href="/myspace/">Mes démarches</a>-->
<span class="connected-user">[session_user_display_name]</span>
<a class="logout" href="[root_url]logout">D&eacute;connexion</a>
</span>
[else]
<span class="login"><a href="[root_url]login/">Connexion</a> / <a href="[root_url]register/">Inscription</a></span>
[end]
[if-any user]
[is session_user_admin_access "True"]
<a class="restricted" href="[root_url]admin/">Administration</a>
[else]
[is session_user_backoffice_access "True"]
<a class="restricted" href="[root_url]backoffice/">Back office</a>
[end]
[end]
[end]
</div>
</div>
</div> <!-- header -->
<div id="main-content-wrapper">
<div id="nav">
<ul>
<li class="link-accueil"><a href="[combo_url]">Accueil</a></li>
<li class="link-demarches"><a href="[wcs_url]">Démarches</a></li>
<li class="link-profil"><a href="[authentic_url]/accounts/">Profil</a></li>
<li class="link-aide"><a href="[help_url]">Aide</a></li>
</ul>
</div>
<div id="main-content">
<div id="content" [if-any is_index]class="large"[end] [if-any form_number]class="large"[end]>
[if-any gauche]
<div id="gauche">
[gauche]
</div>
[end]
[if-any bigdiv]<div id="[bigdiv]" [if-any breadcrumb]class="has-breadcrumb"[end]>[end]
[if-any title]<h2>[title]</h2>[end]
[body]
[if-any bigdiv]</div>[end]
</div> <!-- #content -->
<hr class="clear"/>
</div> <!-- #main-content -->
</div> <!-- #main-content-wrapper -->
</div> <!-- #page -->
<div id="footer-wrapper">
<div id="footer">
<p id="legal">Copyright © 2005-2015 Entr'ouvert</p>
</div>
</div>
</body>
</html>

91
template.py Normal file
View File

@ -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]
<div id="gauche">
[gauche]
</div>
[end]
[if-any bigdiv]<div id="[bigdiv]" [if-any breadcrumb]class="has-breadcrumb"[end]>[end]
[if-any title]<h2>[title]</h2>[end]
[body]
[if-any bigdiv]</div>[end]
"""
extra_head = """
[script]
<script type="text/javascript" src="/themes/base/static/dataview.js"></script>
<link rel="stylesheet" type="text/css" href="[css]">
"""
extra_top_head = """
<link rel="stylesheet" type="text/css" href="/qo/css/qommon.css">
"""
user_info = """
[if-any user]
<span class="logged-in">
<span class="connected-user">[session_user_display_name]</span>
<a class="logout" href="[root_url]logout">D&eacute;connexion</a>
</span>
[else]
<span class="login"><a href="[root_url]login/">Connexion</a> / <a href="[root_url]register/">Inscription</a></span>
[end]
[if-any user]
[is session_user_admin_access "True"]
<a class="restricted" href="[root_url]admin/">Administration</a>
[else]
[is session_user_backoffice_access "True"]
<a class="restricted" href="[root_url]backoffice/">Back office</a>
[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()

View File

@ -1,6 +1,15 @@
{% extends "theme_sekizai.html" %}
{% load i18n static sekizai_tags %}
{% extends theme_base %}
{% block extra_css %}
<link rel="stylesheet" type="text/css" href="{% static "authentic.style.css" %}" />
{% block extra-body-args %}
{% block bodyargs %}
{% endblock %}
{% endblock %}
{% block user-info %}
{% if user.is_authenticated %}
<span class="logged-in">
<span class="connected-user">{{user.first_name}} {{user.last_name}}</span>
<a class="logout" href="{% url 'auth_logout' %}">D&eacute;connexion</a>
</span>
{% endif %}
{% endblock %}

View File

@ -2,16 +2,27 @@
{% load static i18n combo gadjo %}
{% block extra_css %}
<link rel="stylesheet" type="text/css" href="{% static "combo.style.css" %}" >
<link rel="stylesheet" type="text/css" href="{{site_base}}{% static "combo.style.css" %}" >
{% endblock %}
{% block extra_top_head %}
{% skeleton_extra_placeholder 'extra-top-head' %}
{% endblock %}
{% block extra_scripts %}
<script src="{% xstatic 'jquery' 'jquery.min.js' %}"></script>
<script src="{{ STATIC_URL }}js/combo.public.js"></script>
<script src="{{site_base}}{% xstatic 'jquery' 'jquery.min.js' %}"></script>
<script src="{{site_base}}{% static 'js/combo.public.js' %}"></script>
{% 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 %}
<span class="logged-in">
<span class="connected-user">{{user.first_name}} {{user.last_name}}</span>
<a class="logout" href="{% url 'auth_logout' %}">D&eacute;connexion</a>
</span>
{% endif %}
{% skeleton_extra_placeholder 'user-info' %}
{% endblock %}

View File

@ -7,15 +7,17 @@
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="shortcut icon" href="/themes/auquotidien/favicon.png" />
<title>Compte Citoyen {% block title %}{% endblock %}</title>
<link rel="shortcut icon" href="{% static "fabicon.ico" %}" />
<link rel="stylesheet" type="text/css" href="{% static "style.css" %}" >
{% if css_variant %}
<link rel="stylesheet" type="text/css" href="{% static "" %}custom-{{css_variant}}/style.css" >
{% endif %}
<link rel="shortcut icon" href="{% static "favicon.ico" %}" />
{% block extra_top_head %}
{% endblock %}
<link rel="stylesheet" type="text/css" href="{{site_base}}{% static "style.css" %}" >
{% block extra_css %}
{% endblock %}
{% block extra_scripts %}
{% endblock %}
{% if css_variant %}
<link rel="stylesheet" type="text/css" href="{{site_base}}{% static "" %}custom-{{css_variant}}/style.css" >
{% endif %}
</head>
<body {% block bodyargs %}{% endblock %}>
@ -24,12 +26,14 @@
<div id="top">
<h1 id="logo"><a href="/">{{ site_title }}</a></h1>
<div id="toplinks">
{% block user-info %}
{% if user.is_authenticated %}
<span class="logged-in">
<span class="connected-user">{{user.first_name}} {{user.last_name}}</span>
<a class="logout" href="{% url 'auth_logout' %}">D&eacute;connexion</a>
</span>
{% endif %}
{% endblock %}
</div>
</div>
@ -63,7 +67,9 @@
<div id="footer-wrapper">
<div id="footer">
{% block footer %}
<p id="legal">Copyright © 2005-2015 Entr'ouvert</p>
{% endblock %}
</div>
</div>
</body>

View File

@ -1,71 +0,0 @@
<!DOCTYPE html>
{% load i18n static sekizai_tags %}
<html>
<head>
<meta charset="UTF-8"><!---->
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1" />
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="shortcut icon" href="{% static "favicon.ico" %}" />
<title>Compte Citoyen {% block title %}{% endblock %}</title>
<link rel="stylesheet" type="text/css" href="{% static "style.css" %}" >
{% if css_variant %}
<link rel="stylesheet" type="text/css" href="{% static "" %}custom-{{css_variant}}/style.css" >
{% endif %}
{% block extra_css %}
{% endblock %}
{% render_block "css" %}
{% block extra_scripts %}
{% endblock %}
{% render_block "js" %}
</head>
<body class="authentic2" {% block bodyargs %}{% endblock %}>
<div id="page">
<div id="header">
<div id="top">
<h1 id="logo"><a href="/">{{ site_title }}</a></h1>
<div id="toplinks">
{% if user.is_authenticated %}
<span class="logged-in">
<span class="connected-user">{{user.first_name}} {{user.last_name}}</span>
<a class="logout" href="{% url 'auth_logout' %}">D&eacute;connexion</a>
</span>
{% endif %}
</div>
</div>
</div> <!-- header -->
<div id="main-content-wrapper">
<div id="nav">
{% block menu %}
<ul>
<li class="link-accueil"><a href="{{combo_url}}">Accueil</a></li>
<li class="link-demarches"><a href="{{wcs_url}}/login">Démarches</a></li>
<li class="link-profil"><a href="{{authentic_url}}/accounts/">Profil</a></li>
<li class="link-aide"><a href="{{help_url}}">Aide</a></li>
</ul>
{% endblock %}
</div>
<div id="main-content">
<div id="content" class="large">
{% block content %}
{% endblock %}
</div> <!-- #content -->
<br class="clear"/>
</div> <!-- #main-content -->
</div> <!-- #main-content-wrapper -->
</div> <!-- #page -->
<div id="footer-wrapper">
<div id="footer">
<p id="legal">Copyright © 2005-2015 Entr'ouvert</p>
</div>
</div>
</body>
</html>

11
wcs.css
View File

@ -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;