-
-
Notifications
You must be signed in to change notification settings - Fork 218
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Added Enterprise Data Exports Report #35462
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,6 +10,13 @@ | |
from couchforms.analytics import get_last_form_submission_received | ||
from dimagi.utils.dates import DateSpan | ||
|
||
from corehq.apps.users.models import WebUser | ||
from corehq.apps.export.dbaccessors import ( | ||
get_brief_exports, | ||
is_standard, | ||
is_daily_saved_export, | ||
is_excel_integration | ||
) | ||
from corehq.apps.enterprise.exceptions import EnterpriseReportError, TooMuchRequestedDataError | ||
from corehq.apps.enterprise.iterators import raise_after_max_elements | ||
from corehq.apps.accounting.models import BillingAccount | ||
|
@@ -34,6 +41,7 @@ class EnterpriseReport: | |
MOBILE_USERS = 'mobile_users' | ||
FORM_SUBMISSIONS = 'form_submissions' | ||
ODATA_FEEDS = 'odata_feeds' | ||
DATA_EXPORTS = 'data_exports' | ||
|
||
DATE_ROW_FORMAT = '%Y/%m/%d %H:%M:%S' | ||
|
||
|
@@ -67,6 +75,8 @@ def create(cls, slug, account_id, couch_user, **kwargs): | |
report = EnterpriseFormReport(account, couch_user, **kwargs) | ||
elif slug == cls.ODATA_FEEDS: | ||
report = EnterpriseODataReport(account, couch_user, **kwargs) | ||
elif slug == cls.DATA_EXPORTS: | ||
report = EnterpriseDataExportReport(account, couch_user, **kwargs) | ||
|
||
if report: | ||
report.slug = slug | ||
|
@@ -383,3 +393,68 @@ def _get_individual_export_rows(self, exports, export_line_counts): | |
) | ||
|
||
return rows | ||
|
||
|
||
class EnterpriseDataExportReport(EnterpriseReport): | ||
title = gettext_lazy('Data Exports') | ||
|
||
def __init__(self, account, couch_user): | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Tada! Got you! Same issue as mine when you reviewed my PR lol. |
||
super().__init__(account, couch_user) | ||
|
||
@property | ||
def headers(self): | ||
return [ | ||
_('Project Space'), | ||
_('Name'), | ||
_('Type'), | ||
_('SubType'), | ||
_('Created By'), | ||
] | ||
|
||
def type_lookup(self, doc_type): | ||
from corehq.apps.export.models.new import FormExportInstance, CaseExportInstance | ||
if doc_type == FormExportInstance.__name__: | ||
return _('Form') | ||
elif doc_type == CaseExportInstance.__name__: | ||
return _('Case') | ||
else: | ||
return _('Unknown') | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. In what case it will be unknown? |
||
|
||
SUBTYPE_MAP = { | ||
is_standard: gettext_lazy('Standard'), | ||
is_daily_saved_export: gettext_lazy('Daily Saved Export'), | ||
is_excel_integration: gettext_lazy('Excel Integration'), | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why we don't support PowerBi/tableau integration? |
||
} | ||
|
||
def subtype_lookup(self, export): | ||
for (is_subtype_fn, subtype) in self.SUBTYPE_MAP.items(): | ||
if is_subtype_fn(export): | ||
return subtype | ||
|
||
return _('Unknown') | ||
|
||
def user_lookup(self, owner_id): | ||
if not owner_id: | ||
return _('Unknown') | ||
|
||
owner = WebUser.get_by_user_id(owner_id) | ||
return owner.username | ||
|
||
def get_exports(self, domain_obj): | ||
valid_subtypes = self.SUBTYPE_MAP.values() | ||
return [ | ||
export for export in get_brief_exports(domain_obj.name) | ||
if self.subtype_lookup(export) in valid_subtypes | ||
] | ||
|
||
def rows_for_domain(self, domain_obj): | ||
return [[ | ||
domain_obj.name, | ||
export['name'], | ||
self.type_lookup(export['doc_type']), | ||
self.subtype_lookup(export), | ||
self.user_lookup(export['owner_id']), | ||
] for export in self.get_exports(domain_obj)] | ||
|
||
def total_for_domain(self, domain_obj): | ||
return len(self.get_exports(domain_obj)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I tested on staging, I can have two export in same domain, with same export_type, export_subtype and name. In this case, adding owner won't be helpful. Should we add some other attribute like export_id?