12919.3.2
by Curtis Hovey
Added IQuestionJob and IQuestionJobSource cribbed from the person jobs. |
1 |
# Copyright 2011 Canonical Ltd. This software is licensed under the
|
2 |
# GNU Affero General Public License version 3 (see the file LICENSE).
|
|
3 |
||
4 |
"""Interface for the Jobs system for questions."""
|
|
5 |
||
6 |
__metaclass__ = type |
|
7 |
__all__ = [ |
|
8 |
'IQuestionJob', |
|
12919.3.5
by Curtis Hovey
Added the base QuestionJob class. |
9 |
'IQuestionEmailJob', |
10 |
'IQuestionEmailJobSource', |
|
12919.3.2
by Curtis Hovey
Added IQuestionJob and IQuestionJobSource cribbed from the person jobs. |
11 |
]
|
12 |
||
14100.2.4
by Gavin Panella
QuestionJob does not implement IQuestionJob, because IQuestionJob should not inherit from IRunnableJob. |
13 |
from zope.interface import ( |
14 |
Attribute, |
|
15 |
Interface, |
|
16 |
)
|
|
12919.3.2
by Curtis Hovey
Added IQuestionJob and IQuestionJobSource cribbed from the person jobs. |
17 |
from zope.schema import ( |
12919.3.6
by Curtis Hovey
Added the start of QuestionEmailJob. |
18 |
Choice, |
12919.3.2
by Curtis Hovey
Added IQuestionJob and IQuestionJobSource cribbed from the person jobs. |
19 |
Field, |
20 |
Int, |
|
21 |
Object, |
|
22 |
)
|
|
23 |
||
14600.1.12
by Curtis Hovey
Move i18n to lp. |
24 |
from lp import _ |
12919.3.6
by Curtis Hovey
Added the start of QuestionEmailJob. |
25 |
from lp.answers.enums import QuestionJobType |
12919.3.2
by Curtis Hovey
Added IQuestionJob and IQuestionJobSource cribbed from the person jobs. |
26 |
from lp.services.job.interfaces.job import ( |
27 |
IJob, |
|
28 |
IJobSource, |
|
29 |
IRunnableJob, |
|
30 |
)
|
|
31 |
||
32 |
||
14100.2.4
by Gavin Panella
QuestionJob does not implement IQuestionJob, because IQuestionJob should not inherit from IRunnableJob. |
33 |
class IQuestionJob(Interface): |
12919.3.2
by Curtis Hovey
Added IQuestionJob and IQuestionJobSource cribbed from the person jobs. |
34 |
"""A Job related to a question."""
|
35 |
||
36 |
id = Int( |
|
37 |
title=_('DB ID'), required=True, readonly=True, |
|
38 |
description=_("The tracking number for this job.")) |
|
39 |
||
40 |
job = Object( |
|
41 |
title=_('The common Job attributes'), |
|
42 |
schema=IJob, required=True) |
|
43 |
||
12919.3.6
by Curtis Hovey
Added the start of QuestionEmailJob. |
44 |
job_type = Choice( |
45 |
title=_('Job type'), vocabulary=QuestionJobType, |
|
46 |
required=True, readonly=True) |
|
47 |
||
12919.3.2
by Curtis Hovey
Added IQuestionJob and IQuestionJobSource cribbed from the person jobs. |
48 |
question = Field( |
49 |
title=_("The question related to this job."), |
|
50 |
description=_("An IQuestion."), required=True, readonly=True) |
|
51 |
||
52 |
metadata = Attribute('A dict of data about the job.') |
|
53 |
||
54 |
||
14100.2.4
by Gavin Panella
QuestionJob does not implement IQuestionJob, because IQuestionJob should not inherit from IRunnableJob. |
55 |
class IQuestionEmailJob(IQuestionJob, IRunnableJob): |
12919.3.5
by Curtis Hovey
Added the base QuestionJob class. |
56 |
|
57 |
user = Attribute('The `IPerson` who triggered the email.') |
|
58 |
||
12919.3.19
by Curtis Hovey
Fix the name of the attribute. |
59 |
subject = Attribute('The subject of the email.') |
12919.3.17
by Curtis Hovey
Added subject property. |
60 |
|
61 |
body = Attribute( |
|
12928.2.9
by Curtis Hovey
Fixed grammar and spelling. |
62 |
'The body of the email that is common to all recipients.') |
12919.3.5
by Curtis Hovey
Added the base QuestionJob class. |
63 |
|
64 |
headers = Attribute( |
|
12928.2.9
by Curtis Hovey
Fixed grammar and spelling. |
65 |
'The headers of the email that are common to all recipients.') |
12919.3.5
by Curtis Hovey
Added the base QuestionJob class. |
66 |
|
12928.2.3
by Curtis Hovey
Added from_address. |
67 |
from_address = Attribute( |
68 |
'The formatted email address for the user and question.') |
|
69 |
||
12928.2.4
by Curtis Hovey
Added the recipients property. |
70 |
recipients = Attribute('The recipient of the email.') |
71 |
||
12928.2.6
by Curtis Hovey
Copied QuestionNotification tests to QuestionJob tests. |
72 |
def buildBody(rationale): |
73 |
"""Return the formatted email body with the rationale included."""
|
|
74 |
||
12919.3.5
by Curtis Hovey
Added the base QuestionJob class. |
75 |
|
76 |
class IQuestionEmailJobSource(IJobSource): |
|
12919.3.2
by Curtis Hovey
Added IQuestionJob and IQuestionJobSource cribbed from the person jobs. |
77 |
"""An interface for acquiring IQuestionJob."""
|
78 |
||
12928.2.12
by Curtis Hovey
Added QuestionRecipientSet so that processes can state who should receive emails. |
79 |
def create(question, user, recipient_set, subject, body, headers): |
12919.3.7
by Curtis Hovey
Renamed params. |
80 |
"""Create a new IQuestionJob.
|
81 |
||
82 |
:param question: An `IQuestion`.
|
|
83 |
:param user: An `IPerson`.
|
|
12928.2.12
by Curtis Hovey
Added QuestionRecipientSet so that processes can state who should receive emails. |
84 |
:param recipient_set: A `QuestionRecipientSet`.
|
12928.2.18
by Curtis Hovey
Fixed documentation. |
85 |
:param subject: The subject of the email.
|
12928.2.9
by Curtis Hovey
Fixed grammar and spelling. |
86 |
:param body: The text of the email that is common to all recipients.
|
87 |
:param headers: A dict of headers for the email that are common to
|
|
88 |
all recipients.
|
|
12919.3.7
by Curtis Hovey
Renamed params. |
89 |
"""
|