diff --git a/reporting/models.py b/reporting/models.py index fb508cbc..4f8c1ea9 100644 --- a/reporting/models.py +++ b/reporting/models.py @@ -68,7 +68,7 @@ LICENSE_TAG_PREFIX = "tag: " -MULTIVALUE_SEPARATOR = ", " +MULTIVALUE_SEPARATOR = "\n" ERROR_STR = "Error" @@ -674,7 +674,12 @@ def get_value_for_instance(self, instance, user=None): for field_name in self.field_name.split("__"): objects = self._get_objects_for_field_name(objects, field_name, user) - return [str(val) for val in objects if not (len(objects) < 2 and val is None)] + return [ + # The .strip() ensure the SafeString types are casted to regular str + str(val).strip() + for val in objects + if not (len(objects) < 2 and val is None) + ] class ReportQuerySet(DataspacedQuerySet): @@ -746,7 +751,7 @@ def save(self, *args, **kwargs): def get_absolute_url(self): return reverse("reporting:report_details", args=[self.uuid]) - def get_output(self, queryset=None, user=None, include_view_link=False): + def get_output(self, queryset=None, user=None, include_view_link=False, multi_as_list=False): # Checking if the parameter is given rather than the boolean value of the QuerySet if queryset is None: queryset = self.query.get_qs(user=user) @@ -762,7 +767,15 @@ def get_output(self, queryset=None, user=None, include_view_link=False): for field in self.column_template.fields.all(): value = field.get_value_for_instance(instance, user=user) - cells.append(MULTIVALUE_SEPARATOR.join(value)) + if not multi_as_list: + cells.append(MULTIVALUE_SEPARATOR.join(value)) + else: + if value == []: + cells.append("") + elif len(value) > 1: + cells.append(value) + else: + cells.append(value[0]) rows.append(cells) diff --git a/reporting/views.py b/reporting/views.py index ea9f28ff..a64857e4 100644 --- a/reporting/views.py +++ b/reporting/views.py @@ -193,10 +193,12 @@ def get_context_data(self, **kwargs): # Only available in the UI since the link is relative to the current URL include_view_link = not self.format and hasattr(model_class, "get_absolute_url") interpolated_report_context = self.get_interpolated_report_context(request, report) + multi_as_list = True if self.format in ["json", "yaml"] else False output = report.get_output( queryset=context["object_list"], user=request.user, include_view_link=include_view_link, + multi_as_list=multi_as_list, ) context.update(