"""$URL: svn+ssh://svn.mems-exchange.org/repos/trunk/dulcinea/lib/comment.py $
$Id: comment.py 25468 2004-10-26 20:01:02Z dbinger $

Provides Comment.
"""

from dulcinea.base import DulcineaPersistent
from dulcinea.timestamped import Timestamped
from dulcinea.typeutils import typecheck
from dulcinea.user import DulcineaUser

class Comment(DulcineaPersistent, Timestamped):
    """A single comment with a bit of audit trail: its author and the
    time it was made.

    Instance attributes:
      text : string
        Text of comment
      user : DulcineaUser
        User who wrote the comment

    All of these attributes should be treated as read-only after the
    Comment instance has been created.
    """

    text_is = str
    user_is = DulcineaUser

    def __init__ (self, text, user):
        Timestamped.__init__(self)
        typecheck(user, DulcineaUser, allow_none=1)
        self.text = text
        self.user = user

    def get_text(self):
        return self.text

    def get_user(self):
        return self.user

    def __str__ (self):
        return "%s at %s" % (self.user, self.get_timestamp())

    def __cmp__ (self, other):
        return cmp((self.text, self.user, self.get_timestamp()),
                   (other.text, other.user, other.get_timestamp()))

