1
# Copyright 2006-2009 Canonical Ltd. All rights reserved.
3
"""Views for linking bugs and questions."""
9
from zope.event import notify
11
from canonical.launchpad import _
12
from zope.interface import providedBy
14
from lazr.lifecycle.event import ObjectModifiedEvent
15
from lazr.lifecycle.snapshot import Snapshot
17
from canonical.launchpad.interfaces.bug import CreateBugParams, IBug
18
from canonical.launchpad.webapp.publisher import canonical_url
19
from canonical.launchpad.webapp.launchpadform import action, LaunchpadFormView
21
class QuestionMakeBugView(LaunchpadFormView):
22
"""Browser class for adding a bug from a question."""
26
field_names = ['title', 'description']
29
"""Initialize the view when a Bug may be reported for the Question."""
30
question = self.context
32
# we can't make a bug when we have linked bugs
33
self.request.response.addErrorNotification(
34
_('You cannot create a bug report from a question'
35
'that already has bugs linked to it.'))
36
self.request.response.redirect(canonical_url(question))
38
LaunchpadFormView.initialize(self)
41
def initial_values(self):
42
"""Return the initial form values."""
43
question = self.context
45
'description': question.description}
47
@action(_('Create Bug Report'), name='create')
48
def create_action(self, action, data):
49
"""Create a Bug from a Question."""
50
question = self.context
52
unmodifed_question = Snapshot(
53
question, providing=providedBy(question))
54
params = CreateBugParams(
55
owner=self.user, title=data['title'], comment=data['description'])
56
bug = question.target.createBug(params)
58
bug.subscribe(question.owner, self.user)
59
bug_added_event = ObjectModifiedEvent(
60
question, unmodifed_question, ['bugs'])
61
notify(bug_added_event)
62
self.request.response.addNotification(
63
_('Thank you! Bug #$bugid created.', mapping={'bugid': bug.id}))
64
self.next_url = canonical_url(bug)