feat: expose Assets field when editing a Log record
This commit is contained in:
parent
45fd5556f2
commit
6d80937e0c
1 changed files with 23 additions and 4 deletions
|
|
@ -256,10 +256,9 @@ class LogMasterView(WuttaFarmMasterView):
|
||||||
f.set_default("timestamp", self.app.make_utc())
|
f.set_default("timestamp", self.app.make_utc())
|
||||||
|
|
||||||
# assets
|
# assets
|
||||||
if self.creating or self.editing:
|
f.set_node("assets", AssetRefs(self.request))
|
||||||
f.remove("assets") # TODO: need to support this
|
f.set_required("assets", False)
|
||||||
else:
|
if not self.creating:
|
||||||
f.set_node("assets", AssetRefs(self.request))
|
|
||||||
# nb. must explicity declare value for non-standard field
|
# nb. must explicity declare value for non-standard field
|
||||||
f.set_default("assets", log.assets)
|
f.set_default("assets", log.assets)
|
||||||
|
|
||||||
|
|
@ -324,13 +323,33 @@ class LogMasterView(WuttaFarmMasterView):
|
||||||
|
|
||||||
def objectify(self, form):
|
def objectify(self, form):
|
||||||
log = super().objectify(form)
|
log = super().objectify(form)
|
||||||
|
data = form.validated
|
||||||
|
|
||||||
if self.creating:
|
if self.creating:
|
||||||
model_class = self.get_model_class()
|
model_class = self.get_model_class()
|
||||||
log.log_type = self.get_farmos_log_type()
|
log.log_type = self.get_farmos_log_type()
|
||||||
|
|
||||||
|
self.set_assets(log, data["assets"] or [])
|
||||||
|
|
||||||
return log
|
return log
|
||||||
|
|
||||||
|
def set_assets(self, log, desired):
|
||||||
|
model = self.app.model
|
||||||
|
session = self.Session()
|
||||||
|
current = [a.uuid for a in log.assets]
|
||||||
|
|
||||||
|
for uuid in desired:
|
||||||
|
if uuid not in current:
|
||||||
|
asset = session.get(model.Asset, uuid)
|
||||||
|
assert asset
|
||||||
|
log.assets.append(asset)
|
||||||
|
|
||||||
|
for uuid in current:
|
||||||
|
if uuid not in desired:
|
||||||
|
asset = session.get(model.Asset, uuid)
|
||||||
|
assert asset
|
||||||
|
log.assets.remove(asset)
|
||||||
|
|
||||||
def get_farmos_url(self, log):
|
def get_farmos_url(self, log):
|
||||||
return self.app.get_farmos_url(f"/log/{log.drupal_id}")
|
return self.app.get_farmos_url(f"/log/{log.drupal_id}")
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue