1
Recently Touched Bugs for a IBugTarget
2
======================================
4
Every IBugTarget has a portlet for showing the most recently touched
5
bugs (i.e bugs that have been recently modified/created).
7
>>> from zope.component import getMultiAdapter
8
>>> from canonical.launchpad.webapp.servers import LaunchpadTestRequest
9
>>> portlet_view = getMultiAdapter(
10
... (bugtarget, LaunchpadTestRequest()),
11
... name='+portlet-recently-touched-bugs')
12
>>> portlet_view.initialize()
15
>>> from datetime import datetime, timedelta
16
>>> now = datetime.now(pytz.timezone('UTC'))
17
>>> def set_date_updated(bug, minutes_in_future):
18
... bug.date_last_updated = now + timedelta(minutes=minutes_in_future)
20
If we have three bugs with a recent date_last_updated set, they will
21
appear in the top of the list.
23
>>> login('test@canonical.com')
24
>>> sample_person = getUtility(ILaunchBag).user
25
>>> bug_a = filebug(bugtarget, 'Bug A')
26
>>> set_date_updated(bug_a, 1)
27
>>> bug_b = filebug(bugtarget, 'Bug B')
28
>>> set_date_updated(bug_b, 2)
29
>>> bug_c = filebug(bugtarget, 'Bug C')
30
>>> set_date_updated(bug_c, 3)
32
>>> for bugtask in portlet_view.getMostRecentlyUpdatedBugTasks()[:3]:
33
... print bugtask.bug.title
38
If one of the bug's date_last_updated gets updated to a newer value, it
39
will be first in the list.
41
>>> set_date_updated(bug_b, 4)
42
>>> for bugtask in portlet_view.getMostRecentlyUpdatedBugTasks()[:3]:
43
... print bugtask.bug.title
51
Only bugs that the user is allowed to see will be present in the list.
53
>>> bug_c.setPrivate(True, getUtility(ILaunchBag).user)
56
>>> login('no-priv@canonical.com')
57
>>> portlet_view = getMultiAdapter(
58
... (bugtarget, LaunchpadTestRequest()),
59
... name='+portlet-recently-touched-bugs')
60
>>> portlet_view.initialize()
61
>>> for bugtask in portlet_view.getMostRecentlyUpdatedBugTasks()[:2]:
62
... print bugtask.bug.title
66
>>> login('test@canonical.com')
67
>>> portlet_view = getMultiAdapter(
68
... (bugtarget, LaunchpadTestRequest()),
69
... name='+portlet-recently-touched-bugs')
70
>>> portlet_view.initialize()
71
>>> for bugtask in portlet_view.getMostRecentlyUpdatedBugTasks()[:3]:
72
... print bugtask.bug.title
80
Bugs that are duplicates of other bugs will be omitted from the list as
83
>>> bug_b.markAsDuplicate(bug_c)
85
>>> for bugtask in portlet_view.getMostRecentlyUpdatedBugTasks()[:2]:
86
... print bugtask.bug.title
93
By default only five bugs will be returned, but it's possible to specify
96
>>> for index in range(6):
97
... bug = filebug(bugtarget, 'Bug %s' % index)
98
>>> len(portlet_view.getMostRecentlyUpdatedBugTasks())
101
>>> len(portlet_view.getMostRecentlyUpdatedBugTasks(limit=2))