From: Michael Tremer Date: Sat, 24 Jan 2026 16:18:39 +0000 (+0000) Subject: dbl: Refactor how we show search results X-Git-Url: http://git.ipfire.org/gitweb/?a=commitdiff_plain;h=2e382187148693dcc01357919312224af4875e90;p=ipfire.org.git dbl: Refactor how we show search results Signed-off-by: Michael Tremer --- diff --git a/Makefile.am b/Makefile.am index 0760ef60..175cafde 100644 --- a/Makefile.am +++ b/Makefile.am @@ -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 index 00000000..0855dd48 --- /dev/null +++ b/src/templates/dbl/search-not-found.html @@ -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 %} +
+
+
+

+ {{ _("Sorry, we could not find anything for %s") % q }} +

+ + {# Suggest to report if it is a valid domain #} + {% if valid_fqdn %} + {% module DBLSubmitReport(q) %} + {% end %} +
+
+
+{% end block %} diff --git a/src/templates/dbl/search.html b/src/templates/dbl/search.html index d0101c96..0948df30 100644 --- a/src/templates/dbl/search.html +++ b/src/templates/dbl/search.html @@ -9,73 +9,42 @@ {% block title %}{{ _("Search Results For: %s") % q }}{% end block %} {% block container %} -
+
-

- {{ _("Search Results For: %s") % q }} -

-
-
-
+
+
+
+

+ {{ format_domain(q) }} +

-
-
- {# Show any results #} - {% if results %} - {% for list, result in sorted(results.items()) %} -
- {% end %} - - {# Show a note if there has been no results #} - {% else %} -
-

- {{ _("There are no matches for '%s'") % q }} -

- - {# If the query has been a valid FQDN, we encourage users to report it #} - {% if results == {} %} - {% module DBLSubmitReport(name=q) %} - {% end %} - {% end %} +
{% end block %} diff --git a/src/web/dbl.py b/src/web/dbl.py index 543bab6c..0f48c3bc 100644 --- a/src/web/dbl.py +++ b/src/web/dbl.py @@ -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):