Add views for PendingProduct model; also DepartmentWidget
This commit is contained in:
parent
7630f504b0
commit
5f9d311cdb
3 changed files with 192 additions and 2 deletions
|
@ -2,7 +2,7 @@
|
|||
################################################################################
|
||||
#
|
||||
# Rattail -- Retail Software Framework
|
||||
# Copyright © 2010-2019 Lance Edgar
|
||||
# Copyright © 2010-2021 Lance Edgar
|
||||
#
|
||||
# This file is part of Rattail.
|
||||
#
|
||||
|
@ -36,6 +36,7 @@ import colander
|
|||
from deform import widget as dfwidget
|
||||
from webhelpers2.html import tags, HTML
|
||||
|
||||
from tailbone.db import Session
|
||||
from tailbone.forms.types import ProductQuantity
|
||||
|
||||
|
||||
|
@ -278,3 +279,30 @@ class JQueryAutocompleteWidget(dfwidget.AutocompleteInputWidget):
|
|||
tmpl_values = self.get_template_values(field, cstruct, kw)
|
||||
template = readonly and self.readonly_template or self.template
|
||||
return field.renderer(template, **tmpl_values)
|
||||
|
||||
|
||||
class DepartmentWidget(dfwidget.SelectWidget):
|
||||
"""
|
||||
Custom select widget for a Department reference field.
|
||||
|
||||
Constructor accepts the normal ``values`` kwarg but if not
|
||||
provided then the widget will fetch department list from Rattail
|
||||
DB.
|
||||
|
||||
Constructor also accepts ``required`` kwarg, which defaults to
|
||||
true unless specified.
|
||||
"""
|
||||
|
||||
def __init__(self, request, **kwargs):
|
||||
|
||||
if 'values' not in kwargs:
|
||||
model = request.rattail_config.get_model()
|
||||
departments = Session.query(model.Department)\
|
||||
.order_by(model.Department.number)
|
||||
values = [(dept.uuid, six.text_type(dept))
|
||||
for dept in departments]
|
||||
if not kwargs.pop('required', True):
|
||||
values.insert(0, ('', "(none)"))
|
||||
kwargs['values'] = values
|
||||
|
||||
super(DepartmentWidget, self).__init__(**kwargs)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue