Skip to content

Commit 0014119

Browse files
author
Jérémy Leriche
committed
feat: add home blocks, move db tpl to jinja
1 parent b700159 commit 0014119

8 files changed

+54
-46
lines changed

backend/app.py

+1-2
Original file line numberDiff line numberDiff line change
@@ -69,9 +69,8 @@ def inject_to_tpl():
6969
debug=app.debug,
7070
locale=get_locale(),
7171
isMultiObservatories=utils.isMultiObservatories,
72-
isDbPagePublished=utils.isDbPagePublished,
7372
getThumborUrl=utils.getThumborUrl,
74-
pathExists=os.path.exists,
73+
getCustomTpl=utils.getCustomTpl,
7574
)
7675
data.update(custom)
7776
return data

backend/routes.py

+12-6
Original file line numberDiff line numberDiff line change
@@ -301,14 +301,20 @@ def sample():
301301

302302
@main.route('/about')
303303
def about():
304-
if (not utils.isDbPagePublished('about')):
304+
305+
tpl = utils.getCustomTpl('about')
306+
307+
if not tpl:
305308
return abort(404)
306309

307-
return render_template('db-page.jinja', name='about', page=utils.getDbPage('about'))
310+
return render_template(tpl)
311+
312+
@main.route('/legal-notices')
313+
def legal_notices():
314+
315+
tpl = utils.getCustomTpl('legal_notices')
308316

309-
@main.route('/disclaimer')
310-
def disclaimer():
311-
if (not utils.isDbPagePublished('disclaimer')):
317+
if not tpl:
312318
return abort(404)
313319

314-
return render_template('db-page.jinja', name='disclaimer', page=utils.getDbPage('disclaimer'))
320+
return render_template(tpl)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{{ _('footer.copyright') }}
2+
3+
{% if getCustomTpl('legal_notices') %}
4+
<span class="mx-3">-</span>
5+
<a href="/legal-notices">Mentions Légales</a>
6+
{% endif %}

backend/tpl/components/main-nav.jinja

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
<li class="nav-item {% if active_page == 'home' %}active{% endif %}">
33
<a class="nav-link " href="/">{{ _('header.nav.home') }}</a>
44
</li>
5-
{% if isDbPagePublished('about'): %}
5+
{% if getCustomTpl('about') %}
66
<li class="nav-item {% if active_page == 'about' %}active{% endif %}">
77
<a class="nav-link" href="/about" >{{ _('header.nav.about') }}</a>
88
</li>

backend/tpl/home_mono_obs.jinja

+8-4
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,10 @@
2727

2828
{% include 'components/home-carousel.jinja' %}
2929

30-
{% set home_block_1 = dbconf.get('home_block_1_' + locale.__str__()) if dbconf.get('home_block_1_' + locale.__str__()) else dbconf.get('home_block_1', '') %}
31-
{% autoescape false %}{{ home_block_1 }}{% endautoescape %}
30+
{% set home_block_1 = getCustomTpl('home_block_1') %}
31+
{% if home_block_1 %}
32+
{% include home_block_1 %}
33+
{% endif %}
3234

3335
<div class="blocks mt-4">
3436

@@ -54,8 +56,10 @@
5456

5557
</div>
5658

57-
{% set home_block_2 = dbconf.get('home_block_2_' + locale.__str__()) if dbconf.get('home_block_2_' + locale.__str__()) else dbconf.get('home_block_2', '') %}
58-
{% autoescape false %}{{ home_block_2 }}{% endautoescape %}
59+
{% set home_block_2 = getCustomTpl('home_block_2') %}
60+
{% if home_block_2 %}
61+
{% include home_block_2 %}
62+
{% endif %}
5963
</div>
6064

6165
<script>

backend/tpl/home_multi_obs.jinja

+12-6
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,10 @@
2929

3030
{% include 'components/home-carousel.jinja' %}
3131

32-
{% set home_block_1 = dbconf.get('home_block_1_' + locale.__str__()) if dbconf.get('home_block_1_' + locale.__str__()) else dbconf.get('home_block_1', '') %}
33-
{% autoescape false %}{{ home_block_1 }}{% endautoescape %}
32+
{% set home_block_1 = getCustomTpl('home_block_1') %}
33+
{% if home_block_1 %}
34+
{% include home_block_1 %}
35+
{% endif %}
3436

3537
<div class="container-fluid px-0 my-4 my-md-5">
3638
{% set count = namespace(value=0) %}
@@ -78,8 +80,10 @@
7880
{% endfor %}
7981
</div>
8082

81-
{% set home_block_2 = dbconf.get('home_block_2_' + locale.__str__()) if dbconf.get('home_block_2_' + locale.__str__()) else dbconf.get('home_block_2', '') %}
82-
{% autoescape false %}{{ home_block_2 }}{% endautoescape %}
83+
{% set home_block_2 = getCustomTpl('home_block_2') %}
84+
{% if home_block_2 %}
85+
{% include home_block_2 %}
86+
{% endif %}
8387

8488
<div class="container-xl">
8589
<div class="text-center">
@@ -93,8 +97,10 @@
9397
</a>
9498
</div>
9599

96-
{% set home_block_3 = dbconf.get('home_block_3_' + locale.__str__()) if dbconf.get('home_block_3_' + locale.__str__()) else dbconf.get('home_block_3', '') %}
97-
{% autoescape false %}{{ home_block_3 }}{% endautoescape %}
100+
{% set home_block_3 = getCustomTpl('home_block_3') %}
101+
{% if home_block_3 %}
102+
{% include home_block_3 %}
103+
{% endif %}
98104

99105
</div>
100106

backend/tpl/layout.jinja

+5-9
Original file line numberDiff line numberDiff line change
@@ -62,8 +62,9 @@
6262
</header>
6363
<div class="header-title d-none d-sm-block">{% block header_title %}{% endblock %}</div>
6464
{% block content %}{% endblock %}
65-
{% if pathExists('tpl/custom/footer.jinja') %}
66-
{% include 'custom/footer.jinja' %}
65+
{% set footer = getCustomTpl('footer') %}
66+
{% if footer: %}
67+
{% include footer %}
6768
{% else %}
6869
<footer class="app-footer">
6970
{% block footer %}
@@ -117,13 +118,8 @@
117118

118119
<hr class="mt-4" />
119120

120-
<div class="text-light d-flex">
121-
{{ _('footer.copyright') }}
122-
123-
{% if isDbPagePublished('disclaimer'): %}
124-
<span class="mx-3">-</span>
125-
<a href="/disclaimer">Mentions Légales</a>
126-
{% endif %}
121+
<div class="mt-4 d-flex">
122+
{% include 'components/legal-footer.jinja' %}
127123
</div>
128124
{% endblock %}
129125
</footer>

backend/utils.py

+9-18
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,15 @@
2424
site_schema = models.TSiteSchema(many=True)
2525
themes_sthemes_schema = models.CorSthemeThemeSchema(many=True)
2626

27+
def getCustomTpl(name):
28+
tpl_local = f'custom/{name}_{get_locale().__str__()}.jinja'
29+
tpl_common = f'custom/{name}.jinja'
30+
if os.path.exists(f'tpl/{tpl_local}'):
31+
return tpl_local
32+
if os.path.exists(f'tpl/{tpl_common}'):
33+
return tpl_common
34+
return None
35+
2736
def getThumborSignature(url):
2837
key = bytes(os.getenv("THUMBOR_SECURITY_KEY"), 'UTF-8')
2938
msg = bytes(url, 'UTF-8')
@@ -148,12 +157,6 @@ def getDbConf():
148157

149158
return conf
150159

151-
152-
def isDbPagePublished(name):
153-
dbconf = getDbConf()
154-
155-
return dbconf.get('page_' + name + '_published_' + get_locale().__str__(), dbconf.get('page_' + name + '_published')) is True
156-
157160
def isMultiObservatories():
158161
# Pourrait passer par un count sql
159162
sql = text("SELECT id FROM geopaysages.t_observatory where is_published is true")
@@ -163,18 +166,6 @@ def isMultiObservatories():
163166
return True
164167
return False
165168

166-
def getDbPage(name):
167-
dbconf = getDbConf()
168-
169-
locale = get_locale()
170-
title_locale = dbconf.get('page_' + name + '_title_' + locale.__str__())
171-
content_locale = dbconf.get('page_' + name + '_content_' + locale.__str__())
172-
173-
return {
174-
'title': title_locale if title_locale else dbconf.get('page_' + name + '_title', ''),
175-
'content': content_locale if content_locale else dbconf.get('page_' + name + '_content', '')
176-
}
177-
178169
def getFiltersData():
179170
sites=site_schema.dump(models.TSite.query.join(models.Observatory).filter(models.TSite.publish_site == True, models.Observatory.is_published == True).order_by(DEFAULT_SORT_SITES))
180171
for site in sites:

0 commit comments

Comments
 (0)