Skip to content

Commit

Permalink
Refactor: move get_report_task to the base class
Browse files Browse the repository at this point in the history
  • Loading branch information
jingcheng16 committed Dec 3, 2024
1 parent 981520f commit 5a77507
Showing 1 changed file with 6 additions and 41 deletions.
47 changes: 6 additions & 41 deletions corehq/apps/enterprise/api/resources.py
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,12 @@ def get_object_list(self, request):
response=http.HttpTooManyRequests(headers={'Retry-After': self.RETRY_IN_PROGRESS_DELAY}))

def get_report_task(self, request):
raise NotImplementedError()
account = BillingAccount.get_account_by_domain(request.domain)
return generate_enterprise_report.s(
self.REPORT_SLUG,
account.id,
request.couch_user.username,
)

def _add_query_id_to_request(self, request, query_id):
if 'report' not in request.GET:
Expand All @@ -213,14 +218,6 @@ class DomainResource(ODataEnterpriseReportResource):

REPORT_SLUG = EnterpriseReport.DOMAINS

def get_report_task(self, request):
account = BillingAccount.get_account_by_domain(request.domain)
return generate_enterprise_report.s(
self.REPORT_SLUG,
account.id,
request.couch_user.username,
)

def dehydrate(self, bundle):
bundle.data['domain'] = bundle.obj[6]
bundle.data['created_on'] = self.convert_datetime(bundle.obj[0])
Expand All @@ -247,14 +244,6 @@ class WebUserResource(ODataEnterpriseReportResource):

REPORT_SLUG = EnterpriseReport.WEB_USERS

def get_report_task(self, request):
account = BillingAccount.get_account_by_domain(request.domain)
return generate_enterprise_report.s(
self.REPORT_SLUG,
account.id,
request.couch_user.username,
)

def dehydrate(self, bundle):
bundle.data['email'] = bundle.obj[0]
bundle.data['name'] = self.convert_not_available(bundle.obj[1])
Expand Down Expand Up @@ -288,14 +277,6 @@ class MobileUserResource(ODataEnterpriseReportResource):

REPORT_SLUG = EnterpriseReport.MOBILE_USERS

def get_report_task(self, request):
account = BillingAccount.get_account_by_domain(request.domain)
return generate_enterprise_report.s(
self.REPORT_SLUG,
account.id,
request.couch_user.username,
)

def dehydrate(self, bundle):
bundle.data['username'] = bundle.obj[0]
bundle.data['name'] = bundle.obj[1]
Expand Down Expand Up @@ -328,14 +309,6 @@ class ODataFeedResource(ODataEnterpriseReportResource):

REPORT_SLUG = EnterpriseReport.ODATA_FEEDS

def get_report_task(self, request):
account = BillingAccount.get_account_by_domain(request.domain)
return generate_enterprise_report.s(
self.REPORT_SLUG,
account.id,
request.couch_user.username,
)

def dehydrate(self, bundle):
bundle.data['num_feeds_used'] = bundle.obj[0]
bundle.data['num_feeds_available'] = bundle.obj[1]
Expand Down Expand Up @@ -398,14 +371,6 @@ class CommCareVersionComplianceResource(ODataEnterpriseReportResource):

REPORT_SLUG = EnterpriseReport.COMMCARE_VERSION_COMPLIANCE

def get_report_task(self, request):
account = BillingAccount.get_account_by_domain(request.domain)
return generate_enterprise_report.s(
self.REPORT_SLUG,
account.id,
request.couch_user.username,
)

def dehydrate(self, bundle):
bundle.data['mobile_worker'] = bundle.obj[0]
bundle.data['project_space'] = bundle.obj[1]
Expand Down

0 comments on commit 5a77507

Please sign in to comment.