Remove legacy fieldset configuration logic
This commit is contained in:
parent
1c27efc8f1
commit
2cbacd6187
|
@ -39,7 +39,6 @@ from rattail.db import model, Session as RattailSession
|
||||||
from rattail.threads import Thread
|
from rattail.threads import Thread
|
||||||
from rattail.util import load_object, prettify
|
from rattail.util import load_object, prettify
|
||||||
|
|
||||||
import formalchemy as fa
|
|
||||||
from pyramid import httpexceptions
|
from pyramid import httpexceptions
|
||||||
from pyramid.renderers import render_to_response
|
from pyramid.renderers import render_to_response
|
||||||
from pyramid.response import FileResponse
|
from pyramid.response import FileResponse
|
||||||
|
@ -49,7 +48,6 @@ from webhelpers2.html import HTML, tags
|
||||||
from tailbone import forms, grids
|
from tailbone import forms, grids
|
||||||
from tailbone.db import Session
|
from tailbone.db import Session
|
||||||
from tailbone.views import MasterView
|
from tailbone.views import MasterView
|
||||||
from tailbone.forms.renderers.batch import FileFieldRenderer
|
|
||||||
from tailbone.progress import SessionProgress
|
from tailbone.progress import SessionProgress
|
||||||
|
|
||||||
|
|
||||||
|
@ -293,95 +291,6 @@ class BatchMasterView(MasterView):
|
||||||
url = self.request.route_url('users.view', uuid=user.uuid)
|
url = self.request.route_url('users.view', uuid=user.uuid)
|
||||||
return tags.link_to(title, url)
|
return tags.link_to(title, url)
|
||||||
|
|
||||||
def _preconfigure_fieldset(self, fs):
|
|
||||||
"""
|
|
||||||
Apply some commonly-useful pre-configuration to the main batch
|
|
||||||
fieldset.
|
|
||||||
"""
|
|
||||||
fs.id.set(label="Batch ID", readonly=True, renderer=forms.renderers.BatchIDFieldRenderer)
|
|
||||||
|
|
||||||
fs.created.set(readonly=True)
|
|
||||||
fs.created_by.set(label="Created by", renderer=forms.renderers.UserFieldRenderer,
|
|
||||||
readonly=True)
|
|
||||||
fs.cognized_by.set(label="Cognized by", renderer=forms.renderers.UserFieldRenderer)
|
|
||||||
fs.rowcount.set(label="Row Count", readonly=True)
|
|
||||||
fs.status_code.set(label="Status", renderer=StatusRenderer(self.model_class.STATUS))
|
|
||||||
fs.executed.set(readonly=True)
|
|
||||||
fs.executed_by.set(label="Executed by", renderer=forms.renderers.UserFieldRenderer, readonly=True)
|
|
||||||
fs.notes.set(renderer=fa.TextAreaFieldRenderer, size=(80, 10))
|
|
||||||
|
|
||||||
if self.creating and self.request.user:
|
|
||||||
batch = fs.model
|
|
||||||
batch.created_by_uuid = self.request.user.uuid
|
|
||||||
|
|
||||||
def configure_fieldset(self, fs):
|
|
||||||
"""
|
|
||||||
Apply final configuration to the main batch fieldset. Custom batch
|
|
||||||
views are encouraged to override this method.
|
|
||||||
"""
|
|
||||||
if self.creating:
|
|
||||||
fs.configure()
|
|
||||||
|
|
||||||
else:
|
|
||||||
batch = fs.model
|
|
||||||
if batch.executed:
|
|
||||||
fs.configure(
|
|
||||||
include=[
|
|
||||||
fs.id,
|
|
||||||
fs.created,
|
|
||||||
fs.created_by,
|
|
||||||
fs.rowcount,
|
|
||||||
fs.executed,
|
|
||||||
fs.executed_by,
|
|
||||||
])
|
|
||||||
else:
|
|
||||||
fs.configure(
|
|
||||||
include=[
|
|
||||||
fs.id,
|
|
||||||
fs.created,
|
|
||||||
fs.created_by,
|
|
||||||
fs.rowcount,
|
|
||||||
])
|
|
||||||
|
|
||||||
def _postconfigure_fieldset(self, fs):
|
|
||||||
if self.creating:
|
|
||||||
unwanted = [
|
|
||||||
'id',
|
|
||||||
'rowcount',
|
|
||||||
'created',
|
|
||||||
'created_by',
|
|
||||||
'cognized',
|
|
||||||
'cognized_by',
|
|
||||||
'executed',
|
|
||||||
'executed_by',
|
|
||||||
'purge',
|
|
||||||
'data_rows',
|
|
||||||
]
|
|
||||||
for field in unwanted:
|
|
||||||
if field in fs.render_fields:
|
|
||||||
delattr(fs, field)
|
|
||||||
else:
|
|
||||||
batch = fs.model
|
|
||||||
if not batch.executed:
|
|
||||||
unwanted = [
|
|
||||||
'executed',
|
|
||||||
'executed_by',
|
|
||||||
]
|
|
||||||
for field in unwanted:
|
|
||||||
if field in fs.render_fields:
|
|
||||||
delattr(fs, field)
|
|
||||||
|
|
||||||
def add_file_field(self, fs, name, **kwargs):
|
|
||||||
kwargs.setdefault('value', lambda b: getattr(b, 'filename_{}'.format(name)))
|
|
||||||
if 'renderer' not in kwargs:
|
|
||||||
batch = fs.model
|
|
||||||
storage_path = self.rattail_config.batch_filedir(self.handler.batch_key)
|
|
||||||
download_url = self.get_action_url('download', batch, _query={'file': name})
|
|
||||||
kwargs['renderer'] = FileFieldRenderer.new(self,
|
|
||||||
storage_path=storage_path,
|
|
||||||
download_url=download_url)
|
|
||||||
fs.append(fa.Field(name, **kwargs))
|
|
||||||
|
|
||||||
def configure_mobile_form(self, f):
|
def configure_mobile_form(self, f):
|
||||||
super(BatchMasterView, self).configure_mobile_form(f)
|
super(BatchMasterView, self).configure_mobile_form(f)
|
||||||
batch = f.model_instance
|
batch = f.model_instance
|
||||||
|
@ -917,21 +826,6 @@ class BatchMasterView(MasterView):
|
||||||
return True
|
return True
|
||||||
return False
|
return False
|
||||||
|
|
||||||
def _preconfigure_row_fieldset(self, fs):
|
|
||||||
fs.sequence.set(readonly=True)
|
|
||||||
fs.status_code.set(renderer=StatusRenderer(self.model_row_class.STATUS),
|
|
||||||
label="Status", readonly=True)
|
|
||||||
fs.status_text.set(readonly=True)
|
|
||||||
fs.removed.set(readonly=True)
|
|
||||||
try:
|
|
||||||
fs.product.set(readonly=True, renderer=forms.renderers.ProductFieldRenderer)
|
|
||||||
except AttributeError:
|
|
||||||
pass
|
|
||||||
|
|
||||||
def configure_row_fieldset(self, fs):
|
|
||||||
fs.configure()
|
|
||||||
del fs.batch
|
|
||||||
|
|
||||||
def template_kwargs_view_row(self, **kwargs):
|
def template_kwargs_view_row(self, **kwargs):
|
||||||
kwargs['batch_model_title'] = kwargs['parent_model_title']
|
kwargs['batch_model_title'] = kwargs['parent_model_title']
|
||||||
return kwargs
|
return kwargs
|
||||||
|
@ -1252,44 +1146,6 @@ class FileBatchMasterView(BatchMasterView):
|
||||||
url = self.get_action_url('download', batch)
|
url = self.get_action_url('download', batch)
|
||||||
return self.render_file_field(path, url)
|
return self.render_file_field(path, url)
|
||||||
|
|
||||||
def _preconfigure_fieldset(self, fs):
|
|
||||||
super(FileBatchMasterView, self)._preconfigure_fieldset(fs)
|
|
||||||
fs.filename.set(label="Data File", renderer=FileFieldRenderer.new(self))
|
|
||||||
if self.editing:
|
|
||||||
fs.filename.set(readonly=True)
|
|
||||||
|
|
||||||
def configure_fieldset(self, fs):
|
|
||||||
"""
|
|
||||||
Apply final configuration to the main batch fieldset. Custom batch
|
|
||||||
views are encouraged to override this method.
|
|
||||||
"""
|
|
||||||
if self.creating:
|
|
||||||
fs.configure(
|
|
||||||
include=[
|
|
||||||
fs.filename,
|
|
||||||
])
|
|
||||||
|
|
||||||
else:
|
|
||||||
batch = fs.model
|
|
||||||
if batch.executed:
|
|
||||||
fs.configure(
|
|
||||||
include=[
|
|
||||||
fs.id,
|
|
||||||
fs.created,
|
|
||||||
fs.created_by,
|
|
||||||
fs.filename,
|
|
||||||
fs.executed,
|
|
||||||
fs.executed_by,
|
|
||||||
])
|
|
||||||
else:
|
|
||||||
fs.configure(
|
|
||||||
include=[
|
|
||||||
fs.id,
|
|
||||||
fs.created,
|
|
||||||
fs.created_by,
|
|
||||||
fs.filename,
|
|
||||||
])
|
|
||||||
|
|
||||||
def download(self):
|
def download(self):
|
||||||
"""
|
"""
|
||||||
View for downloading the data file associated with a batch.
|
View for downloading the data file associated with a batch.
|
||||||
|
@ -1329,23 +1185,6 @@ class FileBatchMasterView(BatchMasterView):
|
||||||
"Download existing {} data file".format(model_title))
|
"Download existing {} data file".format(model_title))
|
||||||
|
|
||||||
|
|
||||||
class StatusRenderer(forms.renderers.EnumFieldRenderer):
|
|
||||||
"""
|
|
||||||
Custom renderer for ``status_code`` fields. Adds ``status_text`` value as
|
|
||||||
title attribute if it exists.
|
|
||||||
"""
|
|
||||||
|
|
||||||
def render_readonly(self, **kwargs):
|
|
||||||
value = self.raw_value
|
|
||||||
if value is None:
|
|
||||||
return ''
|
|
||||||
status_code_text = self.enumeration.get(value, unicode(value))
|
|
||||||
row = self.field.parent.model
|
|
||||||
if row.status_text:
|
|
||||||
return HTML.tag('span', title=row.status_text, c=status_code_text)
|
|
||||||
return status_code_text
|
|
||||||
|
|
||||||
|
|
||||||
class MobileBatchStatusFilter(grids.filters.MobileFilter):
|
class MobileBatchStatusFilter(grids.filters.MobileFilter):
|
||||||
|
|
||||||
value_choices = ['pending', 'complete', 'executed', 'all']
|
value_choices = ['pending', 'complete', 'executed', 'all']
|
||||||
|
|
|
@ -993,12 +993,6 @@ class MasterView(View):
|
||||||
|
|
||||||
self.set_labels(form)
|
self.set_labels(form)
|
||||||
|
|
||||||
def preconfigure_mobile_row_fieldset(self, fieldset):
|
|
||||||
self._preconfigure_row_fieldset(fieldset)
|
|
||||||
|
|
||||||
def configure_mobile_row_fieldset(self, fieldset):
|
|
||||||
self.configure_row_fieldset(fieldset)
|
|
||||||
|
|
||||||
def validate_mobile_form(self, form):
|
def validate_mobile_form(self, form):
|
||||||
controls = self.request.POST.items()
|
controls = self.request.POST.items()
|
||||||
try:
|
try:
|
||||||
|
@ -1081,15 +1075,6 @@ class MasterView(View):
|
||||||
return False
|
return False
|
||||||
return True
|
return True
|
||||||
|
|
||||||
def preconfigure_mobile_fieldset(self, fieldset):
|
|
||||||
self._preconfigure_fieldset(fieldset)
|
|
||||||
|
|
||||||
def configure_mobile_fieldset(self, fieldset):
|
|
||||||
"""
|
|
||||||
Configure the given mobile fieldset.
|
|
||||||
"""
|
|
||||||
self.configure_fieldset(fieldset)
|
|
||||||
|
|
||||||
def get_mobile_row_data(self, parent):
|
def get_mobile_row_data(self, parent):
|
||||||
return self.get_row_data(parent)
|
return self.get_row_data(parent)
|
||||||
|
|
||||||
|
@ -2226,18 +2211,6 @@ class MasterView(View):
|
||||||
def save_form(self, form):
|
def save_form(self, form):
|
||||||
form.save()
|
form.save()
|
||||||
|
|
||||||
def _preconfigure_fieldset(self, fieldset):
|
|
||||||
pass
|
|
||||||
|
|
||||||
def configure_fieldset(self, fieldset):
|
|
||||||
"""
|
|
||||||
Configure the given fieldset.
|
|
||||||
"""
|
|
||||||
fieldset.configure()
|
|
||||||
|
|
||||||
def _postconfigure_fieldset(self, fieldset):
|
|
||||||
pass
|
|
||||||
|
|
||||||
def before_create(self, form):
|
def before_create(self, form):
|
||||||
"""
|
"""
|
||||||
Event hook, called just after the form to create a new instance has
|
Event hook, called just after the form to create a new instance has
|
||||||
|
@ -2570,12 +2543,6 @@ class MasterView(View):
|
||||||
|
|
||||||
self.set_row_labels(form)
|
self.set_row_labels(form)
|
||||||
|
|
||||||
def _preconfigure_row_fieldset(self, fs):
|
|
||||||
pass
|
|
||||||
|
|
||||||
def configure_row_fieldset(self, fs):
|
|
||||||
fs.configure()
|
|
||||||
|
|
||||||
def validate_row_form(self, form):
|
def validate_row_form(self, form):
|
||||||
controls = self.request.POST.items()
|
controls = self.request.POST.items()
|
||||||
try:
|
try:
|
||||||
|
|
Loading…
Reference in a new issue