Refactor mobile receiving to use "quick row" feature
plus some other random things thrown in there, for good measure..
This commit is contained in:
parent
3cc8adba86
commit
a34a42d2b2
9 changed files with 177 additions and 156 deletions
|
@ -717,6 +717,15 @@ class MasterView(View):
|
|||
def process_uploads(self, obj, form, uploads):
|
||||
pass
|
||||
|
||||
def render_product_key_value(self, obj):
|
||||
"""
|
||||
Render the "canonical" product key value for the given object.
|
||||
"""
|
||||
product_key = self.rattail_config.product_key()
|
||||
if product_key == 'upc':
|
||||
return obj.upc.pretty() if obj.upc else ''
|
||||
return getattr(obj, product_key)
|
||||
|
||||
def before_create_flush(self, obj, form):
|
||||
pass
|
||||
|
||||
|
@ -1060,24 +1069,36 @@ class MasterView(View):
|
|||
defaults.update(kwargs)
|
||||
return defaults
|
||||
|
||||
def configure_mobile_form(self, form):
|
||||
def configure_common_form(self, form):
|
||||
"""
|
||||
Configure the primary mobile form.
|
||||
Configure the form in whatever way is deemed "common" - i.e. where
|
||||
configuration should be done the same for desktop and mobile.
|
||||
|
||||
By default this removes the 'uuid' field (if present), sets any primary
|
||||
key fields to be readonly (if we have a :attr:`model_class` and are in
|
||||
edit mode), and sets labels as defined by the master class hierarchy.
|
||||
"""
|
||||
# TODO: is any of this stuff from configure_form() needed?
|
||||
# if self.editing:
|
||||
# model_class = self.get_model_class(error=False)
|
||||
# if model_class:
|
||||
# mapper = orm.class_mapper(model_class)
|
||||
# for key in mapper.primary_key:
|
||||
# for field in form.fields:
|
||||
# if field == key.name:
|
||||
# form.set_readonly(field)
|
||||
# break
|
||||
# form.remove_field('uuid')
|
||||
form.remove_field('uuid')
|
||||
|
||||
if self.editing:
|
||||
model_class = self.get_model_class(error=False)
|
||||
if model_class:
|
||||
# set readonly for all primary key fields
|
||||
mapper = orm.class_mapper(model_class)
|
||||
for key in mapper.primary_key:
|
||||
for field in form.fields:
|
||||
if field == key.name:
|
||||
form.set_readonly(field)
|
||||
break
|
||||
|
||||
self.set_labels(form)
|
||||
|
||||
def configure_mobile_form(self, form):
|
||||
"""
|
||||
Configure the main "mobile" form for the view's data model.
|
||||
"""
|
||||
self.configure_common_form(form)
|
||||
|
||||
def validate_mobile_form(self, form):
|
||||
controls = self.request.POST.items()
|
||||
try:
|
||||
|
@ -1832,17 +1853,14 @@ class MasterView(View):
|
|||
context['row_model_title_plural'] = self.get_row_model_title_plural()
|
||||
context['row_action_url'] = self.get_row_action_url
|
||||
|
||||
if mobile:
|
||||
if mobile and self.viewing and self.mobile_rows_quickable:
|
||||
|
||||
if self.mobile_rows_creatable:
|
||||
context['add_item_title'] = "Add Record"
|
||||
# quick row does *not* mimic keyboard wedge by default, but can
|
||||
context['quick_row_keyboard_wedge'] = False
|
||||
|
||||
if self.mobile_rows_quickable:
|
||||
context['quick_row_entry_placeholder'] = "Enter search text"
|
||||
|
||||
# quick row does *not* use autocomplete by default
|
||||
context['quick_row_autocomplete'] = False
|
||||
context['quick_row_autocomplete_url'] = '#'
|
||||
# quick row does *not* use autocomplete by default, but can
|
||||
context['quick_row_autocomplete'] = False
|
||||
context['quick_row_autocomplete_url'] = '#'
|
||||
|
||||
context.update(data)
|
||||
context.update(self.template_kwargs(**context))
|
||||
|
@ -2366,22 +2384,9 @@ class MasterView(View):
|
|||
|
||||
def configure_form(self, form):
|
||||
"""
|
||||
Configure the primary form. By default this just sets any primary key
|
||||
fields to be readonly (if we have a :attr:`model_class`).
|
||||
Configure the main "desktop" form for the view's data model.
|
||||
"""
|
||||
if self.editing:
|
||||
model_class = self.get_model_class(error=False)
|
||||
if model_class:
|
||||
mapper = orm.class_mapper(model_class)
|
||||
for key in mapper.primary_key:
|
||||
for field in form.fields:
|
||||
if field == key.name:
|
||||
form.set_readonly(field)
|
||||
break
|
||||
|
||||
form.remove_field('uuid')
|
||||
|
||||
self.set_labels(form)
|
||||
self.configure_common_form(form)
|
||||
|
||||
def validate_form(self, form):
|
||||
if form.validate(newstyle=True):
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue