Skip to content

Commit

Permalink
Simplify Enterprise OData Report and API
Browse files Browse the repository at this point in the history
  • Loading branch information
mjriley committed Dec 12, 2024
1 parent ee30561 commit fe05ecc
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 49 deletions.
16 changes: 6 additions & 10 deletions corehq/apps/enterprise/api/resources.py
Original file line number Diff line number Diff line change
Expand Up @@ -369,10 +369,8 @@ class ODataFeedResource(ODataEnterpriseReportResource):
Currently includes summary rows as well as individual reports
'''

domain = fields.CharField(null=True)
num_feeds_used = fields.IntegerField(null=True)
num_feeds_available = fields.IntegerField(null=True)
report_name = fields.CharField(null=True)
domain = fields.CharField()
report_name = fields.CharField()
report_rows = fields.IntegerField(null=True)

REPORT_SLUG = EnterpriseReport.ODATA_FEEDS
Expand All @@ -386,16 +384,14 @@ def get_report_task(self, request):
)

def dehydrate(self, bundle):
bundle.data['num_feeds_used'] = bundle.obj[0]
bundle.data['num_feeds_available'] = bundle.obj[1]
bundle.data['report_name'] = bundle.obj[2]
bundle.data['report_rows'] = bundle.obj[3]
bundle.data['domain'] = bundle.obj[5] if len(bundle.obj) >= 5 else None
bundle.data['domain'] = bundle.obj[0]
bundle.data['report_name'] = bundle.obj[1]
bundle.data['report_rows'] = bundle.obj[2]

return bundle

def get_primary_keys(self):
return ('report_name',) # very odd report that makes coming up with an actual key challenging
return ('domain', 'report_name',)


class FormSubmissionResource(ODataEnterpriseReportResource):
Expand Down
49 changes: 10 additions & 39 deletions corehq/apps/enterprise/enterprise.py
Original file line number Diff line number Diff line change
Expand Up @@ -358,56 +358,27 @@ def __init__(self, account, couch_user):

@property
def headers(self):
headers = super().headers
return [_('Odata feeds used'), _('Odata feeds available'), _('Report Names'),
_('Number of rows')] + headers
return [_('Project Space'), _('Report Names'), _('Number of rows')]

def total_for_domain(self, domain_obj):
return self.export_fetcher.get_export_count(domain_obj.name)

def rows_for_domain(self, domain_obj):
export_count = self.total_for_domain(domain_obj)
if export_count == 0 or export_count > self.MAXIMUM_EXPECTED_EXPORTS:
return [self._get_domain_summary_line(domain_obj, export_count)]

exports = self.export_fetcher.get_exports(domain_obj.name)

export_line_counts = self._get_export_line_counts(exports)

domain_summary_line = self._get_domain_summary_line(domain_obj, export_count, export_line_counts)
individual_export_rows = self._get_individual_export_rows(exports, export_line_counts)

rows = [domain_summary_line]
rows.extend(individual_export_rows)
return rows

def _get_export_line_counts(self, exports):
return {export._id: export.get_count() for export in exports}

def _get_domain_summary_line(self, domain_obj, export_count, export_line_counts={}):
if export_count > self.MAXIMUM_EXPECTED_EXPORTS:
total_line_count = _('ERROR: Too many exports. Please contact customer service')
else:
total_line_count = sum(export_line_counts.values())

return [
export_count,
domain_obj.get_odata_feed_limit(),
None, # Report Name
total_line_count
] + self.domain_properties(domain_obj)
return [
[
domain_obj.name,
_('ERROR: Too many exports. Please contact customer service'),
None,
]
]

def _get_individual_export_rows(self, exports, export_line_counts):
exports = self.export_fetcher.get_exports(domain_obj.name)
rows = []

for export in exports:
count = export_line_counts[export._id]
rows.append([
None, # OData feeds used
None, # OData feeds available
export.name,
count]
)
rows.append([domain_obj.name, export.name, export.get_count()])

return rows

Expand Down

0 comments on commit fe05ecc

Please sign in to comment.