Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ This project (not yet) adheres to [Semantic Versioning](https://semver.org/spec/
- emails: add `get_from_email()` hook on `EmailBase` so projects can customize
the sender address without overriding `dispatch()`.
- exports: add ItemExportWithImageMixin to include images in exports
- exports: export each image on its own row to keep image links clickable

### Fixed

Expand Down
3 changes: 3 additions & 0 deletions adhocracy4/exports/mixins/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ class VirtualFieldMixin:
def get_virtual_fields(self, virtual):
return virtual

def get_extra_rows(self, item, names):
return []


class ExportModelFieldsMixin(VirtualFieldMixin):
"""
Expand Down
28 changes: 26 additions & 2 deletions adhocracy4/exports/mixins/general.py
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ def get_virtual_fields(self, virtual):
virtual["images"] = _("Images")
return super().get_virtual_fields(virtual)

def get_images_data(self, item):
def get_images(self, item):
images = []

if item.image:
Expand All @@ -130,4 +130,28 @@ def get_images_data(self, item):
for url in re.findall(pattern, description):
images.append(self.request.build_absolute_uri(url))

return "; ".join(images) if images else ""
return images

def get_images_data(self, item):
images = self.get_images(item)
return images[0] if images else ""

def get_extra_rows(self, item, names):
images = self.get_images(item)
if len(images) <= 1:
return []

images_index = names.index("images")
reference_number_index = (
names.index("reference_number") if "reference_number" in names else None
)
extra_rows = []
for url in images[1:]:
extra_row = [""] * len(names)
extra_row[images_index] = url
if reference_number_index is not None:
extra_row[reference_number_index] = self.get_field_data(
item, "reference_number"
)
extra_rows.append(extra_row)
return extra_rows
5 changes: 4 additions & 1 deletion adhocracy4/exports/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,10 @@ def export_rows(self):
names, _ = self.get_fields()

for item in self.get_object_list():
yield [self.get_field_data(item, name) for name in names]
row = [self.get_field_data(item, name) for name in names]
yield row
for extra_row in self.get_extra_rows(item, names):
yield extra_row

def get_field_data(self, item, name):
# Use custom getters if they are defined
Expand Down
Loading