def HandleRequest(self, mr): changed_ranks = self._GetNewRankings(mr) if changed_ranks: relations_to_change = dict( (issue_id, rank) for issue_id, rank in changed_ranks) self.services.features.UpdateHotlistItemsFields( mr.cnxn, mr.hotlist_id, new_ranks=relations_to_change) hotlist_items = self.services.features.GetHotlist( mr.cnxn, mr.hotlist_id).items # Note: Cannot use mr.hotlist because hotlist_issues # of mr.hotlist is not updated sorting.InvalidateArtValuesKeys( mr.cnxn, [hotlist_item.issue_id for hotlist_item in hotlist_items]) (table_data, _) = hotlist_helpers.CreateHotlistTableData( mr, hotlist_items, self.profiler, self.services) json_table_data = [{ 'cells': [{ 'type': cell.type, 'values': [{ 'item': value.item, 'isDerived': value.is_derived, } for value in cell.values], 'colIndex': cell.col_index, 'align': cell.align, 'noWrap': cell.NOWRAP, 'nonColLabels': [{ 'value': label.value, 'isDerived': label.is_derived, } for label in cell.non_column_labels], } for cell in table_row.cells], 'issueRef': table_row.issue_ref, 'idx': table_row.idx, 'projectName': table_row.project_name, 'projectURL': table_row.project_url, 'localID': table_row.local_id, 'issueID': table_row.issue_id, 'isStarred': table_row.starred, 'issueCleanURL': table_row.issue_clean_url, 'issueContextURL': table_row.issue_ctx_url, } for table_row in table_data] for row, json_row in zip([table_row for table_row in table_data], json_table_data): if (row.group and row.group.cells): json_row.update({ 'group': { 'rowsInGroup': row.group.rows_in_group, 'cells': [ { 'groupName': cell.group_name, 'values': [ { # TODO(jojwang): check if this gives error when there # is no value.item 'item': value.item if value.item else 'None', } for value in cell.values ], } for cell in row.group.cells ], } }) else: json_row['group'] = 'no' return {'table_data': json_table_data} else: return {'table_data': ''}
def ProcessFormData(self, mr, post_data): if post_data.get('deletestate') == 'true': hotlist_helpers.RemoveHotlist(mr.cnxn, mr.hotlist_id, self.services) return framework_helpers.FormatAbsoluteURL(mr, '/u/%s/hotlists' % mr.auth.email, saved=1, ts=int(time.time()), include_project=False) hotlist_view_url = hotlist_helpers.GetURLOfHotlist( mr.cnxn, mr.hotlist, self.services.user) current_col_spec = post_data.get('current_col_spec') default_url = framework_helpers.FormatAbsoluteURL( mr, hotlist_view_url, include_project=False, colspec=current_col_spec) sorting.InvalidateArtValuesKeys( mr.cnxn, [hotlist_item.issue_id for hotlist_item in mr.hotlist.items]) if post_data.get('remove') == 'true': project_and_local_ids = post_data.get('remove_local_ids') else: project_and_local_ids = post_data.get('add_local_ids') if not project_and_local_ids: return default_url selected_iids = [] if project_and_local_ids: pattern = re.compile(features_constants.ISSUE_INPUT_REGEX) if pattern.match(project_and_local_ids): issue_refs_tuples = [ (pair.split(':')[0].strip(), int(pair.split(':')[1].strip())) for pair in project_and_local_ids.split(',') if pair.strip() ] project_names = { project_name for (project_name, _) in issue_refs_tuples } projects_dict = self.services.project.GetProjectsByName( mr.cnxn, project_names) selected_iids, _misses = self.services.issue.ResolveIssueRefs( mr.cnxn, projects_dict, mr.project_name, issue_refs_tuples) if (not selected_iids ) or len(issue_refs_tuples) > len(selected_iids): mr.errors.issues = _MSG_ISSUES_NOT_FOUND # TODO(jojwang): give issues that were not found. else: mr.errors.issues = _MSG_INVALID_ISSUES_INPUT try: with work_env.WorkEnv(mr, self.services) as we: selected_issues = we.GetIssuesDict(selected_iids) except exceptions.NoSuchIssueException: mr.errors.issues = _MSG_ISSUES_NOT_FOUND if len(selected_issues) < len(selected_iids): mr.errors.issues = _MSG_ISSUES_NOT_VIEWABLE # TODO(jojwang): fix: when there are errors, hidden column come back on # the .do page but go away once the errors are fixed and the form # is submitted again if mr.errors.AnyErrors(): self.PleaseCorrect(mr, add_local_ids=project_and_local_ids, add_issues_selected=ezt.boolean(True), col_spec=current_col_spec) else: with work_env.WorkEnv(mr, self.services) as we: if post_data.get('remove') == 'true': we.RemoveIssuesFromHotlists([mr.hotlist_id], selected_iids) else: we.AddIssuesToHotlists([mr.hotlist_id], selected_iids, '') return framework_helpers.FormatAbsoluteURL( mr, hotlist_view_url, saved=1, ts=int(time.time()), include_project=False, colspec=current_col_spec)
def GetSortedHotlistIssues(mr, hotlist_issues, issues_list, harmonized_config, profiler, services): with profiler.Phase('Checking issue permissions and getting ranks'): allowed_issues = FilterIssues(mr, issues_list, services) allowed_iids = [issue.issue_id for issue in allowed_issues] # The values for issues in a hotlist are specific to the hotlist # (rank, adder, added) without invalidating the keys, an issue will retain # the rank value it has in one hotlist when navigating to another hotlist. sorting.InvalidateArtValuesKeys( mr.cnxn, [issue.issue_id for issue in allowed_issues]) sorted_ranks = sorted([ hotlist_issue.rank for hotlist_issue in hotlist_issues if hotlist_issue.issue_id in allowed_iids ]) friendly_ranks = { rank: friendly for friendly, rank in enumerate(sorted_ranks, 1) } issue_adders = framework_views.MakeAllUserViews( mr.cnxn, services.user, [hotlist_issue.adder_id for hotlist_issue in hotlist_issues]) hotlist_issues_context = { hotlist_issue.issue_id: { 'issue_rank': friendly_ranks[hotlist_issue.rank], 'adder_id': hotlist_issue.adder_id, 'date_added': timestr.FormatAbsoluteDate(hotlist_issue.date_added), 'note': hotlist_issue.note } for hotlist_issue in hotlist_issues if hotlist_issue.issue_id in allowed_iids } with profiler.Phase('Making user views'): issues_users_by_id = framework_views.MakeAllUserViews( mr.cnxn, services.user, tracker_bizobj.UsersInvolvedInIssues(allowed_issues or [])) issues_users_by_id.update(issue_adders) with profiler.Phase('Sorting issues'): sortable_fields = tracker_helpers.SORTABLE_FIELDS.copy() sortable_fields.update({ 'rank': lambda issue: hotlist_issues_context[issue.issue_id]['issue_rank'], 'adder': lambda issue: hotlist_issues_context[issue.issue_id]['adder_id'], 'added': lambda issue: hotlist_issues_context[issue.issue_id]['date_added'], 'note': lambda issue: hotlist_issues_context[issue.issue_id]['note'] }) sortable_postproc = tracker_helpers.SORTABLE_FIELDS_POSTPROCESSORS.copy( ) sortable_postproc.update({ 'adder': lambda user_view: user_view.email, }) if not mr.sort_spec: mr.sort_spec = 'rank' sorted_issues = sorting.SortArtifacts(mr, allowed_issues, harmonized_config, sortable_fields, sortable_postproc, users_by_id=issues_users_by_id, tie_breakers=['rank', 'id']) return sorted_issues, hotlist_issues_context, issues_users_by_id