1
# Copyright 2009 Canonical Ltd. This software is licensed under the
2
# GNU Affero General Public License version 3 (see the file LICENSE).
4
"""Views for linking bugs and questions."""
10
from lazr.lifecycle.event import ObjectModifiedEvent
11
from lazr.lifecycle.snapshot import Snapshot
12
from zope.event import notify
13
from zope.interface import providedBy
15
from canonical.launchpad import _
16
from canonical.launchpad.webapp.publisher import canonical_url
17
from lp.app.browser.launchpadform import (
21
from lp.bugs.interfaces.bug import (
27
class QuestionMakeBugView(LaunchpadFormView):
28
"""Browser class for adding a bug from a question."""
32
field_names = ['title', 'description']
35
"""Initialize the view when a Bug may be reported for the Question."""
36
question = self.context
38
# we can't make a bug when we have linked bugs
39
self.request.response.addErrorNotification(
40
_('You cannot create a bug report from a question'
41
'that already has bugs linked to it.'))
42
self.request.response.redirect(canonical_url(question))
44
LaunchpadFormView.initialize(self)
48
return 'Create bug report based on question #%s' % self.context.id
52
return 'Create a bug based on a question'
55
def initial_values(self):
56
"""Return the initial form values."""
57
question = self.context
59
'description': question.description}
61
@action(_('Create Bug Report'), name='create')
62
def create_action(self, action, data):
63
"""Create a Bug from a Question."""
64
question = self.context
66
unmodifed_question = Snapshot(
67
question, providing=providedBy(question))
68
params = CreateBugParams(
69
owner=self.user, title=data['title'], comment=data['description'])
70
bug = question.target.createBug(params)
72
bug.subscribe(question.owner, self.user)
73
bug_added_event = ObjectModifiedEvent(
74
question, unmodifed_question, ['bugs'])
75
notify(bug_added_event)
76
self.request.response.addNotification(
77
_('Thank you! Bug #$bugid created.', mapping={'bugid': bug.id}))
78
self.next_url = canonical_url(bug)