From 30a284a92e804cfd135a6780084652b893d68199 Mon Sep 17 00:00:00 2001 From: Zandre Engelbrecht Date: Mon, 10 Jun 2024 11:07:51 +0200 Subject: [PATCH 01/20] add new loc col --- corehq/apps/reports/standard/deployments.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/corehq/apps/reports/standard/deployments.py b/corehq/apps/reports/standard/deployments.py index 2a859ac8f4e6..7c3276eb830c 100644 --- a/corehq/apps/reports/standard/deployments.py +++ b/corehq/apps/reports/standard/deployments.py @@ -81,6 +81,9 @@ def _columns(self): DataTablesColumn(_("Username"), prop_name='username.exact', sql_col='user_dim__username'), + DataTablesColumn(_("Assigned Location(s)"), + help_text=_('The location(s) that the user is assigned to'), + sortable=False), DataTablesColumn(_("Last Submission"), prop_name='reporting_metadata.last_submissions.submission_date', alt_prop_name='reporting_metadata.last_submission_for_user.submission_date', @@ -119,7 +122,7 @@ def headers(self): sortable=False) ) headers = DataTablesHeader(*columns) - headers.custom_sort = [[1, 'desc']] + headers.custom_sort = [[2, 'desc']] return headers @cached_property From de825b1f463a7e8d84fac41441ff5da11ffebeef Mon Sep 17 00:00:00 2001 From: Zandre Engelbrecht Date: Wed, 12 Jun 2024 10:58:45 +0200 Subject: [PATCH 02/20] refactor help text --- corehq/apps/reports/standard/deployments.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/corehq/apps/reports/standard/deployments.py b/corehq/apps/reports/standard/deployments.py index 7c3276eb830c..0b30084d6752 100644 --- a/corehq/apps/reports/standard/deployments.py +++ b/corehq/apps/reports/standard/deployments.py @@ -82,7 +82,8 @@ def _columns(self): prop_name='username.exact', sql_col='user_dim__username'), DataTablesColumn(_("Assigned Location(s)"), - help_text=_('The location(s) that the user is assigned to'), + help_text=_('The location(s) that the user is assigned to, ' + 'including the primary location which is highlighted in bold.'), sortable=False), DataTablesColumn(_("Last Submission"), prop_name='reporting_metadata.last_submissions.submission_date', From 07b58280ce9eb3c9503562e38ce59e8970ec102b Mon Sep 17 00:00:00 2001 From: Zandre Engelbrecht Date: Wed, 12 Jun 2024 10:59:24 +0200 Subject: [PATCH 03/20] add loc data to assigned loc col --- corehq/apps/reports/standard/deployments.py | 35 +++++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/corehq/apps/reports/standard/deployments.py b/corehq/apps/reports/standard/deployments.py index 0b30084d6752..436ded11b7ae 100644 --- a/corehq/apps/reports/standard/deployments.py +++ b/corehq/apps/reports/standard/deployments.py @@ -377,6 +377,7 @@ def process_rows(self, users, fmt_for_export=False): user_display_string(user.get('username', ''), user.get('first_name', ''), user.get('last_name', '')), + self.get_location_column(user), _fmt_date(last_seen, fmt_for_export), _fmt_date(last_sync_date, fmt_for_export), app_name or "---", build_version, commcare_version or '---', num_unsent_forms if num_unsent_forms is not None else "---", @@ -487,6 +488,40 @@ def _fmt_timestamp(timestamp): result[0][1] = table return result + def get_location_column(self, user): + assigned_loc_ids = user.get('assigned_location_ids') + if not assigned_loc_ids: + return '---' + primary_loc_id = user.get('location_id') + return self._get_formatted_assigned_location_names(primary_loc_id, assigned_loc_ids) + + def _get_formatted_assigned_location_names(self, primary_location_id, assigned_location_ids): + """ + Create an HTML formatted string of the given assigned location names. + The primary location will be highlighted in bold. + """ + locs = SQLLocation.objects.filter(location_id__in=assigned_location_ids) + formatted_loc_names = [] + for loc in locs: + if loc.location_id == primary_location_id and len(assigned_location_ids) > 1: + formatted_loc_names.append( + f'{loc.name}' + ) + else: + formatted_loc_names.append(loc.name) + + formatted_str = ', '.join(formatted_loc_names[:4]) + all_str = ', '.join(formatted_loc_names) + eplise_str = _('...See more') if len(formatted_loc_names) > 4 else '' + out_str = (''' +
+ {} + {} + +
+ ''').format(formatted_str, eplise_str, all_str) + return format_html(out_str) + def _get_commcare_version(app_version_info): commcare_version = ( From c229c7ab2fdf8684a311e1f5010c93759eeb76c9 Mon Sep 17 00:00:00 2001 From: Zandre Engelbrecht Date: Wed, 12 Jun 2024 10:59:52 +0200 Subject: [PATCH 04/20] add JS to handle toggling see more link --- .../reports/js/bootstrap3/application_status.js | 15 +++++++++++++++ .../reports/js/bootstrap5/application_status.js | 15 +++++++++++++++ .../standard/bootstrap3/base_template.html | 1 + .../standard/bootstrap5/base_template.html | 1 + 4 files changed, 32 insertions(+) create mode 100644 corehq/apps/reports/static/reports/js/bootstrap3/application_status.js create mode 100644 corehq/apps/reports/static/reports/js/bootstrap5/application_status.js diff --git a/corehq/apps/reports/static/reports/js/bootstrap3/application_status.js b/corehq/apps/reports/static/reports/js/bootstrap3/application_status.js new file mode 100644 index 000000000000..1a833dc2e359 --- /dev/null +++ b/corehq/apps/reports/static/reports/js/bootstrap3/application_status.js @@ -0,0 +1,15 @@ +'use strict'; +hqDefine("reports/js/bootstrap3/application_status", [ + "jquery", +], function ( + $ +) { + $(function () { + $('#report-content').on('click', '.toggle-all-locations', function (e) { + $(this).prevAll('.locations-list').toggle(); + $(this).toggle(); + $(this).nextAll('.all-locations-list').toggle(); + e.preventDefault(); + }); + }); +}); \ No newline at end of file diff --git a/corehq/apps/reports/static/reports/js/bootstrap5/application_status.js b/corehq/apps/reports/static/reports/js/bootstrap5/application_status.js new file mode 100644 index 000000000000..8ca0dde47ee3 --- /dev/null +++ b/corehq/apps/reports/static/reports/js/bootstrap5/application_status.js @@ -0,0 +1,15 @@ +'use strict'; +hqDefine("reports/js/bootstrap5/application_status", [ + "jquery", +], function ( + $ +) { + $(function () { + $('#report-content').on('click', '.toggle-all-locations', function (e) { + $(this).prevAll('.locations-list').toggle(); + $(this).toggle(); + $(this).nextAll('.all-locations-list').toggle(); + e.preventDefault(); + }); + }); +}); \ No newline at end of file diff --git a/corehq/apps/reports/templates/reports/standard/bootstrap3/base_template.html b/corehq/apps/reports/templates/reports/standard/bootstrap3/base_template.html index 127918c16f50..aa62e3737d05 100644 --- a/corehq/apps/reports/templates/reports/standard/bootstrap3/base_template.html +++ b/corehq/apps/reports/templates/reports/standard/bootstrap3/base_template.html @@ -36,6 +36,7 @@ + diff --git a/corehq/apps/reports/templates/reports/standard/bootstrap5/base_template.html b/corehq/apps/reports/templates/reports/standard/bootstrap5/base_template.html index 5c6463780a43..2aa429586c16 100644 --- a/corehq/apps/reports/templates/reports/standard/bootstrap5/base_template.html +++ b/corehq/apps/reports/templates/reports/standard/bootstrap5/base_template.html @@ -36,6 +36,7 @@ + From d60fcbdfe511d387a23d7bbeb918eccdcd46cab1 Mon Sep 17 00:00:00 2001 From: Zandre Engelbrecht Date: Wed, 12 Jun 2024 11:30:12 +0200 Subject: [PATCH 05/20] Bootstrap 5 Migration - Rebuilt diffs --- .../reports/js/application_status.js.diff.txt | 9 +++++++++ .../reports/standard/base_template.html.diff.txt | 12 +++++++----- 2 files changed, 16 insertions(+), 5 deletions(-) create mode 100644 corehq/apps/hqwebapp/tests/data/bootstrap5_diffs/javascript/reports/js/application_status.js.diff.txt diff --git a/corehq/apps/hqwebapp/tests/data/bootstrap5_diffs/javascript/reports/js/application_status.js.diff.txt b/corehq/apps/hqwebapp/tests/data/bootstrap5_diffs/javascript/reports/js/application_status.js.diff.txt new file mode 100644 index 000000000000..0e67208e3293 --- /dev/null +++ b/corehq/apps/hqwebapp/tests/data/bootstrap5_diffs/javascript/reports/js/application_status.js.diff.txt @@ -0,0 +1,9 @@ +--- ++++ +@@ -1,5 +1,5 @@ + 'use strict'; +-hqDefine("reports/js/bootstrap3/application_status", [ ++hqDefine("reports/js/bootstrap5/application_status", [ + "jquery", + ], function ( + $ diff --git a/corehq/apps/hqwebapp/tests/data/bootstrap5_diffs/reports/standard/base_template.html.diff.txt b/corehq/apps/hqwebapp/tests/data/bootstrap5_diffs/reports/standard/base_template.html.diff.txt index 7b449f35c29a..d34556b3fd1e 100644 --- a/corehq/apps/hqwebapp/tests/data/bootstrap5_diffs/reports/standard/base_template.html.diff.txt +++ b/corehq/apps/hqwebapp/tests/data/bootstrap5_diffs/reports/standard/base_template.html.diff.txt @@ -1,6 +1,6 @@ --- +++ -@@ -1,44 +1,44 @@ +@@ -1,45 +1,45 @@ -{% extends "hqwebapp/bootstrap3/two_column.html" %} +{% extends "hqwebapp/bootstrap5/two_column.html" %} {% load compress %} @@ -48,8 +48,10 @@ - - +- + + ++ - @@ -57,7 +59,7 @@ {% endcompress %} {% endblock %} -@@ -58,8 +58,8 @@ +@@ -59,8 +59,8 @@ {% block title %}{{ report.title|default:"Project Reports" }}{% endblock %} {% block page_breadcrumbs %} @@ -68,7 +70,7 @@
  • {% trans report.section_name|default:"Reports" %}
  • -@@ -98,17 +98,17 @@ +@@ -99,17 +99,17 @@ {% initial_page_data 'slug' report.slug %} {% block filter_panel %} @@ -90,7 +92,7 @@ aria-label="Close" data-bind="click: resetModal"> @@ -107,7 +109,7 @@

    {% trans 'Notice' %}

    {{ report.special_notice }}

    -@@ -137,7 +137,7 @@ +@@ -138,7 +138,7 @@ {% block reportcontent %} {% endblock %} {% else %} From 362e684582058c181a3d043fb73fbaa5cf491cb3 Mon Sep 17 00:00:00 2001 From: Zandre Engelbrecht Date: Thu, 13 Jun 2024 12:54:33 +0200 Subject: [PATCH 06/20] move up col index to account for new col --- corehq/apps/reports/standard/deployments.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/corehq/apps/reports/standard/deployments.py b/corehq/apps/reports/standard/deployments.py index 436ded11b7ae..07f15de05a94 100644 --- a/corehq/apps/reports/standard/deployments.py +++ b/corehq/apps/reports/standard/deployments.py @@ -482,9 +482,9 @@ def _fmt_timestamp(timestamp): for row in table[1:]: # Last submission - row[len(location_colums) + 1] = _fmt_timestamp(row[len(location_colums) + 1]) - # Last sync row[len(location_colums) + 2] = _fmt_timestamp(row[len(location_colums) + 2]) + # Last sync + row[len(location_colums) + 3] = _fmt_timestamp(row[len(location_colums) + 3]) result[0][1] = table return result From 561afac05c2a643648b1633077479634f74748bb Mon Sep 17 00:00:00 2001 From: Zandre Engelbrecht Date: Mon, 17 Jun 2024 11:07:57 +0200 Subject: [PATCH 07/20] move var to helper func --- corehq/apps/reports/standard/deployments.py | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/corehq/apps/reports/standard/deployments.py b/corehq/apps/reports/standard/deployments.py index 07f15de05a94..678af181f113 100644 --- a/corehq/apps/reports/standard/deployments.py +++ b/corehq/apps/reports/standard/deployments.py @@ -488,19 +488,17 @@ def _fmt_timestamp(timestamp): result[0][1] = table return result - def get_location_column(self, user): - assigned_loc_ids = user.get('assigned_location_ids') - if not assigned_loc_ids: + if not user.get('assigned_location_ids'): return '---' - primary_loc_id = user.get('location_id') - return self._get_formatted_assigned_location_names(primary_loc_id, assigned_loc_ids) + return self._get_formatted_assigned_location_names(user) - def _get_formatted_assigned_location_names(self, primary_location_id, assigned_location_ids): + def _get_formatted_assigned_location_names(self, user): """ Create an HTML formatted string of the given assigned location names. The primary location will be highlighted in bold. """ - locs = SQLLocation.objects.filter(location_id__in=assigned_location_ids) + assigned_location_ids = user.get('assigned_location_ids') + primary_location_id = user.get('location_id') formatted_loc_names = [] for loc in locs: if loc.location_id == primary_location_id and len(assigned_location_ids) > 1: From 78bb53d4477a313693f62dd4c93e913615ca250b Mon Sep 17 00:00:00 2001 From: Zandre Engelbrecht Date: Mon, 17 Jun 2024 11:09:50 +0200 Subject: [PATCH 08/20] make primary bold even if only 1 loc --- corehq/apps/reports/standard/deployments.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/corehq/apps/reports/standard/deployments.py b/corehq/apps/reports/standard/deployments.py index 678af181f113..5315d52cd742 100644 --- a/corehq/apps/reports/standard/deployments.py +++ b/corehq/apps/reports/standard/deployments.py @@ -501,7 +501,7 @@ def _get_formatted_assigned_location_names(self, user): primary_location_id = user.get('location_id') formatted_loc_names = [] for loc in locs: - if loc.location_id == primary_location_id and len(assigned_location_ids) > 1: + if loc.location_id == primary_location_id: formatted_loc_names.append( f'{loc.name}' ) From 7ebeb724ef171090285e0f99695bfa81350528a5 Mon Sep 17 00:00:00 2001 From: Zandre Engelbrecht Date: Mon, 17 Jun 2024 11:46:46 +0200 Subject: [PATCH 09/20] do single DB query for loc names --- corehq/apps/reports/standard/deployments.py | 26 +++++++++++++++------ 1 file changed, 19 insertions(+), 7 deletions(-) diff --git a/corehq/apps/reports/standard/deployments.py b/corehq/apps/reports/standard/deployments.py index 5315d52cd742..824dd31b9d8a 100644 --- a/corehq/apps/reports/standard/deployments.py +++ b/corehq/apps/reports/standard/deployments.py @@ -311,6 +311,15 @@ def include_location_data(self): ) ) + def user_locations_dict(self, users): + all_loc_ids = set() + for user in users: + for loc_id in user.get('assigned_location_ids'): + all_loc_ids.add(loc_id) + return dict(SQLLocation.objects.filter( + location_id__in=all_loc_ids + ).values_list('location_id', 'name')) + def process_rows(self, users, fmt_for_export=False): rows = [] users = list(users) @@ -320,6 +329,7 @@ def process_rows(self, users, fmt_for_export=False): grouped_ancestor_locs = self.get_bulk_ancestors(location_ids) self.required_loc_columns = self.get_location_columns(grouped_ancestor_locs) + user_loc_dict = self.user_locations_dict(users) for user in users: last_build = last_seen = last_sub = last_sync = last_sync_date = app_name = commcare_version = None last_build_profile_name = device = device_app_meta = num_unsent_forms = None @@ -377,7 +387,7 @@ def process_rows(self, users, fmt_for_export=False): user_display_string(user.get('username', ''), user.get('first_name', ''), user.get('last_name', '')), - self.get_location_column(user), + self.get_location_column(user, user_loc_dict), _fmt_date(last_seen, fmt_for_export), _fmt_date(last_sync_date, fmt_for_export), app_name or "---", build_version, commcare_version or '---', num_unsent_forms if num_unsent_forms is not None else "---", @@ -488,11 +498,12 @@ def _fmt_timestamp(timestamp): result[0][1] = table return result + def get_location_column(self, user, user_loc_dict): if not user.get('assigned_location_ids'): return '---' - return self._get_formatted_assigned_location_names(user) + return self._get_formatted_assigned_location_names(user, user_loc_dict) - def _get_formatted_assigned_location_names(self, user): + def _get_formatted_assigned_location_names(self, user, user_loc_dict): """ Create an HTML formatted string of the given assigned location names. The primary location will be highlighted in bold. @@ -500,13 +511,14 @@ def _get_formatted_assigned_location_names(self, user): assigned_location_ids = user.get('assigned_location_ids') primary_location_id = user.get('location_id') formatted_loc_names = [] - for loc in locs: - if loc.location_id == primary_location_id: + for loc_id in assigned_location_ids: + loc_name = user_loc_dict.get(loc_id) + if loc_id == primary_location_id: formatted_loc_names.append( - f'{loc.name}' + f'{loc_name}' ) else: - formatted_loc_names.append(loc.name) + formatted_loc_names.append(loc_name) formatted_str = ', '.join(formatted_loc_names[:4]) all_str = ', '.join(formatted_loc_names) From c1a088b0477ad503df92cf40494d1336f279d16a Mon Sep 17 00:00:00 2001 From: Zandre Engelbrecht Date: Tue, 18 Jun 2024 11:22:21 +0200 Subject: [PATCH 10/20] constrain assigned locations to domain --- corehq/apps/reports/standard/deployments.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/corehq/apps/reports/standard/deployments.py b/corehq/apps/reports/standard/deployments.py index 824dd31b9d8a..c6e59fb85f67 100644 --- a/corehq/apps/reports/standard/deployments.py +++ b/corehq/apps/reports/standard/deployments.py @@ -317,7 +317,7 @@ def user_locations_dict(self, users): for loc_id in user.get('assigned_location_ids'): all_loc_ids.add(loc_id) return dict(SQLLocation.objects.filter( - location_id__in=all_loc_ids + location_id__in=all_loc_ids, domain=self.domain ).values_list('location_id', 'name')) def process_rows(self, users, fmt_for_export=False): From 37c70b4e2870e07555d1930c9689fc2c03cbf724 Mon Sep 17 00:00:00 2001 From: Zandre Engelbrecht Date: Wed, 19 Jun 2024 12:53:36 +0200 Subject: [PATCH 11/20] refactor help text --- corehq/apps/reports/standard/deployments.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/corehq/apps/reports/standard/deployments.py b/corehq/apps/reports/standard/deployments.py index c6e59fb85f67..cfa178504cd8 100644 --- a/corehq/apps/reports/standard/deployments.py +++ b/corehq/apps/reports/standard/deployments.py @@ -82,8 +82,8 @@ def _columns(self): prop_name='username.exact', sql_col='user_dim__username'), DataTablesColumn(_("Assigned Location(s)"), - help_text=_('The location(s) that the user is assigned to, ' - 'including the primary location which is highlighted in bold.'), + help_text=_('Assigned locations for the user, with the primary ' + 'location highlighted in bold.'), sortable=False), DataTablesColumn(_("Last Submission"), prop_name='reporting_metadata.last_submissions.submission_date', From e55ec3d672989163d5fefce15b580c794b505d2d Mon Sep 17 00:00:00 2001 From: Zandre Engelbrecht Date: Wed, 19 Jun 2024 12:54:03 +0200 Subject: [PATCH 12/20] insert primary location at front of list --- corehq/apps/reports/standard/deployments.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/corehq/apps/reports/standard/deployments.py b/corehq/apps/reports/standard/deployments.py index cfa178504cd8..93b223dbdf15 100644 --- a/corehq/apps/reports/standard/deployments.py +++ b/corehq/apps/reports/standard/deployments.py @@ -514,8 +514,8 @@ def _get_formatted_assigned_location_names(self, user, user_loc_dict): for loc_id in assigned_location_ids: loc_name = user_loc_dict.get(loc_id) if loc_id == primary_location_id: - formatted_loc_names.append( - f'{loc_name}' + formatted_loc_names.insert( + 0, f'{loc_name}' ) else: formatted_loc_names.append(loc_name) From fd2f9be55e04ddf8dccf5993ec5819809899d0a9 Mon Sep 17 00:00:00 2001 From: Zandre Engelbrecht Date: Wed, 19 Jun 2024 12:55:55 +0200 Subject: [PATCH 13/20] add ability to shrink list of all locs again --- corehq/apps/reports/standard/deployments.py | 10 +++++++--- .../static/reports/js/bootstrap3/application_status.js | 4 ++-- .../static/reports/js/bootstrap5/application_status.js | 4 ++-- 3 files changed, 11 insertions(+), 7 deletions(-) diff --git a/corehq/apps/reports/standard/deployments.py b/corehq/apps/reports/standard/deployments.py index 93b223dbdf15..ae1f9384c665 100644 --- a/corehq/apps/reports/standard/deployments.py +++ b/corehq/apps/reports/standard/deployments.py @@ -522,14 +522,18 @@ def _get_formatted_assigned_location_names(self, user, user_loc_dict): formatted_str = ', '.join(formatted_loc_names[:4]) all_str = ', '.join(formatted_loc_names) - eplise_str = _('...See more') if len(formatted_loc_names) > 4 else '' + view_all_str = _('...See more') if len(formatted_loc_names) > 4 else '' + view_less_str = _('...See less') if len(formatted_loc_names) > 4 else '' out_str = ('''
    {} - {} + + {} + {} +
    - ''').format(formatted_str, eplise_str, all_str) + ''').format(formatted_str, all_str, view_all_str, view_less_str) return format_html(out_str) diff --git a/corehq/apps/reports/static/reports/js/bootstrap3/application_status.js b/corehq/apps/reports/static/reports/js/bootstrap3/application_status.js index 1a833dc2e359..5308e1c06b48 100644 --- a/corehq/apps/reports/static/reports/js/bootstrap3/application_status.js +++ b/corehq/apps/reports/static/reports/js/bootstrap3/application_status.js @@ -7,8 +7,8 @@ hqDefine("reports/js/bootstrap3/application_status", [ $(function () { $('#report-content').on('click', '.toggle-all-locations', function (e) { $(this).prevAll('.locations-list').toggle(); - $(this).toggle(); - $(this).nextAll('.all-locations-list').toggle(); + $(this).children('span').toggle(); + $(this).prevAll('.all-locations-list').toggle(); e.preventDefault(); }); }); diff --git a/corehq/apps/reports/static/reports/js/bootstrap5/application_status.js b/corehq/apps/reports/static/reports/js/bootstrap5/application_status.js index 8ca0dde47ee3..a0e08d2c8380 100644 --- a/corehq/apps/reports/static/reports/js/bootstrap5/application_status.js +++ b/corehq/apps/reports/static/reports/js/bootstrap5/application_status.js @@ -7,8 +7,8 @@ hqDefine("reports/js/bootstrap5/application_status", [ $(function () { $('#report-content').on('click', '.toggle-all-locations', function (e) { $(this).prevAll('.locations-list').toggle(); - $(this).toggle(); - $(this).nextAll('.all-locations-list').toggle(); + $(this).children('span').toggle(); + $(this).prevAll('.all-locations-list').toggle(); e.preventDefault(); }); }); From ee88a5567458320e630905c6d2f6a3d1048cbfc0 Mon Sep 17 00:00:00 2001 From: Zandre Engelbrecht Date: Thu, 20 Jun 2024 14:23:54 +0200 Subject: [PATCH 14/20] refactor building loc HTML --- corehq/apps/reports/standard/deployments.py | 28 ++++++++++----------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/corehq/apps/reports/standard/deployments.py b/corehq/apps/reports/standard/deployments.py index ae1f9384c665..d53a0d4c092a 100644 --- a/corehq/apps/reports/standard/deployments.py +++ b/corehq/apps/reports/standard/deployments.py @@ -521,20 +521,20 @@ def _get_formatted_assigned_location_names(self, user, user_loc_dict): formatted_loc_names.append(loc_name) formatted_str = ', '.join(formatted_loc_names[:4]) - all_str = ', '.join(formatted_loc_names) - view_all_str = _('...See more') if len(formatted_loc_names) > 4 else '' - view_less_str = _('...See less') if len(formatted_loc_names) > 4 else '' - out_str = (''' -
    - {} - - - {} - {} - -
    - ''').format(formatted_str, all_str, view_all_str, view_less_str) - return format_html(out_str) + html_nodes = [ + f'{formatted_str}', + ] + if len(formatted_loc_names) > 4: + all_str = ', '.join(formatted_loc_names) + view_controls_html_nodes = [ + f'{_("...See more")}', + f'{_("...See less")}', + ] + html_nodes += [ + f'', + f'{"".join(view_controls_html_nodes)}', + ] + return format_html(f'
    {"".join(html_nodes)}
    ') def _get_commcare_version(app_version_info): From d5b572806cbe8fc4e6c992741a24a1c99a21aac2 Mon Sep 17 00:00:00 2001 From: Zandre Engelbrecht Date: Thu, 20 Jun 2024 14:24:15 +0200 Subject: [PATCH 15/20] use HTML class to toggle visibility --- corehq/apps/reports/standard/deployments.py | 4 ++-- .../static/reports/js/bootstrap3/application_status.js | 2 +- .../static/reports/js/bootstrap5/application_status.js | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/corehq/apps/reports/standard/deployments.py b/corehq/apps/reports/standard/deployments.py index d53a0d4c092a..34b1c547008d 100644 --- a/corehq/apps/reports/standard/deployments.py +++ b/corehq/apps/reports/standard/deployments.py @@ -527,8 +527,8 @@ def _get_formatted_assigned_location_names(self, user, user_loc_dict): if len(formatted_loc_names) > 4: all_str = ', '.join(formatted_loc_names) view_controls_html_nodes = [ - f'{_("...See more")}', - f'{_("...See less")}', + f'{_("...See more")}', + f'', ] html_nodes += [ f'', diff --git a/corehq/apps/reports/static/reports/js/bootstrap3/application_status.js b/corehq/apps/reports/static/reports/js/bootstrap3/application_status.js index 5308e1c06b48..ab91e49c35f6 100644 --- a/corehq/apps/reports/static/reports/js/bootstrap3/application_status.js +++ b/corehq/apps/reports/static/reports/js/bootstrap3/application_status.js @@ -7,7 +7,7 @@ hqDefine("reports/js/bootstrap3/application_status", [ $(function () { $('#report-content').on('click', '.toggle-all-locations', function (e) { $(this).prevAll('.locations-list').toggle(); - $(this).children('span').toggle(); + $(this).children('.loc-view-control').toggle(); $(this).prevAll('.all-locations-list').toggle(); e.preventDefault(); }); diff --git a/corehq/apps/reports/static/reports/js/bootstrap5/application_status.js b/corehq/apps/reports/static/reports/js/bootstrap5/application_status.js index a0e08d2c8380..8465cbf00c0e 100644 --- a/corehq/apps/reports/static/reports/js/bootstrap5/application_status.js +++ b/corehq/apps/reports/static/reports/js/bootstrap5/application_status.js @@ -7,7 +7,7 @@ hqDefine("reports/js/bootstrap5/application_status", [ $(function () { $('#report-content').on('click', '.toggle-all-locations', function (e) { $(this).prevAll('.locations-list').toggle(); - $(this).children('span').toggle(); + $(this).children('.loc-view-control').toggle(); $(this).prevAll('.all-locations-list').toggle(); e.preventDefault(); }); From 581bfe1a7dd92eb5d6282dc48f37f4599eeb899b Mon Sep 17 00:00:00 2001 From: Zandre Engelbrecht Date: Thu, 20 Jun 2024 14:28:27 +0200 Subject: [PATCH 16/20] correctly fetch locations for web users --- corehq/apps/reports/standard/deployments.py | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/corehq/apps/reports/standard/deployments.py b/corehq/apps/reports/standard/deployments.py index 34b1c547008d..974be2c76972 100644 --- a/corehq/apps/reports/standard/deployments.py +++ b/corehq/apps/reports/standard/deployments.py @@ -47,6 +47,7 @@ ProjectReportParametersMixin, ) from corehq.apps.reports.util import format_datatables_data +from corehq.apps.users.models import CouchUser from corehq.apps.users.util import user_display_string from corehq.const import USER_DATE_FORMAT from corehq.util.quickcache import quickcache @@ -311,10 +312,11 @@ def include_location_data(self): ) ) - def user_locations_dict(self, users): + def user_locations_dict(self, user_docs): all_loc_ids = set() - for user in users: - for loc_id in user.get('assigned_location_ids'): + for user_doc in user_docs: + user = CouchUser.wrap_correctly(user_doc) + for loc_id in user.get_location_ids(self.domain): all_loc_ids.add(loc_id) return dict(SQLLocation.objects.filter( location_id__in=all_loc_ids, domain=self.domain @@ -498,8 +500,9 @@ def _fmt_timestamp(timestamp): result[0][1] = table return result - def get_location_column(self, user, user_loc_dict): - if not user.get('assigned_location_ids'): + def get_location_column(self, user_doc, user_loc_dict): + user = CouchUser.wrap_correctly(user_doc) + if not user.get_location_ids(self.domain): return '---' return self._get_formatted_assigned_location_names(user, user_loc_dict) @@ -508,8 +511,8 @@ def _get_formatted_assigned_location_names(self, user, user_loc_dict): Create an HTML formatted string of the given assigned location names. The primary location will be highlighted in bold. """ - assigned_location_ids = user.get('assigned_location_ids') - primary_location_id = user.get('location_id') + assigned_location_ids = user.get_location_ids(self.domain) + primary_location_id = user.get_location_id(self.domain) formatted_loc_names = [] for loc_id in assigned_location_ids: loc_name = user_loc_dict.get(loc_id) From ba975bf2ee0e9031d8d1293347297ef32ba8bf03 Mon Sep 17 00:00:00 2001 From: Zandre Engelbrecht Date: Mon, 1 Jul 2024 11:10:17 +0200 Subject: [PATCH 17/20] docstring + rename --- corehq/apps/reports/standard/deployments.py | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/corehq/apps/reports/standard/deployments.py b/corehq/apps/reports/standard/deployments.py index 974be2c76972..cf8a6af84104 100644 --- a/corehq/apps/reports/standard/deployments.py +++ b/corehq/apps/reports/standard/deployments.py @@ -312,7 +312,14 @@ def include_location_data(self): ) ) - def user_locations_dict(self, user_docs): + def locations_names_dict(self, user_docs): + """ + Returns a dict of all assigned location names for given `user_docs`. + The dict has the following structure: + { + 'loc_id': 'loc_name' + } + """ all_loc_ids = set() for user_doc in user_docs: user = CouchUser.wrap_correctly(user_doc) @@ -331,7 +338,7 @@ def process_rows(self, users, fmt_for_export=False): grouped_ancestor_locs = self.get_bulk_ancestors(location_ids) self.required_loc_columns = self.get_location_columns(grouped_ancestor_locs) - user_loc_dict = self.user_locations_dict(users) + loc_names_dict = self.locations_names_dict(users) for user in users: last_build = last_seen = last_sub = last_sync = last_sync_date = app_name = commcare_version = None last_build_profile_name = device = device_app_meta = num_unsent_forms = None @@ -389,7 +396,7 @@ def process_rows(self, users, fmt_for_export=False): user_display_string(user.get('username', ''), user.get('first_name', ''), user.get('last_name', '')), - self.get_location_column(user, user_loc_dict), + self.get_location_column(user, loc_names_dict), _fmt_date(last_seen, fmt_for_export), _fmt_date(last_sync_date, fmt_for_export), app_name or "---", build_version, commcare_version or '---', num_unsent_forms if num_unsent_forms is not None else "---", From b045a3dc300e3d96e2d863eaecd37f4d544da471 Mon Sep 17 00:00:00 2001 From: Zandre Engelbrecht Date: Mon, 1 Jul 2024 11:10:42 +0200 Subject: [PATCH 18/20] update collapse string text --- corehq/apps/reports/standard/deployments.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/corehq/apps/reports/standard/deployments.py b/corehq/apps/reports/standard/deployments.py index cf8a6af84104..90f4fba9b480 100644 --- a/corehq/apps/reports/standard/deployments.py +++ b/corehq/apps/reports/standard/deployments.py @@ -538,7 +538,7 @@ def _get_formatted_assigned_location_names(self, user, user_loc_dict): all_str = ', '.join(formatted_loc_names) view_controls_html_nodes = [ f'{_("...See more")}', - f'', + f'', ] html_nodes += [ f'', From d6a20e8ee55103e1c5e211c6ae3034d5ecc12a42 Mon Sep 17 00:00:00 2001 From: Zandre Engelbrecht Date: Tue, 2 Jul 2024 09:43:04 +0200 Subject: [PATCH 19/20] move func + small refactor --- corehq/apps/reports/standard/deployments.py | 42 ++++++++++----------- 1 file changed, 21 insertions(+), 21 deletions(-) diff --git a/corehq/apps/reports/standard/deployments.py b/corehq/apps/reports/standard/deployments.py index 90f4fba9b480..6e89589c5656 100644 --- a/corehq/apps/reports/standard/deployments.py +++ b/corehq/apps/reports/standard/deployments.py @@ -312,23 +312,6 @@ def include_location_data(self): ) ) - def locations_names_dict(self, user_docs): - """ - Returns a dict of all assigned location names for given `user_docs`. - The dict has the following structure: - { - 'loc_id': 'loc_name' - } - """ - all_loc_ids = set() - for user_doc in user_docs: - user = CouchUser.wrap_correctly(user_doc) - for loc_id in user.get_location_ids(self.domain): - all_loc_ids.add(loc_id) - return dict(SQLLocation.objects.filter( - location_id__in=all_loc_ids, domain=self.domain - ).values_list('location_id', 'name')) - def process_rows(self, users, fmt_for_export=False): rows = [] users = list(users) @@ -338,7 +321,7 @@ def process_rows(self, users, fmt_for_export=False): grouped_ancestor_locs = self.get_bulk_ancestors(location_ids) self.required_loc_columns = self.get_location_columns(grouped_ancestor_locs) - loc_names_dict = self.locations_names_dict(users) + loc_names_dict = self._locations_names_dict(users) for user in users: last_build = last_seen = last_sub = last_sync = last_sync_date = app_name = commcare_version = None last_build_profile_name = device = device_app_meta = num_unsent_forms = None @@ -396,7 +379,7 @@ def process_rows(self, users, fmt_for_export=False): user_display_string(user.get('username', ''), user.get('first_name', ''), user.get('last_name', '')), - self.get_location_column(user, loc_names_dict), + self._get_location_column(user, loc_names_dict), _fmt_date(last_seen, fmt_for_export), _fmt_date(last_sync_date, fmt_for_export), app_name or "---", build_version, commcare_version or '---', num_unsent_forms if num_unsent_forms is not None else "---", @@ -412,6 +395,23 @@ def process_rows(self, users, fmt_for_export=False): rows.append(row_data) return rows + def _locations_names_dict(self, user_docs_es): + """ + Returns a dict of all assigned location names for given `user_docs`. + The dict has the following structure: + { + 'loc_id': 'loc_name' + } + """ + all_loc_ids = set() + for user_doc in user_docs_es: + user = CouchUser.wrap_correctly(user_doc) + for loc_id in user.get_location_ids(self.domain): + all_loc_ids.add(loc_id) + return dict(SQLLocation.objects.filter( + location_id__in=all_loc_ids, domain=self.domain + ).values_list('location_id', 'name')) + def process_facts(self, app_status_facts, fmt_for_export=False): rows = [] for fact in app_status_facts: @@ -507,8 +507,8 @@ def _fmt_timestamp(timestamp): result[0][1] = table return result - def get_location_column(self, user_doc, user_loc_dict): - user = CouchUser.wrap_correctly(user_doc) + def _get_location_column(self, user_doc_es, user_loc_dict): + user = CouchUser.wrap_correctly(user_doc_es) if not user.get_location_ids(self.domain): return '---' return self._get_formatted_assigned_location_names(user, user_loc_dict) From e5c23424c947b4a6e128d6eeca5c9d628c884ffc Mon Sep 17 00:00:00 2001 From: Zandre Engelbrecht Date: Tue, 2 Jul 2024 18:13:58 +0200 Subject: [PATCH 20/20] rename refactor --- corehq/apps/reports/standard/deployments.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/corehq/apps/reports/standard/deployments.py b/corehq/apps/reports/standard/deployments.py index 6e89589c5656..fe5a755e24c2 100644 --- a/corehq/apps/reports/standard/deployments.py +++ b/corehq/apps/reports/standard/deployments.py @@ -395,7 +395,7 @@ def process_rows(self, users, fmt_for_export=False): rows.append(row_data) return rows - def _locations_names_dict(self, user_docs_es): + def _locations_names_dict(self, user_es_docs): """ Returns a dict of all assigned location names for given `user_docs`. The dict has the following structure: @@ -404,8 +404,8 @@ def _locations_names_dict(self, user_docs_es): } """ all_loc_ids = set() - for user_doc in user_docs_es: - user = CouchUser.wrap_correctly(user_doc) + for user_es_doc in user_es_docs: + user = CouchUser.wrap_correctly(user_es_doc) for loc_id in user.get_location_ids(self.domain): all_loc_ids.add(loc_id) return dict(SQLLocation.objects.filter( @@ -507,8 +507,8 @@ def _fmt_timestamp(timestamp): result[0][1] = table return result - def _get_location_column(self, user_doc_es, user_loc_dict): - user = CouchUser.wrap_correctly(user_doc_es) + def _get_location_column(self, user_es_doc, user_loc_dict): + user = CouchUser.wrap_correctly(user_es_doc) if not user.get_location_ids(self.domain): return '---' return self._get_formatted_assigned_location_names(user, user_loc_dict)