blob: 2bf2c90f7e66e3e787ee4b574e81e3eb9f291491 [file] [log] [blame]
Copybara854996b2021-09-07 19:36:02 +00001# Copyright 2016 The Chromium Authors. All rights reserved.
2# Use of this source code is governed by a BSD-style
3# license that can be found in the LICENSE file or at
4# https://developers.google.com/open-source/licenses/bsd
5
6"""Set of helpers for constructing spam-related pages.
7"""
8from __future__ import print_function
9from __future__ import division
10from __future__ import absolute_import
11from framework import template_helpers
12import ezt
13
14from datetime import datetime
15
16def DecorateIssueClassifierQueue(
17 cnxn, issue_service, spam_service, user_service, moderation_items):
18 issue_ids = [item.issue_id for item in moderation_items]
19 issues = issue_service.GetIssues(cnxn, issue_ids)
20 issue_map = {}
21 for issue in issues:
22 issue_map[issue.issue_id] = issue
23
24 flag_counts = spam_service.LookupIssueFlagCounts(cnxn, issue_ids)
25
26 reporter_ids = [issue.reporter_id for issue in issues]
27 reporters = user_service.GetUsersByIDs(cnxn, reporter_ids)
28 comments = issue_service.GetCommentsForIssues(cnxn, issue_ids)
29
30 items = []
31 for item in moderation_items:
32 issue=issue_map[item.issue_id]
33 first_comment = comments.get(item.issue_id, ["[Empty]"])[0]
34
35 items.append(template_helpers.EZTItem(
36 issue=issue,
37 summary=template_helpers.FitUnsafeText(issue.summary, 80),
38 comment_text=template_helpers.FitUnsafeText(first_comment.content, 80),
39 reporter=reporters[issue.reporter_id],
40 flag_count=flag_counts.get(issue.issue_id, 0),
41 is_spam=ezt.boolean(item.is_spam),
42 verdict_time=item.verdict_time,
43 classifier_confidence=item.classifier_confidence,
44 reason=item.reason,
45 ))
46
47 return items