~launchpad-pqm/launchpad/devel

« back to all changes in this revision

Viewing changes to lib/lp/answers/interfaces/questiontarget.py

  • Committer: Francis J. Lacoste
  • Date: 2011-04-27 21:40:03 UTC
  • mto: This revision was merged to the branch mainline in revision 12971.
  • Revision ID: francis.lacoste@canonical.com-20110427214003-iiqhcyyswppyqjsx
Change the default timeout to production value, improved options documentation and use only one bin above timeout value.

Show diffs side-by-side

added added

removed removed

Lines of Context:
16
16
from zope.interface import Interface
17
17
from zope.schema import (
18
18
    Choice,
19
 
    Int,
20
19
    List,
21
20
    Set,
22
21
    TextLine,
23
22
    )
24
23
 
25
 
from lazr.restful.declarations import (
26
 
    call_with,
27
 
    export_as_webservice_entry,
28
 
    export_read_operation,
29
 
    export_write_operation,
30
 
    operation_for_version,
31
 
    operation_parameters,
32
 
    operation_returns_collection_of,
33
 
    REQUEST_USER,
34
 
    )
35
 
from lazr.restful.fields import Reference
36
 
 
37
24
from canonical.launchpad import _
38
25
from lp.answers.interfaces.questioncollection import (
39
26
    ISearchableByQuestionOwner,
43
30
    QuestionStatus,
44
31
    QUESTION_STATUS_DEFAULT_SEARCH,
45
32
    )
46
 
from lp.registry.interfaces.person import IPerson
47
33
from lp.services.fields import PublicPersonChoice
48
 
from lp.services.worlddata.interfaces.language import ILanguage
49
 
 
50
 
 
51
 
class IQuestionTargetPublic(ISearchableByQuestionOwner):
52
 
    """Methods that anonymous in user can access."""
53
 
 
54
 
    @operation_parameters(
55
 
        question_id=Int(title=_('Question Number'), required=True))
56
 
    @export_read_operation()
57
 
    @operation_for_version('devel')
 
34
 
 
35
 
 
36
class IQuestionTarget(ISearchableByQuestionOwner):
 
37
    """An object that can have a new question asked about it."""
 
38
 
 
39
    def newQuestion(owner, title, description, language=None,
 
40
                    datecreated=None):
 
41
        """Create a new question.
 
42
 
 
43
         A new question is created with status OPEN.
 
44
 
 
45
        The owner and all of the target answer contacts will be subscribed
 
46
        to the question.
 
47
 
 
48
        :owner: An IPerson.
 
49
        :title: A string.
 
50
        :description: A string.
 
51
        :language: An ILanguage. If that parameter is omitted, the question
 
52
                 is assumed to be created in English.
 
53
        :datecreated:  A datetime object that will be used for the datecreated
 
54
                attribute. Defaults to canonical.database.constants.UTC_NOW.
 
55
        """
 
56
 
 
57
    def createQuestionFromBug(bug):
 
58
        """Create and return a Question from a Bug.
 
59
 
 
60
        The bug's title and description are used as the question title and
 
61
        description. The bug owner is the question owner. The question
 
62
        is automatically linked to the bug.
 
63
 
 
64
        Note that bug messages are copied to the question, but attachments
 
65
        are not. The question is the same age as the bug, though its
 
66
        datelastresponse attribute is current to signify the question is
 
67
        active.
 
68
 
 
69
        :bug: An IBug.
 
70
        """
 
71
 
58
72
    def getQuestion(question_id):
59
73
        """Return the question by its id, if it is applicable to this target.
60
74
 
63
77
        If there is no such question number for this target, return None
64
78
        """
65
79
 
66
 
    @operation_parameters(
67
 
        phrase=TextLine(title=_('A phrase'), required=True))
68
 
    @operation_returns_collection_of(Interface)
69
 
    @export_read_operation()
70
 
    @operation_for_version('devel')
71
 
    def findSimilarQuestions(phrase):
72
 
        """Return questions similar to phrase.
 
80
    def findSimilarQuestions(title):
 
81
        """Return questions similar to title.
73
82
 
74
 
        Return a list of question similar to the provided phrase. These
75
 
        questions will be found using a fuzzy search. The list is
 
83
        Return a list of question similar to the title provided. These
 
84
        questions should be found using a fuzzy search. The list should be
76
85
        ordered from the most similar question to the least similar question.
77
86
 
78
 
        :param phrase: A phrase such as the summary of a question.
79
 
        """
80
 
 
81
 
    @operation_parameters(
82
 
        language=Reference(ILanguage))
83
 
    @operation_returns_collection_of(IPerson)
84
 
    @export_read_operation()
85
 
    @operation_for_version('devel')
 
87
        :title: A phrase
 
88
        """
 
89
 
 
90
    def addAnswerContact(person):
 
91
        """Add a new answer contact.
 
92
 
 
93
        :person: An IPerson.
 
94
 
 
95
        Returns True if the person was added, False if the person already was
 
96
        an answer contact. A person must have at least one preferred
 
97
        language to be an answer contact.
 
98
        """
 
99
 
 
100
    def removeAnswerContact(person):
 
101
        """Remove an answer contact.
 
102
 
 
103
        :person: An IPerson.
 
104
 
 
105
        Returns True if the person was removed, False if the person wasn't an
 
106
        answer contact.
 
107
        """
 
108
 
86
109
    def getAnswerContactsForLanguage(language):
87
110
        """Return the list of Persons that provide support for a language.
88
111
 
101
124
        for the QuestionTarget.
102
125
        """
103
126
 
104
 
    @operation_returns_collection_of(ILanguage)
105
 
    @export_read_operation()
106
 
    @operation_for_version('devel')
107
127
    def getSupportedLanguages():
108
 
        """Return a list of languages spoken by at the answer contacts.
 
128
        """Return the set of languages spoken by at least one of this object's
 
129
        answer contacts.
109
130
 
110
131
        An answer contact is considered to speak a given language if that
111
132
        language is listed as one of his preferred languages.
128
149
        value_type=PublicPersonChoice(vocabulary="ValidPersonOrTeam"))
129
150
 
130
151
 
131
 
class IQuestionTargetView(Interface):
132
 
    """Methods that logged in user can access."""
133
 
 
134
 
    def newQuestion(owner, title, description, language=None,
135
 
                    datecreated=None):
136
 
        """Create a new question.
137
 
 
138
 
         A new question is created with status OPEN.
139
 
 
140
 
        The owner and all of the target answer contacts will be subscribed
141
 
        to the question.
142
 
 
143
 
        :owner: An IPerson.
144
 
        :title: A string.
145
 
        :description: A string.
146
 
        :language: An ILanguage. If that parameter is omitted, the question
147
 
                 is assumed to be created in English.
148
 
        :datecreated:  A datetime object that will be used for the datecreated
149
 
                attribute. Defaults to canonical.database.constants.UTC_NOW.
150
 
        """
151
 
 
152
 
    def createQuestionFromBug(bug):
153
 
        """Create and return a Question from a Bug.
154
 
 
155
 
        The bug's title and description are used as the question title and
156
 
        description. The bug owner is the question owner. The question
157
 
        is automatically linked to the bug.
158
 
 
159
 
        Note that bug messages are copied to the question, but attachments
160
 
        are not. The question is the same age as the bug, though its
161
 
        datelastresponse attribute is current to signify the question is
162
 
        active.
163
 
 
164
 
        :bug: An IBug.
165
 
        """
166
 
 
167
 
    @operation_parameters(
168
 
        person=PublicPersonChoice(
169
 
            title=_('The user or an administered team'), required=True,
170
 
            vocabulary='ValidPersonOrTeam'))
171
 
    @call_with(subscribed_by=REQUEST_USER)
172
 
    @export_read_operation()
173
 
    @operation_for_version('devel')
174
 
    def canUserAlterAnswerContact(person, subscribed_by):
175
 
        """Can the user add or remove the answer contact.
176
 
 
177
 
        Users can add or remove themselves or one of the teams they
178
 
        administered.
179
 
 
180
 
        :param person: The `IPerson` that is or will be an answer contact.
181
 
        :param subscribed_by: The `IPerson` making the change.
182
 
        """
183
 
 
184
 
    @operation_parameters(
185
 
        person=PublicPersonChoice(
186
 
            title=_('The user of an administered team'), required=True,
187
 
            vocabulary='ValidPersonOrTeam'))
188
 
    @call_with(subscribed_by=REQUEST_USER)
189
 
    @export_write_operation()
190
 
    @operation_for_version('devel')
191
 
    def addAnswerContact(person, subscribed_by):
192
 
        """Add a new answer contact.
193
 
 
194
 
        :param person: An `IPerson`.
195
 
        :param subscribed_by: The user making the change.
196
 
        :return: True if the person was added, False if the person already is
197
 
            an answer contact.
198
 
        :raises AddAnswerContactError: When the person or team does no have a
199
 
            preferred language.
200
 
        """
201
 
 
202
 
    @operation_parameters(
203
 
        person=PublicPersonChoice(
204
 
            title=_('The user of an administered team'), required=True,
205
 
            vocabulary='ValidPersonOrTeam'))
206
 
    @call_with(subscribed_by=REQUEST_USER)
207
 
    @export_write_operation()
208
 
    @operation_for_version('devel')
209
 
    def removeAnswerContact(person, subscribed_by):
210
 
        """Remove an answer contact.
211
 
 
212
 
        :param person: An `IPerson`.
213
 
        :param subscribed_by: The user making the change.
214
 
        :return: True if the person was removed, False if the person wasn't an
215
 
            answer contact.
216
 
        """
217
 
 
218
 
 
219
 
class IQuestionTarget(IQuestionTargetPublic, IQuestionTargetView):
220
 
    """An object that can have a new question asked about it."""
221
 
    export_as_webservice_entry(as_of='devel')
222
 
 
223
 
 
224
152
# These schemas are only used by browser/questiontarget.py and should really
225
153
# live there. See Bug #66950.
226
154
class ISearchQuestionsForm(Interface):