The Bugs front page =================== The contents on the Bugs front page is driven by MaloneView. It doesn't use its context for anything, so we don't have to supply one when creating it. >>> from lp.systemhomes import MaloneApplication >>> from lp.services.webapp.servers import LaunchpadTestRequest >>> from lp.bugs.browser.bug import MaloneView >>> bugs_view = MaloneView(MaloneApplication(), LaunchpadTestRequest()) >>> bugs_view.initialize() Recently Fixed Bugs ------------------- There is a list of the most recently fixed bugs on the page. This list is generated by getMostRecentlyFixedBugs(), which returns the ten most recently fixed bugs, across all contexts. Only one bug is fixed in Launchpad currently. >>> from lp.bugs.interfaces.bugtask import BugTaskStatus >>> from lp.bugs.model.bugtask import BugTask >>> [bugtask.bug.id ... for bugtask in BugTask.selectBy(_status=BugTaskStatus.FIXRELEASED)] [8] >>> for bug in bugs_view.getMostRecentlyFixedBugs(): ... print "%s: %s" % (bug.id, bug.title) 8: Printing doesn't work Let's reopen it and close it again, to ensure that the date closed isn't in the future. >>> login('test@canonical.com') >>> from lp.bugs.interfaces.bug import IBugSet >>> bug_eight = getUtility(IBugSet).get(8) >>> len(bug_eight.bugtasks) 1 >>> bug_eight.bugtasks[0].transitionToStatus( ... BugTaskStatus.CONFIRMED, bug_eight.bugtasks[0].distribution.owner) >>> def fix_bug(bug_id, bugtask_index=0): ... bugtask = getUtility(IBugSet).get(bug_id).bugtasks[bugtask_index] ... bugtask.transitionToStatus( ... BugTaskStatus.FIXRELEASED, getUtility(ILaunchBag).user) >>> fix_bug(8) If we fix a few other bugs, these will turn up first in the list. It doesn't matter which bugtask that gets fixed. >>> fix_bug(1) >>> fix_bug(2) >>> fix_bug(4) >>> for bug in bugs_view.getMostRecentlyFixedBugs(): ... print "%s: %s" % (bug.id, bug.title) 4: Reflow problems with complex page layouts 2: Blackhole Trash folder 1: Firefox does not support SVG 8: Printing doesn't work Even though a bug has several fixed bugtasks, it will only show up once in the list. So if we fix another one of bug one's bugtasks, it will simply appear on the top of the list. >>> fix_bug(1, bugtask_index=1) >>> for bug in bugs_view.getMostRecentlyFixedBugs(): ... print "%s: %s" % (bug.id, bug.title) 1: Firefox does not support SVG 4: Reflow problems with complex page layouts 2: Blackhole Trash folder 8: Printing doesn't work Only the bugs that the user has permission to view are shown in the list, so if we mark bug #4 as private, No Privileges won't see it, since he's not subscribed to it. >>> bug_4 = getUtility(IBugSet).get(4) >>> bug_4.setPrivate(True, getUtility(ILaunchBag).user) True >>> login('no-priv@canonical.com') >>> bugs_view = MaloneView(MaloneApplication(), LaunchpadTestRequest()) >>> bugs_view.initialize() >>> for bug in bugs_view.getMostRecentlyFixedBugs(): ... print "%s: %s" % (bug.id, bug.title) 1: Firefox does not support SVG 2: Blackhole Trash folder 8: Printing doesn't work If Person David gets subscribed to bug #4, he can see it in the list. >>> from lp.registry.interfaces.person import IPersonSet >>> person_set = getUtility(IPersonSet) >>> login('foo.bar@canonical.com') >>> bug_4.subscribe( ... person_set.getByEmail('david@canonical.com'), ... person_set.getByEmail('foo.bar@canonical.com')) >>> login('david@canonical.com') >>> bugs_view = MaloneView(MaloneApplication(), LaunchpadTestRequest()) >>> bugs_view.initialize() >>> for bug in bugs_view.getMostRecentlyFixedBugs(): ... print "%s: %s" % (bug.id, bug.title) 1: Firefox does not support SVG 4: Reflow problems with complex page layouts 2: Blackhole Trash folder 8: Printing doesn't work Only five bugs are returned by default: >>> from lp.bugs.interfaces.bug import CreateBugParams >>> from lp.registry.interfaces.product import IProductSet >>> firefox = getUtility(IProductSet).getByName('firefox') >>> for index in range(20): ... bug = firefox.createBug(CreateBugParams( ... getUtility(ILaunchBag).user, 'Test Bug #%s' % index, ... comment='Test bug #%s.' % index)) ... bug.bugtasks[0].transitionToStatus( ... BugTaskStatus.FIXRELEASED, getUtility(ILaunchBag).user) >>> len(bugs_view.getMostRecentlyFixedBugs()) 5