~launchpad-pqm/launchpad/devel

« back to all changes in this revision

Viewing changes to lib/lp/answers/model/questionsperson.py

  • Committer: Launchpad Patch Queue Manager
  • Date: 2011-05-18 19:08:48 UTC
  • mfrom: (13063.5.5 answers-api-3)
  • Revision ID: launchpad@pqm.canonical.com-20110518190848-swacp7b8yfy0lb34
[r=abentley][bug=784398] Export IQuestionsPerson to the API.

Show diffs side-by-side

added added

removed removed

Lines of Context:
3
3
 
4
4
__metaclass__ = type
5
5
__all__ = [
6
 
    'QuestionsPerson',
 
6
    'QuestionsPersonMixin',
7
7
    ]
8
8
 
9
9
 
10
 
from zope.component import adapts
11
 
from zope.interface import implements
12
 
 
13
10
from canonical.database.sqlbase import sqlvalues
14
11
from lp.answers.enums import QUESTION_STATUS_DEFAULT_SEARCH
15
 
from lp.answers.interfaces.questionsperson import IQuestionsPerson
16
12
from lp.answers.model.answercontact import AnswerContact
17
13
from lp.answers.model.question import QuestionPersonSearch
18
 
from lp.registry.interfaces.person import IPerson
19
14
from lp.services.worlddata.model.language import Language
20
15
 
21
16
 
22
 
class QuestionsPerson:
 
17
class QuestionsPersonMixin:
23
18
    """See `IQuestionsPerson`."""
24
 
    implements(IQuestionsPerson)
25
 
    adapts(IPerson)
26
 
 
27
 
    def __init__(self, person):
28
 
        self.person = person
29
19
 
30
20
    def searchQuestions(self, search_text=None,
31
21
                        status=QUESTION_STATUS_DEFAULT_SEARCH,
33
23
                        needs_attention=None):
34
24
        """See `IQuestionsPerson`."""
35
25
        return QuestionPersonSearch(
36
 
                person=self.person,
 
26
                person=self,
37
27
                search_text=search_text,
38
28
                status=status, language=language, sort=sort,
39
29
                participation=participation,
52
42
            UNION SELECT question
53
43
                  FROM QuestionMessage JOIN Message ON (message = Message.id)
54
44
                  WHERE owner = %(personID)s
55
 
            )""" % sqlvalues(personID=self.person.id),
 
45
            )""" % sqlvalues(personID=self.id),
56
46
            clauseTables=['Question'], distinct=True))
57
47
 
58
48
    def getDirectAnswerQuestionTargets(self):
59
49
        """See `IQuestionsPerson`."""
60
50
        answer_contacts = AnswerContact.select(
61
 
            'person = %s' % sqlvalues(self.person))
 
51
            'person = %s' % sqlvalues(self))
62
52
        return self._getQuestionTargetsFromAnswerContacts(answer_contacts)
63
53
 
64
54
    def getTeamAnswerQuestionTargets(self):
67
57
            '''AnswerContact.person = TeamParticipation.team
68
58
            AND TeamParticipation.person = %(personID)s
69
59
            AND AnswerContact.person != %(personID)s''' % sqlvalues(
70
 
                personID=self.person.id),
 
60
                personID=self.id),
71
61
            clauseTables=['TeamParticipation'], distinct=True)
72
62
        return self._getQuestionTargetsFromAnswerContacts(answer_contacts)
73
63