From: Ed Bartosh <ed.bartosh@linux.intel.com>
To: bitbake-devel@lists.openembedded.org
Subject: [PATCH 04/12] bitbake: toastergui: widgets Add a typeahead widget
Date: Tue, 4 Aug 2015 22:46:32 +0300 [thread overview]
Message-ID: <ee301b98eb6fb31497e41276a95ffa49aa5daa48.1438717072.git.ed.bartosh@linux.intel.com> (raw)
In-Reply-To: <691696f2b87d41540b14b10ef08762f8529b4909.1438717072.git.ed.bartosh@linux.intel.com>
In-Reply-To: <cover.1438717072.git.ed.bartosh@linux.intel.com>
From: Michael Wood <michael.g.wood@intel.com>
The typeahead behaviour is significantly different from searching in a
table so we need a separate widget to do this.
[YOCTO #7152]
Signed-off-by: Michael Wood <michael.g.wood@intel.com>
Signed-off-by: Ed Bartosh <ed.bartosh@linux.intel.com>
---
lib/toaster/toastergui/widgets.py | 52 +++++++++++++++++++++++++++++++++++++++
1 file changed, 52 insertions(+)
diff --git a/lib/toaster/toastergui/widgets.py b/lib/toaster/toastergui/widgets.py
index 0885402..2adf574 100644
--- a/lib/toaster/toastergui/widgets.py
+++ b/lib/toaster/toastergui/widgets.py
@@ -354,3 +354,55 @@ class ToasterTemplateView(TemplateView):
content_type = "application/json; charset=utf-8")
return super(ToasterTemplateView, self).get(*args, **kwargs)
+
+class ToasterTypeAhead(View):
+ """ A typeahead mechanism to support the front end typeahead widgets """
+ MAX_RESULTS = 6
+
+ class MissingFieldsException(Exception):
+ pass
+
+ def __init__(self, *args, **kwargs):
+ super(ToasterTypeAhead, self).__init__()
+
+ def get(self, request, *args, **kwargs):
+ def response(data):
+ return HttpResponse(json.dumps(data,
+ indent=2,
+ cls=DjangoJSONEncoder),
+ content_type="application/json")
+
+ error = "ok"
+
+ search_term = request.GET.get("search", None)
+ if search_term == None:
+ # We got no search value so return empty reponse
+ return response({'error' : error , 'results': []})
+
+ try:
+ prj = Project.objects.get(pk=kwargs['pid'])
+ except KeyError:
+ prj = None
+
+ results = self.apply_search(search_term, prj, request)[:ToasterTypeAhead.MAX_RESULTS]
+
+ if len(results) > 0:
+ try:
+ self.validate_fields(results[0])
+ except MissingFieldsException as e:
+ error = e
+
+ data = { 'results' : results,
+ 'error' : error,
+ }
+
+ return response(data)
+
+ def validate_fields(self, result):
+ if 'name' in result == False or 'detail' in result == False:
+ raise MissingFieldsException("name and detail are required fields")
+
+ def apply_search(self, search_term, prj):
+ """ Override this function to implement search. Return an array of
+ dictionaries with a minium of a name and detail field"""
+ pass
--
2.1.4
next prev parent reply other threads:[~2015-08-04 19:47 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-08-04 19:45 [PATCH 00/12] toaster: bring back the correct typeahead behaviour as a modular widget Ed Bartosh
2015-08-04 19:46 ` [PATCH 01/12] bitbake: toaster: orm Add util function to return the url to layerversion Ed Bartosh
2015-08-04 19:46 ` [PATCH 02/12] bitbake: toaster: orm Add util functions to return common querysets Ed Bartosh
2015-08-04 19:46 ` [PATCH 03/12] bitbake: toastergui: tables Use util functions for the " Ed Bartosh
2015-08-04 19:46 ` Ed Bartosh [this message]
2015-08-04 19:46 ` [PATCH 05/12] bitbake: toastergui: Add typeaheads layers, machines, projects, recipes Ed Bartosh
2015-08-04 19:46 ` [PATCH 06/12] bitbake: toastergui: Switch to using the new toaster typeahead widget Ed Bartosh
2015-08-04 19:46 ` [PATCH 07/12] bitbake: toastergui: libtoaster Throw an exception no url is specified Ed Bartosh
2015-08-04 19:46 ` [PATCH 08/12] bitbake: toasterui: views Remove unused xhr_typeahead view definition Ed Bartosh
2015-08-04 19:46 ` [PATCH 09/12] bitbake: toastergui: views Standardise the fields project layer response Ed Bartosh
2015-08-04 19:46 ` [PATCH 10/12] bitbake: toastergui: tests Fix and more comprehensive typeahead unittest Ed Bartosh
2015-08-04 19:46 ` [PATCH 11/12] bitbake: toastergui: libtoaster: typeahead resiliency for slow server Ed Bartosh
2015-08-04 19:46 ` [PATCH 12/12] bitbake: toastergui: libtoaster typeahead Add in results highlighter Ed Bartosh
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=ee301b98eb6fb31497e41276a95ffa49aa5daa48.1438717072.git.ed.bartosh@linux.intel.com \
--to=ed.bartosh@linux.intel.com \
--cc=bitbake-devel@lists.openembedded.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox