fix: add thumbnail to farmOS asset base view
This commit is contained in:
parent
e5e3d38365
commit
5d7dea5a84
2 changed files with 23 additions and 2 deletions
|
|
@ -63,6 +63,7 @@ class AnimalView(AssetMasterView):
|
||||||
}
|
}
|
||||||
|
|
||||||
grid_columns = [
|
grid_columns = [
|
||||||
|
"thumbnail",
|
||||||
"drupal_id",
|
"drupal_id",
|
||||||
"name",
|
"name",
|
||||||
"produces_eggs",
|
"produces_eggs",
|
||||||
|
|
@ -95,7 +96,7 @@ class AnimalView(AssetMasterView):
|
||||||
]
|
]
|
||||||
|
|
||||||
def get_grid_data(self, **kwargs):
|
def get_grid_data(self, **kwargs):
|
||||||
kwargs.setdefault("include", "animal_type,group,owner,location")
|
kwargs.setdefault("include", "image,animal_type,group,owner,location")
|
||||||
return super().get_grid_data(**kwargs)
|
return super().get_grid_data(**kwargs)
|
||||||
|
|
||||||
def configure_grid(self, grid):
|
def configure_grid(self, grid):
|
||||||
|
|
|
||||||
|
|
@ -54,6 +54,7 @@ class AssetMasterView(FarmOSMasterView):
|
||||||
}
|
}
|
||||||
|
|
||||||
grid_columns = [
|
grid_columns = [
|
||||||
|
"thumbnail",
|
||||||
"drupal_id",
|
"drupal_id",
|
||||||
"name",
|
"name",
|
||||||
"owners",
|
"owners",
|
||||||
|
|
@ -69,7 +70,7 @@ class AssetMasterView(FarmOSMasterView):
|
||||||
}
|
}
|
||||||
|
|
||||||
def get_grid_data(self, columns=None, session=None, **kwargs):
|
def get_grid_data(self, columns=None, session=None, **kwargs):
|
||||||
kwargs.setdefault("include", "owner,location")
|
kwargs.setdefault("include", "image,owner,location")
|
||||||
kwargs.setdefault("normalizer", self.normalize_asset)
|
kwargs.setdefault("normalizer", self.normalize_asset)
|
||||||
return ResourceData(
|
return ResourceData(
|
||||||
self.config,
|
self.config,
|
||||||
|
|
@ -82,6 +83,11 @@ class AssetMasterView(FarmOSMasterView):
|
||||||
g = grid
|
g = grid
|
||||||
super().configure_grid(g)
|
super().configure_grid(g)
|
||||||
|
|
||||||
|
# thumbnail
|
||||||
|
g.set_renderer("thumbnail", self.render_grid_thumbnail)
|
||||||
|
g.set_label("thumbnail", "", column_only=True)
|
||||||
|
g.set_centered("thumbnail")
|
||||||
|
|
||||||
# drupal_id
|
# drupal_id
|
||||||
g.set_label("drupal_id", "ID", column_only=True)
|
g.set_label("drupal_id", "ID", column_only=True)
|
||||||
g.set_sorter("drupal_id", SimpleSorter("drupal_internal__id"))
|
g.set_sorter("drupal_id", SimpleSorter("drupal_internal__id"))
|
||||||
|
|
@ -103,6 +109,11 @@ class AssetMasterView(FarmOSMasterView):
|
||||||
g.set_sorter("archived", SimpleSorter("archived"))
|
g.set_sorter("archived", SimpleSorter("archived"))
|
||||||
g.set_filter("archived", BooleanFilter)
|
g.set_filter("archived", BooleanFilter)
|
||||||
|
|
||||||
|
def render_grid_thumbnail(self, obj, field, value):
|
||||||
|
if url := obj.get("thumbnail_url"):
|
||||||
|
return tags.image(url, f"thumbnail for {self.get_model_title()}")
|
||||||
|
return None
|
||||||
|
|
||||||
def render_owners_for_grid(self, asset, field, value):
|
def render_owners_for_grid(self, asset, field, value):
|
||||||
owners = []
|
owners = []
|
||||||
for user in value:
|
for user in value:
|
||||||
|
|
@ -203,6 +214,7 @@ class AssetMasterView(FarmOSMasterView):
|
||||||
owner_names = []
|
owner_names = []
|
||||||
location_objects = []
|
location_objects = []
|
||||||
location_names = []
|
location_names = []
|
||||||
|
thumbnail_url = None
|
||||||
if relationships := asset.get("relationships"):
|
if relationships := asset.get("relationships"):
|
||||||
|
|
||||||
if owners := relationships.get("owner"):
|
if owners := relationships.get("owner"):
|
||||||
|
|
@ -226,6 +238,13 @@ class AssetMasterView(FarmOSMasterView):
|
||||||
location_objects.append(location)
|
location_objects.append(location)
|
||||||
location_names.append(location["name"])
|
location_names.append(location["name"])
|
||||||
|
|
||||||
|
if images := relationships.get("image"):
|
||||||
|
for image in images["data"]:
|
||||||
|
if image := included.get(image["id"]):
|
||||||
|
thumbnail_url = image["attributes"]["image_style_uri"][
|
||||||
|
"thumbnail"
|
||||||
|
]
|
||||||
|
|
||||||
return {
|
return {
|
||||||
"uuid": asset["id"],
|
"uuid": asset["id"],
|
||||||
"drupal_id": asset["attributes"]["drupal_internal__id"],
|
"drupal_id": asset["attributes"]["drupal_internal__id"],
|
||||||
|
|
@ -237,6 +256,7 @@ class AssetMasterView(FarmOSMasterView):
|
||||||
"locations": location_objects,
|
"locations": location_objects,
|
||||||
"location_names": location_names,
|
"location_names": location_names,
|
||||||
"archived": archived,
|
"archived": archived,
|
||||||
|
"thumbnail_url": thumbnail_url,
|
||||||
}
|
}
|
||||||
|
|
||||||
def configure_form(self, form):
|
def configure_form(self, form):
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue