From 5ebbffdddc5abf0a65174250ac7b7137fd620afc Mon Sep 17 00:00:00 2001 From: Davis Raymond Muro Date: Fri, 14 Aug 2020 17:16:08 +0300 Subject: [PATCH] Add "INSTANCE_CREATE_EVENT" and "INSTANCE_UPDATE_EVENT" common tags --- onadata/libs/utils/analytics.py | 6 ++++-- onadata/libs/utils/common_tags.py | 3 +++ onadata/libs/utils/csv_import.py | 8 +++++--- 3 files changed, 12 insertions(+), 5 deletions(-) diff --git a/onadata/libs/utils/analytics.py b/onadata/libs/utils/analytics.py index 8be00e613f..895e802b4c 100644 --- a/onadata/libs/utils/analytics.py +++ b/onadata/libs/utils/analytics.py @@ -10,6 +10,8 @@ from django.utils import timezone from onadata.apps.logger.models import Instance +from onadata.libs.utils.common_tags import ( + INSTANCE_CREATE_EVENT, INSTANCE_UPDATE_EVENT) _segment = False @@ -95,9 +97,9 @@ def get_event_name(self) -> str: if isinstance(self.tracked_obj, Instance) and not event_name: last_edited = self.tracked_obj.last_edited if last_edited and last_edited > self.event_start: - event_name = 'Submission updated' + event_name = INSTANCE_UPDATE_EVENT else: - event_name = 'Submission created' + event_name = INSTANCE_CREATE_EVENT return event_name def get_event_label(self) -> str: diff --git a/onadata/libs/utils/common_tags.py b/onadata/libs/utils/common_tags.py index 7f3fd53842..2484dcd4a1 100644 --- a/onadata/libs/utils/common_tags.py +++ b/onadata/libs/utils/common_tags.py @@ -181,3 +181,6 @@ '_submission_time', '_xform_id' ] + +INSTANCE_CREATE_EVENT = 'Submission created' +INSTANCE_UPDATE_EVENT = 'Submission updated' diff --git a/onadata/libs/utils/csv_import.py b/onadata/libs/utils/csv_import.py index 6cf37c13e6..6034c50487 100644 --- a/onadata/libs/utils/csv_import.py +++ b/onadata/libs/utils/csv_import.py @@ -35,7 +35,9 @@ celery_state_to_status) from onadata.libs.utils.common_tags import (MULTIPLE_SELECT_TYPE, EXCEL_TRUE, XLS_DATE_FIELDS, - XLS_DATETIME_FIELDS, UUID, NA_REP) + XLS_DATETIME_FIELDS, UUID, NA_REP, + INSTANCE_CREATE_EVENT, + INSTANCE_UPDATE_EVENT) from onadata.libs.utils.common_tools import report_exception from onadata.libs.utils.dict_tools import csv_dict_to_nested_dict from onadata.libs.utils.logger_tools import (OpenRosaResponse, dict2xml, @@ -441,10 +443,10 @@ def submit_csv(username, xform, csv_file, overwrite=False): } if added_submissions > 0: tracking_properties['value'] = added_submissions - event_name = 'Submission created' + event_name = INSTANCE_CREATE_EVENT if inserts > 0: tracking_properties['value'] = inserts - event_name = 'Submission updated' + event_name = INSTANCE_UPDATE_EVENT if event_name: analytics.track(