app/soc/models/comment.py
author Sverre Rabbelier <srabbelier@gmail.com>
Thu, 05 Mar 2009 19:21:43 +0000
changeset 1678 80411f57f31a
child 1687 8203c805edc7
permissions -rw-r--r--
Added comment support, but don't enable it Patch by: Sverre Rabbelier
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
1678
80411f57f31a Added comment support, but don't enable it
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
     1
#!/usr/bin/python2.5
80411f57f31a Added comment support, but don't enable it
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
     2
#
80411f57f31a Added comment support, but don't enable it
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
     3
# Copyright 2008 the Melange authors.
80411f57f31a Added comment support, but don't enable it
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
     4
#
80411f57f31a Added comment support, but don't enable it
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
     5
# Licensed under the Apache License, Version 2.0 (the "License");
80411f57f31a Added comment support, but don't enable it
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
     6
# you may not use this file except in compliance with the License.
80411f57f31a Added comment support, but don't enable it
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
     7
# You may obtain a copy of the License at
80411f57f31a Added comment support, but don't enable it
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
     8
#
80411f57f31a Added comment support, but don't enable it
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
     9
#   http://www.apache.org/licenses/LICENSE-2.0
80411f57f31a Added comment support, but don't enable it
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    10
#
80411f57f31a Added comment support, but don't enable it
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    11
# Unless required by applicable law or agreed to in writing, software
80411f57f31a Added comment support, but don't enable it
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    12
# distributed under the License is distributed on an "AS IS" BASIS,
80411f57f31a Added comment support, but don't enable it
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    13
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
80411f57f31a Added comment support, but don't enable it
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    14
# See the License for the specific language governing permissions and
80411f57f31a Added comment support, but don't enable it
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    15
# limitations under the License.
80411f57f31a Added comment support, but don't enable it
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    16
80411f57f31a Added comment support, but don't enable it
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    17
"""This module contains the comment Model."""
80411f57f31a Added comment support, but don't enable it
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    18
80411f57f31a Added comment support, but don't enable it
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    19
__authors__ = [
80411f57f31a Added comment support, but don't enable it
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    20
  '"Matthew Wilkes" <matthew@matthewwilkes.co.uk>',
80411f57f31a Added comment support, but don't enable it
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    21
]
80411f57f31a Added comment support, but don't enable it
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    22
80411f57f31a Added comment support, but don't enable it
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    23
from google.appengine.ext import db
80411f57f31a Added comment support, but don't enable it
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    24
80411f57f31a Added comment support, but don't enable it
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    25
import soc.models.work
80411f57f31a Added comment support, but don't enable it
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    26
import soc.models.user
80411f57f31a Added comment support, but don't enable it
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    27
from soc.models import base
80411f57f31a Added comment support, but don't enable it
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    28
import soc.models.linkable
80411f57f31a Added comment support, but don't enable it
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    29
80411f57f31a Added comment support, but don't enable it
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    30
80411f57f31a Added comment support, but don't enable it
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    31
from django.utils.translation import ugettext as _
80411f57f31a Added comment support, but don't enable it
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    32
80411f57f31a Added comment support, but don't enable it
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    33
80411f57f31a Added comment support, but don't enable it
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    34
class Comment(soc.models.linkable.Linkable):
80411f57f31a Added comment support, but don't enable it
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    35
  """Model of a comment on a work.
80411f57f31a Added comment support, but don't enable it
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    36
80411f57f31a Added comment support, but don't enable it
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    37
  A comment is associated with a Work, for example a Document or a Proposal,
80411f57f31a Added comment support, but don't enable it
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    38
  and with a user, the author.  There are two types of comment, public (i.e.
80411f57f31a Added comment support, but don't enable it
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    39
  visible to the student), or private (i.e. visible to programme/club staff).
80411f57f31a Added comment support, but don't enable it
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    40
  Neither type are visible to people who are not connected to the work being
80411f57f31a Added comment support, but don't enable it
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    41
  commented on.
80411f57f31a Added comment support, but don't enable it
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    42
  """
80411f57f31a Added comment support, but don't enable it
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    43
80411f57f31a Added comment support, but don't enable it
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    44
  #: A required many:1 relationship with a Work, where the comment entity
80411f57f31a Added comment support, but don't enable it
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    45
  #: provides additional textual information about the commented work.
80411f57f31a Added comment support, but don't enable it
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    46
  #: There is a backreference in Work called comments, which is a db.Query
80411f57f31a Added comment support, but don't enable it
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    47
  #: instance
80411f57f31a Added comment support, but don't enable it
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    48
  commented = db.ReferenceProperty(reference_class=soc.models.work.Work,
80411f57f31a Added comment support, but don't enable it
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    49
                                  required=False, collection_name="comments")
80411f57f31a Added comment support, but don't enable it
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    50
80411f57f31a Added comment support, but don't enable it
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    51
  #: A required many:1 relationship with a comment entity indicating
80411f57f31a Added comment support, but don't enable it
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    52
  #: the user who provided that comment.  There is a backreference in Work
80411f57f31a Added comment support, but don't enable it
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    53
  #: called comments, which is a db.Query instance.
80411f57f31a Added comment support, but don't enable it
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    54
  author = db.ReferenceProperty(reference_class=soc.models.user.User,
80411f57f31a Added comment support, but don't enable it
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    55
                                  required=True, collection_name="commented")
80411f57f31a Added comment support, but don't enable it
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    56
80411f57f31a Added comment support, but don't enable it
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    57
  #: The rich textual content of this comment
80411f57f31a Added comment support, but don't enable it
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    58
  content = db.TextProperty(verbose_name=_('Content'))
80411f57f31a Added comment support, but don't enable it
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    59
80411f57f31a Added comment support, but don't enable it
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    60
  #: Indicated if the comment should be visible to the appropriate student
80411f57f31a Added comment support, but don't enable it
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    61
  is_public = db.BooleanProperty(
80411f57f31a Added comment support, but don't enable it
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    62
    verbose_name=_('Public comment'))
80411f57f31a Added comment support, but don't enable it
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    63
80411f57f31a Added comment support, but don't enable it
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    64
  #: Date when the comment was added
80411f57f31a Added comment support, but don't enable it
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    65
  created = db.DateTimeProperty(auto_now_add=True)
80411f57f31a Added comment support, but don't enable it
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    66
80411f57f31a Added comment support, but don't enable it
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    67
  #: date when the work was last modified
80411f57f31a Added comment support, but don't enable it
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    68
  modified = db.DateTimeProperty(auto_now=True)
80411f57f31a Added comment support, but don't enable it
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    69
80411f57f31a Added comment support, but don't enable it
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    70
  # indicating wich user last modified the work. Used in displaying Work
80411f57f31a Added comment support, but don't enable it
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    71
  modified_by = db.ReferenceProperty(reference_class=soc.models.user.User,
80411f57f31a Added comment support, but don't enable it
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    72
                                     required=False,
80411f57f31a Added comment support, but don't enable it
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    73
                                     collection_name="modified_comments",
80411f57f31a Added comment support, but don't enable it
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    74
                                     verbose_name=_('Modified by'))