From 1ab087a7899de2b0e5b14afa73e8a2685338003f Mon Sep 17 00:00:00 2001 From: Jing Cheng Date: Tue, 30 Jan 2024 20:42:08 +0800 Subject: [PATCH] Update _get_raw_user_link to send more parameters --- corehq/apps/reports/standard/monitoring.py | 30 ++++++++++++++++++---- 1 file changed, 25 insertions(+), 5 deletions(-) diff --git a/corehq/apps/reports/standard/monitoring.py b/corehq/apps/reports/standard/monitoring.py index fc39ca0b15f1..28538aef32ed 100644 --- a/corehq/apps/reports/standard/monitoring.py +++ b/corehq/apps/reports/standard/monitoring.py @@ -965,8 +965,12 @@ def get_row(self, user=None): def get_raw_user_link(self, user): from corehq.apps.reports.standard.inspect import SubmitHistory + sub_time_param = { + CompletionOrSubmissionTimeFilter.slug: + CompletionOrSubmissionTimeFilter.get_value(self.request, self.domain) or '' + } return _get_raw_user_link(user, SubmitHistory.get_url(domain=self.domain), - filter_class=EMWF) + filter_class=EMWF, additional_params=sub_time_param) @property def template_context(self): @@ -1799,16 +1803,32 @@ def rows(self): return rows -def _get_raw_user_link(user, url, filter_class): +def _get_raw_user_link(user, url, filter_class, additional_params=None): """ - filter_class is expected to be either ExpandedMobileWorkerFilter or a - subclass of it, such as the CaseListFilter + Generates an HTML anchor tag () for a user link with additional query parameters. + + Parameters: + - user (SimplifiedUserInfo object): The user for whom the link is being generated. + - url (str): The base URL to which filter parameters and any additional parameters will be appended. + - filter_class (class): A filter class expected to be either ExpandedMobileWorkerFilter or a subclass of it, + such as CaseListFilter. + - additional_params (dict, optional): An optional dictionary of additional query parameters to be appended to + the URL. Each key-value pair in the dictionary represents a parameter name and its value. + + Returns: + - str: A string containing an HTML anchor tag () with the constructed URL and the user's display name. """ user_link_template = '{username}' + additional_param_string = '' + if additional_params: + if isinstance(additional_params, dict): + additional_param_string = '&' + urlencode(additional_params) + else: + raise ValueError("additional_params must be a dictionary") user_link = format_html( user_link_template, link=url, - params=urlencode(filter_class.for_user(user.user_id)), + params=urlencode(filter_class.for_user(user.user_id)) + additional_param_string, username=user.username_in_report, ) return user_link