changeset c474f836438b in www.tryton.org:default
details: https://hg.tryton.org/www.tryton.org?cmd=changeset&node=c474f836438b
description:
        Add services to providers

        issue11710
        review413561011
diffstat:

 app.py                                  |  92 ++++++++++++++++++++++++++------
 templates/service_providers.html        |  28 ++++++++++
 templates/service_providers/layout.html |  14 +++++
 3 files changed, 117 insertions(+), 17 deletions(-)

diffs (213 lines):

diff -r 9439eb0644f5 -r c474f836438b app.py
--- a/app.py    Wed Sep 14 22:31:47 2022 +0200
+++ b/app.py    Thu Sep 15 00:31:54 2022 +0200
@@ -1,10 +1,12 @@
 #!/usr/bin/env python3
 import ast
 import datetime
+import enum
 import functools
 import glob
 import hashlib
 import logging
+import operator
 import os
 import re
 import unicodedata
@@ -85,6 +87,15 @@
 sitemap = Sitemap(app=app)
 
 
+def url_for_self(**args):
+    return url_for(request.endpoint, **dict(request.args, **args))
+
+
[email protected]_processor
+def inject_self():
+    return dict(url_for_self=url_for_self)
+
+
 def json_default(o):
     if hasattr(o, '__json__'):
         return o.__json__()
@@ -855,10 +866,23 @@
     return render_template('donate_cancel.html')
 
 
+class Service(enum.Flag):
+    NONE = 0
+    CONSULTING = enum.auto()
+    DEVELOPMENT = enum.auto()
+    HOSTING = enum.auto()
+    TRAINING = enum.auto()
+
+
 class Provider:
-    def __init__(self, name, positions):
+    def __init__(self, name, positions, services=Service.NONE):
         self.name = name
         self.positions = positions
+        self.services = services
+
+    def __getattr__(self, name):
+        if self.services:
+            return self.services & getattr(Service, name.upper())
 
     def __json__(self):
         return {
@@ -869,35 +893,52 @@
 
 PROVIDERS = [
     Provider(name="Adiczion",
-        positions=[(43.52153, 5.43150)]),
+        positions=[(43.52153, 5.43150)],
+        services=Service.CONSULTING | Service.DEVELOPMENT),
     Provider(name="B2CK",
-        positions=[(50.631123, 5.567552)]),
+        positions=[(50.631123, 5.567552)],
+        services=Service.CONSULTING | Service.DEVELOPMENT | Service.TRAINING),
     Provider(name="Coopengo",
-        positions=[(48.873278, 2.324776)]),
+        positions=[(48.873278, 2.324776)],
+        services=Service.DEVELOPMENT),
     Provider(name="Datalife",
-        positions=[(37.9596885, -1.2086241)]),
+        positions=[(37.9596885, -1.2086241)],
+        services=Service.CONSULTING | Service.DEVELOPMENT),
     Provider(name="First Telecom",
-        positions=[(38.0131591, 23.7721521)]),
+        positions=[(38.0131591, 23.7721521)],
+        services=Service.CONSULTING),
     Provider(name="gcoop",
-        positions=[(-34.59675, -58.43035)]),
+        positions=[(-34.59675, -58.43035)],
+        services=Service.CONSULTING | Service.DEVELOPMENT),
     Provider(name="IntegraPer",
-        positions=[(-11.9753824, -77.0860785)]),
+        positions=[(-11.9753824, -77.0860785)],
+        services=Service.CONSULTING | Service.DEVELOPMENT),
     Provider(name="INROWGA",
-        positions=[(18.476389, -69.893333)]),
+        positions=[(18.476389, -69.893333)],
+        services=Service.CONSULTING),
     Provider(name="Kopen Software",
-        positions=[(41.5995983, 0.5799085)]),
+        positions=[(41.5995983, 0.5799085)],
+        services=Service.CONSULTING | Service.DEVELOPMENT | Service.HOSTING
+        | Service.TRAINING),
     Provider(name="Lava Lab Software",
-        positions=[(-27.978905, 153.389466)]),
+        positions=[(-27.978905, 153.389466)],
+        services=Service.CONSULTING | Service.DEVELOPMENT),
     Provider(name="m-ds",
-        positions=[(52.520008, 13.404954)]),
+        positions=[(52.520008, 13.404954)],
+        services=Service.CONSULTING | Service.DEVELOPMENT),
     Provider(name="NaN-tic",
-        positions=[(41.544063, 2.115122)]),
+        positions=[(41.544063, 2.115122)],
+        services=Service.CONSULTING | Service.DEVELOPMENT),
     Provider(name="power solutions",
-        positions=[(47.0467674, 8.3048232)]),
+        positions=[(47.0467674, 8.3048232)],
+        services=Service.CONSULTING | Service.DEVELOPMENT | Service.HOSTING),
     Provider(name="SISalp",
-        positions=[(45.903956, 6.099937), (43.132028, 5.935532)]),
+        positions=[(45.903956, 6.099937), (43.132028, 5.935532)],
+        services=Service.CONSULTING | Service.HOSTING),
     Provider(name="Virtual Things",
-        positions=[(48.13585, 11.577415), (50.775116, 6.083565)]),
+        positions=[(48.13585, 11.577415), (50.775116, 6.083565)],
+        services=Service.CONSULTING | Service.DEVELOPMENT | Service.TRAINING
+        | Service.HOSTING),
     ]
 
 
@@ -907,7 +948,24 @@
 def service_providers():
     providers = PROVIDERS.copy()
     shuffle(providers)
-    return render_template('service_providers.html', providers=providers)
+    services = []
+    environ = {}
+    filters = {'consulting', 'development', 'hosting', 'training'}
+    if not (request.args.keys() <= filters):
+        abort(HTTPStatus.BAD_REQUEST)
+    for filter_name in filters:
+        environ[filter_name] = request.args.get(filter_name, type=int)
+        if (environ[filter_name] is not None
+                and environ[filter_name] not in {0, 1}):
+            abort(HTTPStatus.BAD_REQUEST)
+        if environ[filter_name]:
+            services.append(getattr(Service, filter_name.upper()))
+    if services:
+        services = functools.reduce(operator.ior, services)
+        providers = list(
+            filter(lambda p: (p.services & services) == services, providers))
+    return render_template(
+        'service_providers.html', providers=providers, **environ)
 
 
 @app.route('/services.html', endpoint='service_providers-alt')
diff -r 9439eb0644f5 -r c474f836438b templates/service_providers.html
--- a/templates/service_providers.html  Wed Sep 14 22:31:47 2022 +0200
+++ b/templates/service_providers.html  Thu Sep 15 00:31:54 2022 +0200
@@ -19,6 +19,34 @@
 
 <section class="section">
     <div class="container">
+        <div class="row mb-4">
+            <div class="btn-group col-7 mx-auto">
+                <a type="button" class="btn btn-primary {% if consulting 
%}active{% endif %}" {% if consulting %}aria-pressed="true"{% endif %} href="{{ 
url_for_self(consulting=(not consulting)|int) }}">
+                    {% if consulting %}
+                    <span class="material-icons">check</span>
+                    {% endif %}
+                    Consulting
+                </a>
+                <a type="button" class="btn btn-primary {% if development 
%}active{% endif %}" {% if development %}aria-pressed="true"{% endif %} 
href="{{ url_for_self(development=(not development)|int) }}">
+                    {% if development %}
+                    <span class="material-icons">check</span>
+                    {% endif %}
+                    Development
+                </a>
+                <a type="button" class="btn btn-primary {% if hosting 
%}active{% endif %}" {% if hosting %}aria-pressed="true"{% endif %} href="{{ 
url_for_self(hosting=(not hosting)|int) }}">
+                    {% if hosting %}
+                    <span class="material-icons">check</span>
+                    {% endif %}
+                    Hosting
+                </a>
+                <a type="button" class="btn btn-primary {% if training 
%}active{% endif %}" {% if training %}aria-pressed="true"{% endif %} href="{{ 
url_for_self(training=(not training)|int) }}">
+                    {% if training %}
+                    <span class="material-icons">check</span>
+                    {% endif %}
+                    Training
+                </a>
+            </div>
+        </div>
         <div class="row row-cols-1 row-cols-md-2 row-cols-xl-4">
             {% for provider in providers %}
             {% include "service_providers/%s.html" % 
provider.name|lower|slugify %}
diff -r 9439eb0644f5 -r c474f836438b templates/service_providers/layout.html
--- a/templates/service_providers/layout.html   Wed Sep 14 22:31:47 2022 +0200
+++ b/templates/service_providers/layout.html   Thu Sep 15 00:31:54 2022 +0200
@@ -7,6 +7,20 @@
         </a>
         <div class="card-body">
             <h2 class="h5 card-title">{{ provider.name }}</h2>
+            <div class="h6 card-subtitle mb-2 text-muted">
+                {% if provider.consulting %}
+                <span class="material-icons" 
title="Consulting">group_work</span>
+                {% endif %}
+                {% if provider.development %}
+                <span class="material-icons" title="Development">api</span>
+                {% endif %}
+                {% if provider.hosting %}
+                <span class="material-icons" title="Hosting">cloud</span>
+                {% endif %}
+                {% if provider.training %}
+                <span class="material-icons" title="Training">school</span>
+                {% endif %}
+            </div>
             <p class="card-text" style="height: 200px; overflow-y: auto;">
             {% block description %}{% endblock %}
             </p>

Reply via email to