Tweak some field renderers for sake of product view

This commit is contained in:
Lance Edgar 2016-12-14 23:27:45 -06:00
parent ef649d8c96
commit d40d5e3f6b
4 changed files with 36 additions and 22 deletions

View file

@ -41,7 +41,7 @@ from .employees import EmployeeFieldRenderer
from .stores import StoreFieldRenderer from .stores import StoreFieldRenderer
from .vendors import VendorFieldRenderer, PurchaseFieldRenderer from .vendors import VendorFieldRenderer, PurchaseFieldRenderer
from .products import (GPCFieldRenderer, DepartmentFieldRenderer, BrandFieldRenderer, from .products import (GPCFieldRenderer, DepartmentFieldRenderer, SubdepartmentFieldRenderer, CategoryFieldRenderer,
ProductFieldRenderer, PriceFieldRenderer, PriceWithExpirationFieldRenderer) BrandFieldRenderer, ProductFieldRenderer, PriceFieldRenderer, PriceWithExpirationFieldRenderer)
from .batch import BatchIDFieldRenderer, HandheldBatchFieldRenderer from .batch import BatchIDFieldRenderer, HandheldBatchFieldRenderer

View file

@ -89,7 +89,7 @@ class DepartmentFieldRenderer(SelectFieldRenderer):
if not department: if not department:
return '' return ''
if department.number: if department.number:
text = '{} {}'.format(department.number, department.name) text = '({}) {}'.format(department.number, department.name)
else: else:
text = department.name text = department.name
return tags.link_to(text, self.request.route_url('departments.view', uuid=department.uuid)) return tags.link_to(text, self.request.route_url('departments.view', uuid=department.uuid))
@ -97,24 +97,34 @@ class DepartmentFieldRenderer(SelectFieldRenderer):
class SubdepartmentFieldRenderer(SelectFieldRenderer): class SubdepartmentFieldRenderer(SelectFieldRenderer):
""" """
Shows the subdepartment number as well as the name. Shows a link to the subdepartment.
""" """
def render_readonly(self, **kwargs): def render_readonly(self, **kwargs):
sub = self.raw_value subdept = self.raw_value
if sub: if not subdept:
return "{0} - {1}".format(sub.number, sub.name) return ""
return "" if subdept.number:
text = "({}) {}".format(subdept.number, subdept.name)
else:
text = subdept.name
return tags.link_to(text, self.request.route_url('subdepartments.view', uuid=subdept.uuid))
class CategoryFieldRenderer(SelectFieldRenderer): class CategoryFieldRenderer(SelectFieldRenderer):
""" """
Shows the category number as well as the name. Shows a link to the category.
""" """
def render_readonly(self, **kwargs): def render_readonly(self, **kwargs):
cat = self.raw_value category = self.raw_value
if cat: if not category:
return "{0} - {1}".format(cat.number, cat.name) return ""
return "" if category.code:
text = "({}) {}".format(category.code, category.name)
else:
text = category.name
return tags.link_to(text, self.request.route_url('categories.view', uuid=category.uuid))
class BrandFieldRenderer(AutocompleteFieldRenderer): class BrandFieldRenderer(AutocompleteFieldRenderer):

View file

@ -28,7 +28,15 @@
% endif % endif
</%def> </%def>
<%def name="render_link_fields(form)"></%def> <%def name="render_main_fields(form)">
${render_field_readonly(form.fieldset.upc)}
${render_field_readonly(form.fieldset.brand)}
${render_field_readonly(form.fieldset.description)}
${render_field_readonly(form.fieldset.size)}
${render_field_readonly(form.fieldset.unit_size)}
${render_field_readonly(form.fieldset.unit_of_measure)}
${render_field_readonly(form.fieldset.case_pack)}
</%def>
<%def name="render_organization_fields(form)"> <%def name="render_organization_fields(form)">
${render_field_readonly(form.fieldset.department)} ${render_field_readonly(form.fieldset.department)}
@ -68,14 +76,7 @@
<h2>Product</h2> <h2>Product</h2>
<div class="panel-body"> <div class="panel-body">
<div style="clear: none; float: left;"> <div style="clear: none; float: left;">
${render_field_readonly(form.fieldset.upc)} ${self.render_main_fields(form)}
${render_field_readonly(form.fieldset.brand)}
${render_field_readonly(form.fieldset.description)}
${render_field_readonly(form.fieldset.size)}
${render_field_readonly(form.fieldset.unit_size)}
${render_field_readonly(form.fieldset.unit_of_measure)}
${render_field_readonly(form.fieldset.case_pack)}
${self.render_link_fields(form)}
</div> </div>
% if image_url: % if image_url:
${h.image(image_url, "Product Image", id='product-image', path=image_path, use_pil=False)} ${h.image(image_url, "Product Image", id='product-image', path=image_path, use_pil=False)}

View file

@ -266,6 +266,9 @@ class ProductsView(MasterView):
def _preconfigure_fieldset(self, fs): def _preconfigure_fieldset(self, fs):
fs.upc.set(label="UPC", renderer=forms.renderers.GPCFieldRenderer) fs.upc.set(label="UPC", renderer=forms.renderers.GPCFieldRenderer)
fs.brand.set(renderer=forms.renderers.BrandFieldRenderer, options=[]) fs.brand.set(renderer=forms.renderers.BrandFieldRenderer, options=[])
fs.department.set(renderer=forms.renderers.DepartmentFieldRenderer)
fs.subdepartment.set(renderer=forms.renderers.SubdepartmentFieldRenderer)
fs.category.set(renderer=forms.renderers.CategoryFieldRenderer)
fs.unit_of_measure.set(label="Unit of Measure", fs.unit_of_measure.set(label="Unit of Measure",
renderer=forms.renderers.EnumFieldRenderer(self.enum.UNIT_OF_MEASURE)) renderer=forms.renderers.EnumFieldRenderer(self.enum.UNIT_OF_MEASURE))
fs.regular_price.set(renderer=forms.renderers.PriceFieldRenderer) fs.regular_price.set(renderer=forms.renderers.PriceFieldRenderer)