3
0
Fork 0

fix: format all code with black

and from now on should not deviate from that...
This commit is contained in:
Lance Edgar 2025-08-31 12:26:43 -05:00
parent 8a09fb1a3c
commit 4d0693862d
68 changed files with 6693 additions and 5659 deletions

View file

@ -52,18 +52,18 @@ class BatchMasterView(MasterView):
"""
labels = {
'id': "Batch ID",
'status_code': "Status",
"id": "Batch ID",
"status_code": "Status",
}
sort_defaults = ('id', 'desc')
sort_defaults = ("id", "desc")
has_rows = True
rows_title = "Batch Rows"
rows_sort_defaults = 'sequence'
rows_sort_defaults = "sequence"
row_labels = {
'status_code': "Status",
"status_code": "Status",
}
def __init__(self, request, context=None):
@ -89,7 +89,7 @@ class BatchMasterView(MasterView):
batches.
"""
templates = super().get_fallback_templates(template)
templates.insert(0, f'/batch/{template}.mako')
templates.insert(0, f"/batch/{template}.mako")
return templates
def render_to_response(self, template, context):
@ -105,16 +105,19 @@ class BatchMasterView(MasterView):
* ``why_not_execute`` - text of reason (if any) not to execute batch
* ``execution_described`` - HTML (rendered from markdown) describing batch execution
"""
if template == 'view':
batch = context['instance']
context['batch'] = batch
context['batch_handler'] = self.batch_handler
context['why_not_execute'] = self.batch_handler.why_not_execute(batch)
if template == "view":
batch = context["instance"]
context["batch"] = batch
context["batch_handler"] = self.batch_handler
context["why_not_execute"] = self.batch_handler.why_not_execute(batch)
description = (self.batch_handler.describe_execution(batch)
or "Handler does not say! Your guess is as good as mine.")
context['execution_described'] = markdown.markdown(
description, extensions=['fenced_code', 'codehilite'])
description = (
self.batch_handler.describe_execution(batch)
or "Handler does not say! Your guess is as good as mine."
)
context["execution_described"] = markdown.markdown(
description, extensions=["fenced_code", "codehilite"]
)
return super().render_to_response(template, context)
@ -125,24 +128,27 @@ class BatchMasterView(MasterView):
# created_by
CreatedBy = orm.aliased(model.User)
g.set_joiner('created_by',
lambda q: q.join(CreatedBy,
CreatedBy.uuid == self.model_class.created_by_uuid))
g.set_sorter('created_by', CreatedBy.username)
g.set_joiner(
"created_by",
lambda q: q.join(
CreatedBy, CreatedBy.uuid == self.model_class.created_by_uuid
),
)
g.set_sorter("created_by", CreatedBy.username)
# g.set_filter('created_by', CreatedBy.username, label="Created By Username")
# id
g.set_renderer('id', self.render_batch_id)
g.set_link('id')
g.set_renderer("id", self.render_batch_id)
g.set_link("id")
# description
g.set_link('description')
g.set_link("description")
def render_batch_id(self, batch, key, value):
""" """
if value:
batch_id = int(value)
return f'{batch_id:08d}'
return f"{batch_id:08d}"
def get_instance_title(self, batch):
""" """
@ -157,55 +163,55 @@ class BatchMasterView(MasterView):
# id
if self.creating:
f.remove('id')
f.remove("id")
else:
f.set_readonly('id')
f.set_widget('id', BatchIdWidget())
f.set_readonly("id")
f.set_widget("id", BatchIdWidget())
# notes
f.set_widget('notes', 'notes')
f.set_widget("notes", "notes")
# rows
f.remove('rows')
f.remove("rows")
if self.creating:
f.remove('row_count')
f.remove("row_count")
else:
f.set_readonly('row_count')
f.set_readonly("row_count")
# status
f.remove('status_text')
f.remove("status_text")
if self.creating:
f.remove('status_code')
f.remove("status_code")
else:
f.set_readonly('status_code')
f.set_readonly("status_code")
# created
if self.creating:
f.remove('created')
f.remove("created")
else:
f.set_readonly('created')
f.set_readonly("created")
# created_by
f.remove('created_by_uuid')
f.remove("created_by_uuid")
if self.creating:
f.remove('created_by')
f.remove("created_by")
else:
f.set_node('created_by', UserRef(self.request))
f.set_readonly('created_by')
f.set_node("created_by", UserRef(self.request))
f.set_readonly("created_by")
# executed
if self.creating or not batch.executed:
f.remove('executed')
f.remove("executed")
else:
f.set_readonly('executed')
f.set_readonly("executed")
# executed_by
f.remove('executed_by_uuid')
f.remove("executed_by_uuid")
if self.creating or not batch.executed:
f.remove('executed_by')
f.remove("executed_by")
else:
f.set_node('executed_by', UserRef(self.request))
f.set_readonly('executed_by')
f.set_node("executed_by", UserRef(self.request))
f.set_readonly("executed_by")
def objectify(self, form, **kwargs):
"""
@ -226,12 +232,16 @@ class BatchMasterView(MasterView):
batch = schema.objectify(form.validated, context=form.model_instance)
# then we collect attributes from the new batch
kw = dict([(key, getattr(batch, key))
for key in form.validated
if hasattr(batch, key)])
kw = dict(
[
(key, getattr(batch, key))
for key in form.validated
if hasattr(batch, key)
]
)
# and set attribute for user creating the batch
kw['created_by'] = self.request.user
kw["created_by"] = self.request.user
# plus caller can override anything
kw.update(kwargs)
@ -252,15 +262,19 @@ class BatchMasterView(MasterView):
"""
# just view batch if should not populate
if not self.batch_handler.should_populate(batch):
return self.redirect(self.get_action_url('view', batch))
return self.redirect(self.get_action_url("view", batch))
# setup thread to populate batch
route_prefix = self.get_route_prefix()
key = f'{route_prefix}.populate'
progress = self.make_progress(key, success_url=self.get_action_url('view', batch))
thread = threading.Thread(target=self.populate_thread,
args=(batch.uuid,),
kwargs=dict(progress=progress))
key = f"{route_prefix}.populate"
progress = self.make_progress(
key, success_url=self.get_action_url("view", batch)
)
thread = threading.Thread(
target=self.populate_thread,
args=(batch.uuid,),
kwargs=dict(progress=progress),
)
# start thread and show progress page
thread.start()
@ -316,9 +330,12 @@ class BatchMasterView(MasterView):
except Exception as error:
session.rollback()
log.warning("failed to populate %s: %s",
self.get_model_title(), batch,
exc_info=True)
log.warning(
"failed to populate %s: %s",
self.get_model_title(),
batch,
exc_info=True,
)
if progress:
progress.handle_error(error)
@ -351,9 +368,9 @@ class BatchMasterView(MasterView):
self.batch_handler.do_execute(batch, self.request.user)
except Exception as error:
log.warning("failed to execute batch: %s", batch, exc_info=True)
self.request.session.flash(f"Execution failed!: {error}", 'error')
self.request.session.flash(f"Execution failed!: {error}", "error")
return self.redirect(self.get_action_url('view', batch))
return self.redirect(self.get_action_url("view", batch))
##############################
# row methods
@ -362,7 +379,7 @@ class BatchMasterView(MasterView):
@classmethod
def get_row_model_class(cls):
""" """
if hasattr(cls, 'row_model_class'):
if hasattr(cls, "row_model_class"):
return cls.row_model_class
Batch = cls.get_model_class()
@ -375,17 +392,16 @@ class BatchMasterView(MasterView):
data.
"""
BatchRow = self.get_row_model_class()
query = self.Session.query(BatchRow)\
.filter(BatchRow.batch == batch)
query = self.Session.query(BatchRow).filter(BatchRow.batch == batch)
return query
def configure_row_grid(self, g):
""" """
super().configure_row_grid(g)
g.set_label('sequence', "Seq.", column_only=True)
g.set_label("sequence", "Seq.", column_only=True)
g.set_renderer('status_code', self.render_row_status)
g.set_renderer("status_code", self.render_row_status)
def render_row_status(self, row, key, value):
""" """
@ -409,12 +425,17 @@ class BatchMasterView(MasterView):
instance_url_prefix = cls.get_instance_url_prefix()
# execute
config.add_route(f'{route_prefix}.execute',
f'{instance_url_prefix}/execute',
request_method='POST')
config.add_view(cls, attr='execute',
route_name=f'{route_prefix}.execute',
permission=f'{permission_prefix}.execute')
config.add_wutta_permission(permission_prefix,
f'{permission_prefix}.execute',
f"Execute {model_title}")
config.add_route(
f"{route_prefix}.execute",
f"{instance_url_prefix}/execute",
request_method="POST",
)
config.add_view(
cls,
attr="execute",
route_name=f"{route_prefix}.execute",
permission=f"{permission_prefix}.execute",
)
config.add_wutta_permission(
permission_prefix, f"{permission_prefix}.execute", f"Execute {model_title}"
)