Skip to content

Commit

Permalink
feat: append security classification to downloaded file names (#2818)
Browse files Browse the repository at this point in the history
  • Loading branch information
niross authored Nov 2, 2023
1 parent 0e26100 commit b867ab9
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 6 deletions.
19 changes: 17 additions & 2 deletions dataworkspace/dataworkspace/apps/datasets/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -723,7 +723,11 @@ def source_reference(self):
return None

def get_filename(self, extension=".csv"):
filename = slugify(self.name) + extension # pylint: disable=no-member
sec_class = self.dataset.get_government_security_classification_display()
# pylint: disable=no-member
filename = (
f"{slugify(self.name)}{f'-{sec_class}' if sec_class is not None else ''}{extension}"
)
if self.source_reference is not None:
return f"{self.source_reference}-{filename}"
return filename
Expand Down Expand Up @@ -900,6 +904,10 @@ def get_pipeline_last_success_date(self):
def pipeline_last_run_success(self):
return self.get_pipeline_last_run_state() in ["success", None]

def get_custom_export_file_name(self):
sec_class = self.dataset.get_government_security_classification_display()
return f"{self.name}-custom-export{f'-{sec_class}' if sec_class is not None else ''}.csv"


class SourceTableFieldDefinition(models.Model):
field = models.CharField(
Expand Down Expand Up @@ -1016,7 +1024,6 @@ def get_filename(self): # pylint: disable=arguments-differ
native_extension = os.path.splitext(self.url)[1]
extension = native_extension if native_extension else ".csv"
return super().get_filename(extension=extension)

return super().get_filename()

@property
Expand Down Expand Up @@ -1211,6 +1218,10 @@ def get_chart_builder_query(self):
def get_save_grid_view_url(self):
return reverse("datasets:custom_dataset_query_save_grid_view", args=(self.id,))

def get_custom_export_file_name(self):
sec_class = self.dataset.get_government_security_classification_display()
return f"{self.name}-custom-export{f'-{sec_class}' if sec_class is not None else ''}.csv"


class CustomDatasetQueryTable(models.Model):
query = models.ForeignKey(CustomDatasetQuery, on_delete=models.CASCADE, related_name="tables")
Expand Down Expand Up @@ -2084,6 +2095,10 @@ def get_grid_data_url(self):
def get_save_grid_view_url(self):
return reverse("datasets:reference_dataset_save_grid_view", args=(self.id,))

def get_custom_export_file_name(self):
sec_class = self.get_government_security_classification_display()
return f"{self.slug}-{self.published_version}-custom-export{f'-{sec_class}' if sec_class is not None else ''}.csv"


@receiver(m2m_changed, sender=ReferenceDataset.tags.through)
def save_reference_dataset_tags_on_m2m_changed(instance, **_):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
'{{ object.get_grid_data_url }}',
'?download=1',
null,
'{{ object.name }}-custom-export.csv',
'{{ object.get_custom_export_file_name }}',
{% flag CHART_BUILDER_BUILD_CHARTS_FLAG %}
'{% url 'datasets:create_chart_from_grid' object.dataset.id object.id %}',
{% else %}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
'{{ object.get_grid_data_url }}',
'?download=1',
null,
'{{ object.name }}-custom-export.csv',
'{{ object.get_custom_export_file_name }}',
{% flag CHART_BUILDER_BUILD_CHARTS_FLAG %}
'{% url 'datasets:create_chart_from_grid' object.dataset.id object.id %}',
{% else %}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
null,
null,
JSON.parse(document.getElementById('grid_data').textContent),
'{{ model.slug }}-{{ model.published_version }}-custom-export.csv',
'{{ model.get_custom_export_file_name }}',
null,
'{{ model.send_post_data_url}}',
'{{ model.id }}',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
null,
null,
JSON.parse(document.getElementById('grid_data').textContent),
'{{ model.slug }}-{{ model.published_version }}-custom-export.csv',
'{{ model.get_custom_export_file_name }}',
null,
'{{ model.send_post_data_url}}',
'{{ model.id }}',
Expand Down

0 comments on commit b867ab9

Please sign in to comment.