Add basic support for Person quickie lookup
shows profile view if person is found
This commit is contained in:
parent
d77de76c97
commit
12eeb5df97
|
@ -15,6 +15,15 @@
|
|||
</b-checkbox>
|
||||
</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"
|
||||
message="Leave blank for default handler.">
|
||||
<b-input name="rattail.people.handler"
|
||||
|
|
|
@ -66,11 +66,29 @@ class CommonView(View):
|
|||
'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()
|
||||
|
||||
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):
|
||||
"""
|
||||
Returns a basic 'robots.txt' response
|
||||
|
|
|
@ -161,6 +161,9 @@ class View(object):
|
|||
response.content_disposition = str('attachment; filename="{}"'.format(filename))
|
||||
return response
|
||||
|
||||
def should_expose_quickie_search(self):
|
||||
return self.expose_quickie_search
|
||||
|
||||
def get_quickie_context(self):
|
||||
return Object(
|
||||
url=self.get_quickie_url(),
|
||||
|
|
|
@ -107,6 +107,22 @@ class CustomerView(MasterView):
|
|||
'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):
|
||||
if not hasattr(self, '_expose_active_in_pos'):
|
||||
self._expose_active_in_pos = self.rattail_config.getbool(
|
||||
|
|
|
@ -79,6 +79,22 @@ class EmployeeView(MasterView):
|
|||
'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):
|
||||
super(EmployeeView, self).configure_grid(g)
|
||||
route_prefix = self.get_route_prefix()
|
||||
|
|
|
@ -478,9 +478,6 @@ 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))
|
||||
|
@ -492,6 +489,30 @@ class MasterView(View):
|
|||
def get_quickie_placeholder(self):
|
||||
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):
|
||||
"""
|
||||
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_label'] = self.get_product_key_label()
|
||||
|
||||
if self.expose_quickie_search:
|
||||
if self.should_expose_quickie_search():
|
||||
context['quickie'] = self.get_quickie_context()
|
||||
|
||||
if self.grid_index:
|
||||
|
|
|
@ -61,6 +61,7 @@ class PersonView(MasterView):
|
|||
bulk_deletable = True
|
||||
is_contact = True
|
||||
supports_autocomplete = True
|
||||
supports_quickie_search = True
|
||||
configurable = True
|
||||
|
||||
labels = {
|
||||
|
@ -429,6 +430,23 @@ class PersonView(MasterView):
|
|||
(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):
|
||||
"""
|
||||
View which exposes the "full profile" for a given person, i.e. all
|
||||
|
@ -1517,6 +1535,9 @@ class PersonView(MasterView):
|
|||
{'section': 'rattail',
|
||||
'option': 'people.straight_to_profile',
|
||||
'type': bool},
|
||||
{'section': 'rattail',
|
||||
'option': 'people.expose_quickie_search',
|
||||
'type': bool},
|
||||
{'section': 'rattail',
|
||||
'option': 'people.handler'},
|
||||
|
||||
|
|
Loading…
Reference in a new issue