changeset 7d5684f113ea in www.tryton.org:default
details: https://hg.tryton.org/www.tryton.org?cmd=changeset&node=7d5684f113ea
description:
Use class to store providers
issue11710
review413561011
diffstat:
app.py | 79 +++++++++++++++++++++++++-------
requirements.txt | 2 +-
templates/service_providers.html | 12 ++--
templates/service_providers/layout.html | 6 +-
4 files changed, 70 insertions(+), 29 deletions(-)
diffs (162 lines):
diff -r db2bd89e2056 -r 7d5684f113ea app.py
--- a/app.py Thu Sep 15 08:45:45 2022 +0200
+++ b/app.py Wed Sep 14 22:31:26 2022 +0200
@@ -44,23 +44,6 @@
'https://foundation.tryton.org:9000/foundation/foundation/1/donations'
'?account=732&account=734')
-PROVIDERS = [
- ('Adiczion', [(43.52153, 5.43150)]),
- ('B2CK', [(50.631123, 5.567552)]),
- ('Coopengo', [(48.873278, 2.324776)]),
- ('Datalife', [(37.9596885, -1.2086241)]),
- ('First Telecom', [(38.0131591, 23.7721521)]),
- ('gcoop', [(-34.59675, -58.43035)]),
- ('IntegraPer', [(-11.9753824, -77.0860785)]),
- ('INROWGA', [(18.476389, -69.893333)]),
- ('Kopen Software', [(41.5995983, 0.5799085)]),
- ('Lava Lab Software', [(-27.978905, 153.389466)]),
- ('m-ds', [(52.520008, 13.404954)]),
- ('NaN-tic', [(41.544063, 2.115122)]),
- ('power solutions', [(47.0467674, 8.3048232)]),
- ('SISalp', [(45.903956, 6.099937), (43.132028, 5.935532)]),
- ('Virtual Things', [(48.13585, 11.577415), (50.775116, 6.083565)]),
- ]
CRITICAL_CSS_DIR = os.environ.get('CRITICAL_CSS')
CRITICAL_CSS_COOKIE = 'critical-css'
@@ -101,6 +84,20 @@
gravatar = Gravatar(app)
sitemap = Sitemap(app=app)
+
+def json_default(o):
+ if hasattr(o, '__json__'):
+ return o.__json__()
+ raise TypeError(f'Object of type {o.__class__.__name__} '
+ f'is not JSON serializable')
+
+
+app.jinja_env.policies['json.dumps_kwargs'] = {
+ 'sort_keys': True,
+ 'default': json_default,
+ }
+
+
_slugify_strip_re = re.compile(r'[^\w\s-]')
_slugify_hyphenate_re = re.compile(r'[-\s]+')
@@ -858,8 +855,54 @@
return render_template('donate_cancel.html')
+class Provider:
+ def __init__(self, name, positions):
+ self.name = name
+ self.positions = positions
+
+ def __json__(self):
+ return {
+ 'name': self.name,
+ 'positions': self.positions,
+ }
+
+
+PROVIDERS = [
+ Provider(name="Adiczion",
+ positions=[(43.52153, 5.43150)]),
+ Provider(name="B2CK",
+ positions=[(50.631123, 5.567552)]),
+ Provider(name="Coopengo",
+ positions=[(48.873278, 2.324776)]),
+ Provider(name="Datalife",
+ positions=[(37.9596885, -1.2086241)]),
+ Provider(name="First Telecom",
+ positions=[(38.0131591, 23.7721521)]),
+ Provider(name="gcoop",
+ positions=[(-34.59675, -58.43035)]),
+ Provider(name="IntegraPer",
+ positions=[(-11.9753824, -77.0860785)]),
+ Provider(name="INROWGA",
+ positions=[(18.476389, -69.893333)]),
+ Provider(name="Kopen Software",
+ positions=[(41.5995983, 0.5799085)]),
+ Provider(name="Lava Lab Software",
+ positions=[(-27.978905, 153.389466)]),
+ Provider(name="m-ds",
+ positions=[(52.520008, 13.404954)]),
+ Provider(name="NaN-tic",
+ positions=[(41.544063, 2.115122)]),
+ Provider(name="power solutions",
+ positions=[(47.0467674, 8.3048232)]),
+ Provider(name="SISalp",
+ positions=[(45.903956, 6.099937), (43.132028, 5.935532)]),
+ Provider(name="Virtual Things",
+ positions=[(48.13585, 11.577415), (50.775116, 6.083565)]),
+ ]
+
+
@app.route('/service-providers')
[email protected](key_prefix=cache_key_prefix_view)
[email protected](key_prefix=cache_key_prefix_view, query_string=True)
@add_links(PRECONNECT_HEADERS + JS_LINK_HEADERS + CSS_LINK_HEADERS)
def service_providers():
shuffle(PROVIDERS)
diff -r db2bd89e2056 -r 7d5684f113ea requirements.txt
--- a/requirements.txt Thu Sep 15 08:45:45 2022 +0200
+++ b/requirements.txt Wed Sep 14 22:31:26 2022 +0200
@@ -1,4 +1,4 @@
-Flask
+Flask>=2.2
Flask-Caching
Flask-Gravatar
Flask-Sitemap
diff -r db2bd89e2056 -r 7d5684f113ea templates/service_providers.html
--- a/templates/service_providers.html Thu Sep 15 08:45:45 2022 +0200
+++ b/templates/service_providers.html Wed Sep 14 22:31:26 2022 +0200
@@ -20,9 +20,8 @@
<section class="section">
<div class="container">
<div class="row row-cols-1 row-cols-md-2 row-cols-xl-4">
- {% for provider, _ in providers %}
- {% set name = provider %}
- {% include "service_providers/%s.html" % provider|lower|slugify %}
+ {% for provider in providers %}
+ {% include "service_providers/%s.html" %
provider.name|lower|slugify %}
{% endfor %}
</div>
</div>
@@ -63,11 +62,10 @@
attribution: '© <a
href="http://osm.org/copyright">OpenStreetMap</a> contributors'
}).addTo(map);
var markers = {{ providers | tojson }};
- markers.forEach(function(marker) {
- var name = marker[0];
- marker[1].forEach(function(LatLng) {
+ markers.forEach(function(provider) {
+ provider.positions.forEach(function(LatLng) {
L.marker(LatLng).addTo(map)
- .bindPopup('<a href="#' + name.toLowerCase().replace(/ /g,
'-') + '">' + name + '</a>');
+ .bindPopup('<a href="#' +
provider.name.toLowerCase().replace(/ /g, '-') + '">' + provider.name + '</a>');
});
});
}
diff -r db2bd89e2056 -r 7d5684f113ea templates/service_providers/layout.html
--- a/templates/service_providers/layout.html Thu Sep 15 08:45:45 2022 +0200
+++ b/templates/service_providers/layout.html Wed Sep 14 22:31:26 2022 +0200
@@ -1,12 +1,12 @@
-<div class="col mb-gutter" id="{{ name | lower | replace(' ', '-') }}">
+<div class="col mb-gutter" id="{{ provider.name | lower | replace(' ', '-')
}}">
<div class="card mx-auto shadow d-flex flex-colum" style="max-width:
24rem; height: 100%">
<a href="{{ website }}" style="height: 240px">
{% if img %}
- <img class="card-img-top text-center d-block" src="{{ img }}"
alt="{{ name }}" loading="lazy" width="382" height="240"/>
+ <img class="card-img-top text-center d-block" src="{{ img }}"
alt="{{ provider.name }}" loading="lazy" width="382" height="240"/>
{% endif %}
</a>
<div class="card-body">
- <h2 class="h5 card-title">{{ name }}</h2>
+ <h2 class="h5 card-title">{{ provider.name }}</h2>
<p class="card-text" style="height: 200px; overflow-y: auto;">
{% block description %}{% endblock %}
</p>