~launchpad-pqm/launchpad/devel

« back to all changes in this revision

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

  • Committer: Curtis Hovey
  • Date: 2011-05-12 18:25:06 UTC
  • mto: This revision was merged to the branch mainline in revision 13038.
  • Revision ID: curtis.hovey@canonical.com-20110512182506-098n1wovp9m1av59
Renamed licence_reviewed to project_reviewed.

Show diffs side-by-side

added added

removed removed

Lines of Context:
17
17
 
18
18
from canonical.database.enumcol import EnumCol
19
19
from canonical.database.sqlbase import SQLBase
20
 
from lp.services.messages.interfaces.message import IMessage
 
20
from canonical.launchpad.interfaces.message import IMessage
21
21
from lp.answers.enums import (
22
22
    QuestionAction,
23
23
    QuestionStatus,
24
24
    )
25
25
from lp.answers.interfaces.questionmessage import IQuestionMessage
26
 
from lp.registry.interfaces.person import validate_public_person
27
26
from lp.services.propertycache import cachedproperty
28
27
 
29
28
 
46
45
    new_status = EnumCol(
47
46
        schema=QuestionStatus, notNull=True, default=QuestionStatus.OPEN)
48
47
 
49
 
    owner = ForeignKey(dbName='owner', foreignKey='Person',
50
 
        storm_validator=validate_public_person, notNull=True)
51
 
 
52
 
    def __init__(self, **kwargs):
53
 
        if 'owner' not in kwargs:
54
 
            # Although a trigger will set the owner after the SQL
55
 
            # INSERT has been executed, we must specify the parameter
56
 
            # explicitly to fulfill the DB constraint OWNER NOT NULL,
57
 
            # otherweise we'll get an error from the DB server.
58
 
            kwargs['owner'] = kwargs['message'].owner
59
 
        super(QuestionMessage, self).__init__(**kwargs)
60
 
 
61
48
    def __iter__(self):
62
49
        """See IMessage."""
63
50
        # Delegates do not proxy __ methods, because of the name mangling.
65
52
 
66
53
    @cachedproperty
67
54
    def index(self):
68
 
        return list(self.question.messages).index(self)
69
 
 
70
 
    @cachedproperty
71
 
    def display_index(self):
72
55
        # Return the index + 1 so that messages appear 1-indexed in the UI.
73
 
        return self.index + 1
 
56
        return list(self.question.messages).index(self) + 1
74
57
 
75
58
    @property
76
59
    def visible(self):