Add basic support for "quickie" search

a master view can "support" quickie search, which means it will setup a route
suitable for the quickie search form action.  and/or it can "expose" quickie
search which means it will actually show a quickie search form on its views
This commit is contained in:
Lance Edgar 2019-05-06 18:34:42 -05:00
parent 35158204c5
commit a3ca6abb7a
3 changed files with 47 additions and 0 deletions

View file

@ -220,6 +220,9 @@ $(function() {
disable_submit_button(this); disable_submit_button(this);
}); });
// quickie button
$('#submit-quickie').button('option', 'icons', {primary: 'ui-icon-zoomin'});
/* /*
* enhance dropdowns * enhance dropdowns
*/ */

View file

@ -84,6 +84,15 @@
</div> </div>
% endif % endif
% if quickie is not Undefined and quickie and request.has_perm(quickie.perm):
<div class="after-feedback">
${h.form(quickie.url, name="quickie", method="get")}
${h.text('entry', placeholder=quickie.placeholder, autocomplete='off')}
<button type="submit" id="submit-quickie">Lookup</button>
${h.end_form()}
</div>
% endif
</div><!-- global --> </div><!-- global -->
<div class="page"> <div class="page">

View file

@ -39,6 +39,7 @@ import sqlalchemy_continuum as continuum
from rattail.db import model, Session as RattailSession from rattail.db import model, Session as RattailSession
from rattail.db.continuum import model_transaction_query from rattail.db.continuum import model_transaction_query
from rattail.core import Object
from rattail.util import prettify from rattail.util import prettify
from rattail.time import localtime from rattail.time import localtime
from rattail.threads import Thread from rattail.threads import Thread
@ -96,6 +97,10 @@ class MasterView(View):
supports_prev_next = False supports_prev_next = False
supports_import_batch_from_file = False supports_import_batch_from_file = False
# quickie (search)
supports_quickie_search = False
expose_quickie_search = False
# set to True to declare model as "contact" # set to True to declare model as "contact"
is_contact = False is_contact = False
@ -378,6 +383,20 @@ class MasterView(View):
the given object, or ``None``. the given object, or ``None``.
""" """
def quickie(self):
raise NotImplementedError
def get_quickie_url(self):
route_prefix = self.get_route_prefix()
return self.request.route_url('{}.quickie'.format(route_prefix))
def get_quickie_perm(self):
permission_prefix = self.get_permission_prefix()
return '{}.quickie'.format(permission_prefix)
def get_quickie_placeholder(self):
pass
def make_row_grid(self, factory=None, key=None, data=None, columns=None, **kwargs): def make_row_grid(self, factory=None, key=None, data=None, columns=None, **kwargs):
""" """
Make and return a new (configured) rows grid instance. Make and return a new (configured) rows grid instance.
@ -2176,8 +2195,16 @@ class MasterView(View):
'action_url': self.get_action_url, 'action_url': self.get_action_url,
'grid_index': self.grid_index, 'grid_index': self.grid_index,
'help_url': self.get_help_url(), 'help_url': self.get_help_url(),
'quickie': None,
} }
if self.expose_quickie_search:
context['quickie'] = Object(
url=self.get_quickie_url(),
perm=self.get_quickie_perm(),
placeholder=self.get_quickie_placeholder(),
)
if self.grid_index: if self.grid_index:
context['grid_count'] = self.grid_count context['grid_count'] = self.grid_count
@ -3342,6 +3369,14 @@ class MasterView(View):
config.add_view(cls, attr='results_xlsx', route_name='{}.results_xlsx'.format(route_prefix), config.add_view(cls, attr='results_xlsx', route_name='{}.results_xlsx'.format(route_prefix),
permission='{}.results_xlsx'.format(permission_prefix)) permission='{}.results_xlsx'.format(permission_prefix))
# quickie (search)
if cls.supports_quickie_search:
config.add_tailbone_permission(permission_prefix, '{}.quickie'.format(permission_prefix),
"Do a \"quickie search\" for {}".format(model_title_plural))
config.add_route('{}.quickie'.format(route_prefix), '{}/quickie'.format(route_prefix),
request_method='GET')
config.add_view(cls, attr='quickie', route_name='{}.quickie'.format(route_prefix),
permission='{}.quickie'.format(permission_prefix))
# create # create
if cls.creatable or cls.mobile_creatable: if cls.creatable or cls.mobile_creatable: