]> git.ipfire.org Git - ipfire.org.git/commitdiff
dbl: Refactor how we show search results
authorMichael Tremer <michael.tremer@ipfire.org>
Sat, 24 Jan 2026 16:18:39 +0000 (16:18 +0000)
committerMichael Tremer <michael.tremer@ipfire.org>
Sat, 24 Jan 2026 16:24:58 +0000 (16:24 +0000)
Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
Makefile.am
src/templates/dbl/search-not-found.html [new file with mode: 0644]
src/templates/dbl/search.html
src/web/dbl.py

index 0760ef6045dbc65b7e3850948ede5e4f3815e686..175cafde4eb4a08dcfb7444723a35b519839e6eb 100644 (file)
@@ -192,7 +192,8 @@ templates_blog_modulesdir = $(templates_blogdir)/modules
 
 templates_dbl_DATA = \
        src/templates/dbl/index.html \
-       src/templates/dbl/search.html
+       src/templates/dbl/search.html \
+       src/templates/dbl/search-not-found.html
 
 templates_dbldir = $(templatesdir)/dbl
 
diff --git a/src/templates/dbl/search-not-found.html b/src/templates/dbl/search-not-found.html
new file mode 100644 (file)
index 0000000..0855dd4
--- /dev/null
@@ -0,0 +1,26 @@
+{% extends "../base.html" %}
+
+{% block head %}
+       {% module OpenGraph(
+               title=_("IPFire DBL - Search Results For: %s") % q,
+       ) %}
+{% end block %}
+
+{% block title %}{{ _("Search Results For: %s") % q }}{% end block %}
+
+{% block container %}
+       <section class="hero is-fullheight-with-navbar">
+               <div class="hero-body">
+                       <div class="container">
+                               <h1 class="title">
+                                       {{ _("Sorry, we could not find anything for %s") % q }}
+                               </h1>
+
+                               {# Suggest to report if it is a valid domain #}
+                               {% if valid_fqdn %}
+                                       {% module DBLSubmitReport(q) %}
+                               {% end %}
+                       </div>
+               </div>
+       </section>
+{% end block %}
index d0101c9621140b655d5c7e1f7b356fde6f6615f4..0948df30cf6bcad3e661e78c07e86759288f782b 100644 (file)
@@ -9,73 +9,42 @@
 {% block title %}{{ _("Search Results For: %s") % q }}{% end block %}
 
 {% block container %}
-       <section class="hero is-dark">
+       <section class="hero is-fullheight-with-navbar">
                <div class="hero-body">
                        <div class="container">
-                               <h1 class="title">
-                                       {{ _("Search Results For: %s") % q }}
-                               </h1>
-                       </div>
-               </div>
-       </section>
+                               <div class="columns is-centered">
+                                       <div class="column is-half">
+                                               <article class="panel is-primary">
+                                                       <p class="panel-heading">
+                                                               {{ format_domain(q) }}
+                                                       </p>
 
-       <section class="section">
-               <div class="container">
-                       {# Show any results #}
-                       {% if results %}
-                               {% for list, result in sorted(results.items()) %}
-                                       <div class="block">
-                                               <h5 class="title is-5">
-                                                       <a href="/dbl/lists/{{ list.slug }}">
-                                                               {{ list }}
-                                                       </a>
-                                               </h5>
+                                                       {% for list in sorted(lists) %}
+                                                               {% set result = results.get(list) %}
 
-                                               <div class="content">
-                                                       {% if result.status == "ALLOWED" %}
-                                                               <p>
-                                                                       <span class="icon-text">
-                                                                               <span class="icon has-text-success">
-                                                                                       <i class="fas fa-check"></i>
-                                                                               </span>
-                                                                               <span>
-                                                                                       <a href="/dbl/lists/{{ list.slug }}/domains/{{ result.domain }}">
-                                                                                               {{ _("%s is currently allowed") % format_domain(result.domain) }}
-                                                                                       </a>
+                                                               <a class="panel-block is-justify-content-space-between" href="/dbl/lists/{{ list.slug }}/domains/{{ q }}">
+                                                                       {{ list }}
+
+                                                                       {% if result is None %}
+                                                                               <span class="tag">
+                                                                                       {{ _("Not Listed") }}
                                                                                </span>
-                                                                       </span>
-                                                               </p>
-                                                       {% elif result.status == "BLOCKED" %}
-                                                               <p>
-                                                                       <span class="icon-text">
-                                                                               <span class="icon has-text-danger">
-                                                                                       <i class="fas fa-x"></i>
+
+                                                                       {% elif result.status == "ALLOWED" %}
+                                                                               <span class="tag is-success">
+                                                                                       {{ _("Allowed") }}
                                                                                </span>
-                                                                               <span>
-                                                                                       <a href="/dbl/lists/{{ list.slug }}/domains/{{ result.domain }}">
-                                                                                               {{ _("%s is currently blocked") % format_domain(result.domain) }}
-                                                                                       </a>
+                                                                       {% elif result.status == "BLOCKED" %}
+                                                                               <span class="tag is-danger">
+                                                                                       {{ _("Blocked") }}
                                                                                </span>
-                                                                       </span>
-                                                               </p>
+                                                                       {% end %}
+                                                               </a>
                                                        {% end %}
-                                               </div>
+                                               </article>
                                        </div>
-                               {% end %}
-
-                       {# Show a note if there has been no results #}
-                       {% else %}
-                               <div class="content has-text-centered">
-                                       <p>
-                                               {{ _("There are no matches for '%s'") % q }}
-                                       </p>
                                </div>
-
-                               {# If the query has been a valid FQDN, we encourage users to report it #}
-                               {% if results == {} %}
-                                       {% module DBLSubmitReport(name=q) %}
-                               {% end %}
-                       {% end %}
+                       </div>
                </div>
        </section>
 {% end block %}
index 543bab6c32cd4fc9ec12540737ca5772032acabe..0f48c3bc24369d1f06354d1059b41f88721b6550 100644 (file)
@@ -159,12 +159,24 @@ class SearchHandler(base.AnalyticsMixin, BaseHandler):
                try:
                        results = await self.backend.dbl.search(q)
 
+                       # Raise an exception if nothing was found
+                       if not results:
+                               raise FileNotFoundError(q)
+
                # ValueError is raised if the query has not been a valid FQDN
                except ValueError as e:
-                       results = None
+                       self.render("dbl/search-not-found.html", q=q, valid_fqdn=False)
+
+               # FileNotFoundError is raised if nothing was found
+               except FileNotFoundError as e:
+                       self.render("dbl/search-not-found.html", q=q, valid_fqdn=True)
 
                # Render the page
-               self.render("dbl/search.html", q=q, results=results)
+               else:
+                       # Fetch all lists
+                       lists = await self.backend.dbl.get_lists()
+
+                       self.render("dbl/search.html", q=q, lists=lists, results=results)
 
 
 class ListsModule(ui_modules.UIModule):