Refactor handheld batch views per master4
This commit is contained in:
		
							parent
							
								
									0737faa034
								
							
						
					
					
						commit
						7cee515187
					
				
					 1 changed files with 36 additions and 22 deletions
				
			
		| 
						 | 
					@ -34,9 +34,8 @@ from rattail.util import OrderedDict
 | 
				
			||||||
import formencode as fe
 | 
					import formencode as fe
 | 
				
			||||||
from webhelpers2.html import tags
 | 
					from webhelpers2.html import tags
 | 
				
			||||||
 | 
					
 | 
				
			||||||
from tailbone import forms
 | 
					 | 
				
			||||||
from tailbone.db import Session
 | 
					from tailbone.db import Session
 | 
				
			||||||
from tailbone.views.batch import FileBatchMasterView3 as FileBatchMasterView
 | 
					from tailbone.views.batch import FileBatchMasterView4 as FileBatchMasterView
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
ACTION_OPTIONS = OrderedDict([
 | 
					ACTION_OPTIONS = OrderedDict([
 | 
				
			||||||
| 
						 | 
					@ -92,6 +91,10 @@ class HandheldBatchView(FileBatchMasterView):
 | 
				
			||||||
        'executed_by',
 | 
					        'executed_by',
 | 
				
			||||||
    ]
 | 
					    ]
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    row_labels = {
 | 
				
			||||||
 | 
					        'upc': "UPC",
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    row_grid_columns = [
 | 
					    row_grid_columns = [
 | 
				
			||||||
        'sequence',
 | 
					        'sequence',
 | 
				
			||||||
        'upc',
 | 
					        'upc',
 | 
				
			||||||
| 
						 | 
					@ -103,6 +106,17 @@ class HandheldBatchView(FileBatchMasterView):
 | 
				
			||||||
        'status_code',
 | 
					        'status_code',
 | 
				
			||||||
    ]
 | 
					    ]
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    row_form_fields = [
 | 
				
			||||||
 | 
					        'sequence',
 | 
				
			||||||
 | 
					        'upc',
 | 
				
			||||||
 | 
					        'brand_name',
 | 
				
			||||||
 | 
					        'description',
 | 
				
			||||||
 | 
					        'size',
 | 
				
			||||||
 | 
					        'status_code',
 | 
				
			||||||
 | 
					        'cases',
 | 
				
			||||||
 | 
					        'units',
 | 
				
			||||||
 | 
					    ]
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    def configure_grid(self, g):
 | 
					    def configure_grid(self, g):
 | 
				
			||||||
        super(HandheldBatchView, self).configure_grid(g)
 | 
					        super(HandheldBatchView, self).configure_grid(g)
 | 
				
			||||||
        device_types = OrderedDict(sorted(self.enum.HANDHELD_DEVICE_TYPE.items(),
 | 
					        device_types = OrderedDict(sorted(self.enum.HANDHELD_DEVICE_TYPE.items(),
 | 
				
			||||||
| 
						 | 
					@ -153,33 +167,33 @@ class HandheldBatchView(FileBatchMasterView):
 | 
				
			||||||
        super(HandheldBatchView, self).configure_row_grid(g)
 | 
					        super(HandheldBatchView, self).configure_row_grid(g)
 | 
				
			||||||
        g.set_type('cases', 'quantity')
 | 
					        g.set_type('cases', 'quantity')
 | 
				
			||||||
        g.set_type('units', 'quantity')
 | 
					        g.set_type('units', 'quantity')
 | 
				
			||||||
        g.set_label('upc', "UPC")
 | 
					 | 
				
			||||||
        g.set_label('brand_name', "Brand")
 | 
					        g.set_label('brand_name', "Brand")
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    def row_grid_extra_class(self, row, i):
 | 
					    def row_grid_extra_class(self, row, i):
 | 
				
			||||||
        if row.status_code == row.STATUS_PRODUCT_NOT_FOUND:
 | 
					        if row.status_code == row.STATUS_PRODUCT_NOT_FOUND:
 | 
				
			||||||
            return 'warning'
 | 
					            return 'warning'
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    def _preconfigure_row_fieldset(self, fs):
 | 
					    def configure_row_form(self, f):
 | 
				
			||||||
        super(HandheldBatchView, self)._preconfigure_row_fieldset(fs)
 | 
					        super(HandheldBatchView, self).configure_row_form(f)
 | 
				
			||||||
        fs.upc.set(readonly=True, label="UPC", renderer=forms.renderers.GPCFieldRenderer,
 | 
					 | 
				
			||||||
                   attrs={'link': lambda r: self.request.route_url('products.view', uuid=r.product_uuid)})
 | 
					 | 
				
			||||||
        fs.brand_name.set(readonly=True)
 | 
					 | 
				
			||||||
        fs.description.set(readonly=True)
 | 
					 | 
				
			||||||
        fs.size.set(readonly=True)
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
    def configure_row_fieldset(self, fs):
 | 
					        # readonly fields
 | 
				
			||||||
        fs.configure(
 | 
					        f.set_readonly('upc')
 | 
				
			||||||
            include=[
 | 
					        f.set_readonly('brand_name')
 | 
				
			||||||
                fs.sequence,
 | 
					        f.set_readonly('description')
 | 
				
			||||||
                fs.upc,
 | 
					        f.set_readonly('size')
 | 
				
			||||||
                fs.brand_name,
 | 
					
 | 
				
			||||||
                fs.description,
 | 
					        # upc
 | 
				
			||||||
                fs.size,
 | 
					        f.set_renderer('upc', self.render_upc)
 | 
				
			||||||
                fs.status_code,
 | 
					
 | 
				
			||||||
                fs.cases,
 | 
					    def render_upc(self, row, field):
 | 
				
			||||||
                fs.units,
 | 
					        upc = row.upc
 | 
				
			||||||
            ])
 | 
					        if not upc:
 | 
				
			||||||
 | 
					            return ""
 | 
				
			||||||
 | 
					        text = upc.pretty()
 | 
				
			||||||
 | 
					        if row.product_uuid:
 | 
				
			||||||
 | 
					            url = self.request.route_url('products.view', uuid=row.product_uuid)
 | 
				
			||||||
 | 
					            return tags.link_to(text, url)
 | 
				
			||||||
 | 
					        return text
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    def get_exec_options_kwargs(self, **kwargs):
 | 
					    def get_exec_options_kwargs(self, **kwargs):
 | 
				
			||||||
        kwargs['ACTION_OPTIONS'] = list(ACTION_OPTIONS.iteritems())
 | 
					        kwargs['ACTION_OPTIONS'] = list(ACTION_OPTIONS.iteritems())
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue