All of lore.kernel.org
 help / color / mirror / Atom feed
From: Amanda Brindle <amanda.r.brindle@intel.com>
To: yocto@yoctoproject.org
Cc: paul.eggleton@linux.intel.com,
	Amanda Brindle <amanda.r.brindle@intel.com>
Subject: [layerindex-web][patch v2 1/1] recipes.html: Require keyword for recipe search
Date: Mon,  6 Nov 2017 16:21:23 -0800	[thread overview]
Message-ID: <cf75876e6a0b6df11656989ff729f2d4fdaaf5fb.1510013944.git.amanda.r.brindle@intel.com> (raw)
In-Reply-To: <cover.1510013944.git.amanda.r.brindle@intel.com>

Use JavaScript to check if the search box for recipe search is
empty before querying the database. This will prevent the "502
Bad Gateway" error that occurs when the query takes too long due
to the large list of recipes.

Add a browse button for the Machines and Distros pages.

Fixes [YOCTO #11930]

Signed-off-by: Amanda Brindle <amanda.r.brindle@intel.com>
---
 layerindex/views.py                | 10 ++++++++--
 templates/layerindex/distros.html  |  3 ++-
 templates/layerindex/machines.html |  3 ++-
 templates/layerindex/recipes.html  | 12 +++++++++++-
 4 files changed, 23 insertions(+), 5 deletions(-)

diff --git a/layerindex/views.py b/layerindex/views.py
index 3b22067..9b5d505 100644
--- a/layerindex/views.py
+++ b/layerindex/views.py
@@ -656,7 +656,10 @@ class MachineSearchView(ListView):
 
     def get_queryset(self):
         _check_url_branch(self.kwargs)
-        query_string = self.request.GET.get('q', '')
+        if self.request.GET.get('search', ''):
+            query_string = self.request.GET.get('q', '')
+        else:
+            query_string = ""
         init_qs = Machine.objects.filter(layerbranch__branch__name=self.kwargs['branch'])
         if query_string.strip():
             entry_query = simplesearch.get_query(query_string, ['name', 'description'])
@@ -705,7 +708,10 @@ class DistroSearchView(ListView):
 
     def get_queryset(self):
         _check_url_branch(self.kwargs)
-        query_string = self.request.GET.get('q', '')
+        if self.request.GET.get('search', ''):
+            query_string = self.request.GET.get('q', '')
+        else:
+            query_string = ""
         init_qs = Distro.objects.filter(layerbranch__branch__name=self.kwargs['branch'])
         if query_string.strip():
             entry_query = simplesearch.get_query(query_string, ['name', 'description'])
diff --git a/templates/layerindex/distros.html b/templates/layerindex/distros.html
index 7085584..34b5419 100644
--- a/templates/layerindex/distros.html
+++ b/templates/layerindex/distros.html
@@ -34,7 +34,8 @@
                     <div class="input-append">
                         <form id="filter-form" action="{% url 'distro_search' url_branch %}" method="get">
                             <input type="text" class="input-xxlarge" id="appendedInputButtons" placeholder="Search distros" name="q" value="{{ search_keyword }}" />
-                            <button class="btn" type="submit">search</button>
+                            <button class="btn" type="submit" name="search" value="1">search</button>
+                            <button class="btn" type="submit" name="browse" value="1">browse</button>
                         </form>
                     </div>
                 </div>
diff --git a/templates/layerindex/machines.html b/templates/layerindex/machines.html
index 2a9f947..d91228a 100644
--- a/templates/layerindex/machines.html
+++ b/templates/layerindex/machines.html
@@ -33,7 +33,8 @@
                     <div class="input-append">
                         <form id="filter-form" action="{% url 'machine_search' url_branch %}" method="get">
                             <input type="text" class="input-xxlarge" id="appendedInputButtons" placeholder="Search machines" name="q" value="{{ search_keyword }}" />
-                            <button class="btn" type="submit">search</button>
+                            <button class="btn" type="submit" name="search" value="1">search</button>
+                            <button class="btn" type="submit" name="browse" value="1">browse</button>
                         </form>
                     </div>
                 </div>
diff --git a/templates/layerindex/recipes.html b/templates/layerindex/recipes.html
index 60a2667..28f3f55 100644
--- a/templates/layerindex/recipes.html
+++ b/templates/layerindex/recipes.html
@@ -32,13 +32,14 @@
 
                 <div class="row-fluid">
                     <div class="input-append">
-                        <form id="filter-form" action="{% url 'recipe_search' url_branch %}" method="get">
+                        <form id="filter-form" action="{% url 'recipe_search' url_branch %}" method="get" onsubmit="return validate()">
                             <input type="text" class="input-xxlarge" id="appendedInputButtons" placeholder="Search recipes" name="q" value="{{ search_keyword }}" />
                             <button class="btn" type="submit">search</button>
                         </form>
                     </div>
                 </div>
 
+                <div id="error"> </div>
 {% if recipe_list %}
                 <table class="table table-striped table-bordered recipestable">
                     <thead>
@@ -87,5 +88,14 @@
         $('.icon-hdd').tooltip({title:"Inherits image"});
         $('.label-inverse').tooltip();
     });
+
+    function validate(){
+        if (!$("#appendedInputButtons").val()){
+            $("#error").html("<error>Recipe search cannot be blank</error>");
+            $("error").addClass("control-group alert alert-error");
+            return false;
+        }
+    }
+
 </script>
 {% endblock %}
-- 
2.7.4



  reply	other threads:[~2017-11-07  0:21 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-11-07  0:21 [layerindex-web][patch v2 0/1] recipes.html: Require keyword for recipe search Amanda Brindle
2017-11-07  0:21 ` Amanda Brindle [this message]
2017-11-07  7:27   ` [layerindex-web][patch v2 1/1] " Paul Eggleton
2017-11-07  7:42     ` Paul Eggleton

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=cf75876e6a0b6df11656989ff729f2d4fdaaf5fb.1510013944.git.amanda.r.brindle@intel.com \
    --to=amanda.r.brindle@intel.com \
    --cc=paul.eggleton@linux.intel.com \
    --cc=yocto@yoctoproject.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.