Skip to content

Commit

Permalink
rename functions and variables, fix grammar, and allow for views to b…
Browse files Browse the repository at this point in the history
…e None
  • Loading branch information
RuthShryock committed Nov 27, 2024
1 parent 43ce879 commit bd5c994
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 10 deletions.
2 changes: 1 addition & 1 deletion kobo/apps/audit_log/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -610,7 +610,7 @@ def create_from_related_request(
action = modify_action
if action:
# some actions on related objects do not need to be logged,
# eg deleting an SubmissionExportTask
# eg deleting a SubmissionExportTask
ProjectHistoryLog.objects.create(
user=request.user, object_id=object_id, action=action, metadata=metadata
)
Expand Down
16 changes: 9 additions & 7 deletions kpi/models/import_export_task.py
Original file line number Diff line number Diff line change
Expand Up @@ -495,15 +495,17 @@ def default_email_subject(self) -> str:
return 'Report Complete'

def _get_export_details(self) -> tuple:
return self.data['type'], self.data['view']
return self.data.get('type'), self.data.get('view', None)

def _build_export_filename(
self, export_type: str, username: str, view: str
self, export_type: str, username: str, view: str = None
) -> str:
time = timezone.now().strftime('%Y-%m-%dT%H:%M:%SZ')
return f'{export_type}-{username}-view_{view}-{time}.csv'
if view:
return f'{export_type}-{username}-view_{view}-{time}.csv'
return f'{export_type}-{username}-{time}.csv'

def _run_task_base(self, messages: list, buff) -> None:
def _export_data_to_file(self, messages: list, buff) -> None:
export_type, view = self._get_export_details()
filename = self._build_export_filename(export_type, self.user.username, view)
absolute_filepath = self.get_absolute_filepath(filename)
Expand Down Expand Up @@ -565,14 +567,14 @@ def _run_task(self, messages: list) -> None:
'ip_address',
'initial_user_username',
'initial_user_uid',
'auth_app_name',
'authorized_app_name',
]
for row in data:
row['other_details'] = filter_remaining_metadata(
row, accessed_metadata_fields
)
buff = create_data_export(export_type, data)
self._run_task_base(messages, buff)
self._export_data_to_file(messages, buff)


class ProjectViewExportTask(ExportTaskMixin, ImportExportTask):
Expand Down Expand Up @@ -605,7 +607,7 @@ def _run_task(self, messages: list) -> None:

data = self.get_data(queryset)
buff = create_data_export(export_type, data)
self._run_task_base(messages, buff)
self._export_data_to_file(messages, buff)


class SubmissionExportTaskBase(ImportExportTask):
Expand Down
4 changes: 2 additions & 2 deletions kpi/tests/test_access_logs_export_task.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ def create_export_task(self, user, get_all_logs=True):
return AccessLogExportTask.objects.create(
user=user,
get_all_logs=get_all_logs,
data={'view': 'assets', 'type': 'access_logs_export'},
data={'type': 'access_logs_export'},
)

def test_task_initialization(self):
Expand Down Expand Up @@ -54,7 +54,7 @@ def test_run_task_creates_csv(self):
self.assertIsNotNone(task.result, 'The task.result should not be None.')
expected_pattern = (
rf'{self.superuser.username}/exports/access_logs_export-'
rf'{self.superuser.username}-view_assets-'
rf'{self.superuser.username}-'
r'\d{4}-\d{2}-\d{2}T\d{6}Z\.csv'
)

Expand Down

0 comments on commit bd5c994

Please sign in to comment.