Since typeahead.js is easiest to use when the list of strings to match with has been pre-populated, and we're not going to have 1000 proposals or users at any one University's instance of Enable, we are going to pre-populate the list for typeahead.js by making a DB request upon every render_template. Once you finish this, I can implement a global in-memory cache of the Enable users and proposals list, but with little time to build and smaller traffic, this iteration of the search bar can require a DB request per call for now.
Make a function that returns a list of both user.username
along with their user.profile.name
AND proposal.title
, for every user
in User
and for every proposal
in Proposal
. You'd have to put from app.proposal.models import Proposal
and from app.profile.models import User
, and make a DB call. In fact, just read enable/app/proposal/views:12
to see the function I'm talking about.
-
Follow this StackOverflow answer to be able to call this function in the base template
emable/app/templates/base.html
and -
populate a JavaScript array for
typeahead.js
to use (trace the code happening inenable/app/templates/proposal/create.html:46,37,15
to understand what I'm talking about). -
Also figure out a way to put an
<a href
for each proposal and user in the dropdown that's produced by typeahead. -
Put the search box with the
typeahead
class somewhere in the nav element ofbase.html
-
Have a check in the base template for the user permissions (such that anyone logged in can perform the search) AND also that the create/view proposal templates aren't the ones being rendered at this endpoint, because I'm not sure what would happen with multiple typeahead instances in the same template.