Skip to content

Commit 74726bd

Browse files
authoredAug 31, 2022
Merge pull request #27 from NaturalSolutions/instance-multi-territoires-by-default
Instance multi territoires by default
2 parents 49a7b5e + 0014119 commit 74726bd

10 files changed

+59
-41
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

+15-2
Original file line numberDiff line numberDiff line change
@@ -301,7 +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:
308+
return abort(404)
309+
310+
return render_template(tpl)
311+
312+
@main.route('/legal-notices')
313+
def legal_notices():
314+
315+
tpl = utils.getCustomTpl('legal_notices')
316+
317+
if not tpl:
305318
return abort(404)
306319

307-
return render_template('db-page.jinja', name='about', page=utils.getDbPage('about'))
320+
return render_template(tpl)

‎backend/static/css/home.css

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
background-size: cover;
44
}
55

6-
.page-home .app-home-carousel > h1 {
6+
.page-home .text-shadow{
77
z-index: 2;
88
text-shadow: 2px 2px 2px #00000099;
99
right: 0;

‎backend/tpl/components/home-carousel.jinja

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<div id="js-app-home-carousel" class="app-home-carousel d-none d-md-block position-relative">
2-
<h1 class="position-absolute text-white pt-5 pr-5 pl-2 m-0 col-12 col-lg-8 col-xl-5">{{ _('home.title') }}</h1>
2+
<h1 class="position-absolute text-white pt-5 pr-5 pl-2 m-0 col-12 col-lg-8 col-xl-5 text-shadow">{{ _('home.title') }}</h1>
33
<b-carousel
44
fade
55
:interval="5000"
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

+6-6
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,9 @@
2727

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

30-
{% set intro_locale = dbconf.get('home_intro_' + locale.__str__()) %}
31-
{% set intro = intro_locale if intro_locale else dbconf.get('home_intro', '') %}
32-
{% if dbconf.home_intro_position == 'top': %}
33-
{% autoescape false %}{{ intro }}{% endautoescape %}
30+
{% set home_block_1 = getCustomTpl('home_block_1') %}
31+
{% if home_block_1 %}
32+
{% include home_block_1 %}
3433
{% endif %}
3534

3635
<div class="blocks mt-4">
@@ -57,8 +56,9 @@
5756

5857
</div>
5958

60-
{% if dbconf.home_intro_position == 'bottom': %}
61-
{% autoescape false %}{{ intro }}{% endautoescape %}
59+
{% set home_block_2 = getCustomTpl('home_block_2') %}
60+
{% if home_block_2 %}
61+
{% include home_block_2 %}
6262
{% endif %}
6363
</div>
6464

‎backend/tpl/home_multi_obs.jinja

+13-7
Original file line numberDiff line numberDiff line change
@@ -29,10 +29,9 @@
2929

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

32-
{% set intro_locale = dbconf.get('home_intro_' + locale.__str__()) %}
33-
{% set intro = intro_locale if intro_locale else dbconf.get('home_intro', '') %}
34-
{% if dbconf.home_intro_position == 'top': %}
35-
{% autoescape false %}{{ intro }}{% endautoescape %}
32+
{% set home_block_1 = getCustomTpl('home_block_1') %}
33+
{% if home_block_1 %}
34+
{% include home_block_1 %}
3635
{% endif %}
3736

3837
<div class="container-fluid px-0 my-4 my-md-5">
@@ -52,7 +51,7 @@
5251
<a class="d-block w-100 h-100 position-relative" href='/sites?filters=[{"name":"id_observatory","values":[{{ observatories[count.value].id }}]}]'>
5352
<img class="w-100 h-100" src="{{ getThumborUrl('700x200', observatories[count.value].photo) }}">
5453
<span class="d-flex flex-column justify-content-center align-items-center text-center position-absolute w-100 h-100 info text-white">
55-
<span class="text-uppercase">{{ observatories[count.value].title }}</span>
54+
<span class="text-uppercase text-shadow">{{ observatories[count.value].title }}</span>
5655
<button type="button" class="btn btn-outline-light d-none">Voir</button>
5756
</span>
5857
</a>
@@ -81,6 +80,11 @@
8180
{% endfor %}
8281
</div>
8382

83+
{% set home_block_2 = getCustomTpl('home_block_2') %}
84+
{% if home_block_2 %}
85+
{% include home_block_2 %}
86+
{% endif %}
87+
8488
<div class="container-xl">
8589
<div class="text-center">
8690
<a href="/sites">{{ _('home.map_block_title') }}</a>
@@ -93,9 +97,11 @@
9397
</a>
9498
</div>
9599

96-
{% if dbconf.home_intro_position == 'bottom': %}
97-
{% autoescape false %}{{ intro }}{% endautoescape %}
100+
{% set home_block_3 = getCustomTpl('home_block_3') %}
101+
{% if home_block_3 %}
102+
{% include home_block_3 %}
98103
{% endif %}
104+
99105
</div>
100106

101107
<script>

‎backend/tpl/layout.jinja

+6-3
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,7 +118,9 @@
117118

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

120-
<div>{{ _('footer.copyright') }}</div>
121+
<div class="mt-4 d-flex">
122+
{% include 'components/legal-footer.jinja' %}
123+
</div>
121124
{% endblock %}
122125
</footer>
123126
{% endif %}

‎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)
Please sign in to comment.