Add basic support for Person quickie lookup

shows profile view if person is found
This commit is contained in:
Lance Edgar 2023-06-17 15:11:13 -05:00
parent d77de76c97
commit 12eeb5df97
7 changed files with 109 additions and 5 deletions

View file

@ -15,6 +15,15 @@
</b-checkbox> </b-checkbox>
</b-field> </b-field>
<b-field message="Allows quick profile lookup using e.g. customer number.">
<b-checkbox name="rattail.people.expose_quickie_search"
v-model="simpleSettings['rattail.people.expose_quickie_search']"
native-value="true"
@input="settingsNeedSaved = true">
Show "quickie search" lookup
</b-checkbox>
</b-field>
<b-field label="People Handler" <b-field label="People Handler"
message="Leave blank for default handler."> message="Leave blank for default handler.">
<b-input name="rattail.people.handler" <b-input name="rattail.people.handler"

View file

@ -66,11 +66,29 @@ class CommonView(View):
'help_url': global_help_url(self.rattail_config), 'help_url': global_help_url(self.rattail_config),
} }
if self.expose_quickie_search: if self.should_expose_quickie_search():
context['quickie'] = self.get_quickie_context() context['quickie'] = self.get_quickie_context()
return context return context
# nb. this is only invoked from home() view
def should_expose_quickie_search(self):
if self.expose_quickie_search:
return True
# TODO: for now we are assuming *people* search
app = self.get_rattail_app()
return app.get_people_handler().should_expose_quickie_search()
def get_quickie_perm(self):
return 'people.quickie'
def get_quickie_url(self):
return self.request.route_url('people.quickie')
def get_quickie_placeholder(self):
app = self.get_rattail_app()
return app.get_people_handler().get_quickie_search_placeholder()
def robots_txt(self): def robots_txt(self):
""" """
Returns a basic 'robots.txt' response Returns a basic 'robots.txt' response

View file

@ -161,6 +161,9 @@ class View(object):
response.content_disposition = str('attachment; filename="{}"'.format(filename)) response.content_disposition = str('attachment; filename="{}"'.format(filename))
return response return response
def should_expose_quickie_search(self):
return self.expose_quickie_search
def get_quickie_context(self): def get_quickie_context(self):
return Object( return Object(
url=self.get_quickie_url(), url=self.get_quickie_url(),

View file

@ -107,6 +107,22 @@ class CustomerView(MasterView):
'name', 'name',
] ]
def should_expose_quickie_search(self):
if self.expose_quickie_search:
return True
app = self.get_rattail_app()
return app.get_people_handler().should_expose_quickie_search()
def get_quickie_perm(self):
return 'people.quickie'
def get_quickie_url(self):
return self.request.route_url('people.quickie')
def get_quickie_placeholder(self):
app = self.get_rattail_app()
return app.get_people_handler().get_quickie_search_placeholder()
def get_expose_active_in_pos(self): def get_expose_active_in_pos(self):
if not hasattr(self, '_expose_active_in_pos'): if not hasattr(self, '_expose_active_in_pos'):
self._expose_active_in_pos = self.rattail_config.getbool( self._expose_active_in_pos = self.rattail_config.getbool(

View file

@ -79,6 +79,22 @@ class EmployeeView(MasterView):
'departments', 'departments',
] ]
def should_expose_quickie_search(self):
if self.expose_quickie_search:
return True
app = self.get_rattail_app()
return app.get_people_handler().should_expose_quickie_search()
def get_quickie_perm(self):
return 'people.quickie'
def get_quickie_url(self):
return self.request.route_url('people.quickie')
def get_quickie_placeholder(self):
app = self.get_rattail_app()
return app.get_people_handler().get_quickie_search_placeholder()
def configure_grid(self, g): def configure_grid(self, g):
super(EmployeeView, self).configure_grid(g) super(EmployeeView, self).configure_grid(g)
route_prefix = self.get_route_prefix() route_prefix = self.get_route_prefix()

View file

@ -478,9 +478,6 @@ class MasterView(View):
the given object, or ``None``. the given object, or ``None``.
""" """
def quickie(self):
raise NotImplementedError
def get_quickie_url(self): def get_quickie_url(self):
route_prefix = self.get_route_prefix() route_prefix = self.get_route_prefix()
return self.request.route_url('{}.quickie'.format(route_prefix)) return self.request.route_url('{}.quickie'.format(route_prefix))
@ -492,6 +489,30 @@ class MasterView(View):
def get_quickie_placeholder(self): def get_quickie_placeholder(self):
pass pass
def quickie(self):
"""
Quickie search - tries to do a simple lookup based on a key
value. If a record is found, user is redirected to its view.
"""
entry = self.request.params.get('entry', '').strip()
if not entry:
self.request.session.flash("No search criteria specified", 'error')
return self.redirect(self.request.get_referrer())
obj = self.do_quickie_lookup(entry)
if not obj:
model_title = self.get_model_title()
self.request.session.flash(f"{model_title} not found: {entry}", 'error')
return self.redirect(self.request.get_referrer())
return self.redirect(self.get_quickie_result_url(obj))
def do_quickie_lookup(self, entry):
pass
def get_quickie_result_url(self, obj):
return self.get_action_url('view', obj)
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.
@ -2422,7 +2443,7 @@ class MasterView(View):
context['product_key_field'] = self.get_product_key_field() context['product_key_field'] = self.get_product_key_field()
context['product_key_label'] = self.get_product_key_label() context['product_key_label'] = self.get_product_key_label()
if self.expose_quickie_search: if self.should_expose_quickie_search():
context['quickie'] = self.get_quickie_context() context['quickie'] = self.get_quickie_context()
if self.grid_index: if self.grid_index:

View file

@ -61,6 +61,7 @@ class PersonView(MasterView):
bulk_deletable = True bulk_deletable = True
is_contact = True is_contact = True
supports_autocomplete = True supports_autocomplete = True
supports_quickie_search = True
configurable = True configurable = True
labels = { labels = {
@ -429,6 +430,23 @@ class PersonView(MasterView):
(model.VendorContact, 'person_uuid'), (model.VendorContact, 'person_uuid'),
] ]
def should_expose_quickie_search(self):
if self.expose_quickie_search:
return True
app = self.get_rattail_app()
return app.get_people_handler().should_expose_quickie_search()
def do_quickie_lookup(self, entry):
app = self.get_rattail_app()
return app.get_people_handler().quickie_lookup(entry, self.Session())
def get_quickie_placeholder(self):
app = self.get_rattail_app()
return app.get_people_handler().get_quickie_search_placeholder()
def get_quickie_result_url(self, person):
return self.get_action_url('view_profile', person)
def view_profile(self): def view_profile(self):
""" """
View which exposes the "full profile" for a given person, i.e. all View which exposes the "full profile" for a given person, i.e. all
@ -1517,6 +1535,9 @@ class PersonView(MasterView):
{'section': 'rattail', {'section': 'rattail',
'option': 'people.straight_to_profile', 'option': 'people.straight_to_profile',
'type': bool}, 'type': bool},
{'section': 'rattail',
'option': 'people.expose_quickie_search',
'type': bool},
{'section': 'rattail', {'section': 'rattail',
'option': 'people.handler'}, 'option': 'people.handler'},