From a3ca6abb7a263d57b6ab4370d260ff9e1b8b9089 Mon Sep 17 00:00:00 2001 From: Lance Edgar Date: Mon, 6 May 2019 18:34:42 -0500 Subject: [PATCH] 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 --- tailbone/static/js/tailbone.js | 3 +++ tailbone/templates/base.mako | 9 +++++++++ tailbone/views/master.py | 35 ++++++++++++++++++++++++++++++++++ 3 files changed, 47 insertions(+) diff --git a/tailbone/static/js/tailbone.js b/tailbone/static/js/tailbone.js index 868e0b7b..4d3212df 100644 --- a/tailbone/static/js/tailbone.js +++ b/tailbone/static/js/tailbone.js @@ -220,6 +220,9 @@ $(function() { disable_submit_button(this); }); + // quickie button + $('#submit-quickie').button('option', 'icons', {primary: 'ui-icon-zoomin'}); + /* * enhance dropdowns */ diff --git a/tailbone/templates/base.mako b/tailbone/templates/base.mako index 00e27a60..aea0c0e5 100644 --- a/tailbone/templates/base.mako +++ b/tailbone/templates/base.mako @@ -84,6 +84,15 @@ % endif + % if quickie is not Undefined and quickie and request.has_perm(quickie.perm): +
+ ${h.form(quickie.url, name="quickie", method="get")} + ${h.text('entry', placeholder=quickie.placeholder, autocomplete='off')} + + ${h.end_form()} +
+ % endif +
diff --git a/tailbone/views/master.py b/tailbone/views/master.py index be0a9fc3..516009df 100644 --- a/tailbone/views/master.py +++ b/tailbone/views/master.py @@ -39,6 +39,7 @@ import sqlalchemy_continuum as continuum from rattail.db import model, Session as RattailSession from rattail.db.continuum import model_transaction_query +from rattail.core import Object from rattail.util import prettify from rattail.time import localtime from rattail.threads import Thread @@ -96,6 +97,10 @@ class MasterView(View): supports_prev_next = 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" is_contact = False @@ -378,6 +383,20 @@ class MasterView(View): 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): """ Make and return a new (configured) rows grid instance. @@ -2176,8 +2195,16 @@ class MasterView(View): 'action_url': self.get_action_url, 'grid_index': self.grid_index, '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: 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), 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 if cls.creatable or cls.mobile_creatable: