app/soc/models/work.py
author Todd Larsen <tlarsen@google.com>
Tue, 14 Oct 2008 21:39:57 +0000
changeset 329 2d90d49ce78a
parent 242 17984abf0c74
child 342 72482d8e5b34
permissions -rw-r--r--
Add is_featured boolean property to the Work model, so that Works can be designated as "featured" items in various places in the UI. This will be used to allow Sponsors, Programs, and Organizations to select Documents that should be included in their sidebar menus. Perhaps featured "site" Documents, such as site-wide Terms of Service, should probably be listed below the "User (sign-out)" menu, since the User will have to read and agree to these before being allowed to use the site. A collapsable Javascript sidebar is probably going to be needed soon... Patch by: Todd Larsen Review by: to-be-reviewed
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
16
300f7606e100 Initial definition of the Work Model.
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
     1
#!/usr/bin/python2.5
300f7606e100 Initial definition of the Work Model.
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
     2
#
300f7606e100 Initial definition of the Work Model.
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
     3
# Copyright 2008 the Melange authors.
300f7606e100 Initial definition of the Work Model.
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
     4
#
300f7606e100 Initial definition of the Work Model.
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
     5
# Licensed under the Apache License, Version 2.0 (the "License");
300f7606e100 Initial definition of the Work Model.
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
     6
# you may not use this file except in compliance with the License.
300f7606e100 Initial definition of the Work Model.
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
     7
# You may obtain a copy of the License at
300f7606e100 Initial definition of the Work Model.
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
     8
#
300f7606e100 Initial definition of the Work Model.
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
     9
#   http://www.apache.org/licenses/LICENSE-2.0
300f7606e100 Initial definition of the Work Model.
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    10
#
300f7606e100 Initial definition of the Work Model.
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    11
# Unless required by applicable law or agreed to in writing, software
300f7606e100 Initial definition of the Work Model.
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    12
# distributed under the License is distributed on an "AS IS" BASIS,
300f7606e100 Initial definition of the Work Model.
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    13
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
300f7606e100 Initial definition of the Work Model.
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    14
# See the License for the specific language governing permissions and
300f7606e100 Initial definition of the Work Model.
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    15
# limitations under the License.
300f7606e100 Initial definition of the Work Model.
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    16
300f7606e100 Initial definition of the Work Model.
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    17
"""This module contains the Work Model."""
300f7606e100 Initial definition of the Work Model.
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    18
300f7606e100 Initial definition of the Work Model.
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    19
__authors__ = [
300f7606e100 Initial definition of the Work Model.
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    20
  '"Todd Larsen" <tlarsen@google.com>',
300f7606e100 Initial definition of the Work Model.
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    21
  '"Sverre Rabbelier" <sverre@rabbelier.nl>',
300f7606e100 Initial definition of the Work Model.
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    22
]
300f7606e100 Initial definition of the Work Model.
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    23
300f7606e100 Initial definition of the Work Model.
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    24
from google.appengine.ext import db
300f7606e100 Initial definition of the Work Model.
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    25
206
832335761384 Make use of PolyModel for Works, Documents, etc. Add some (but not all) of
Todd Larsen <tlarsen@google.com>
parents: 181
diff changeset
    26
from django.utils.translation import ugettext_lazy
16
300f7606e100 Initial definition of the Work Model.
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    27
206
832335761384 Make use of PolyModel for Works, Documents, etc. Add some (but not all) of
Todd Larsen <tlarsen@google.com>
parents: 181
diff changeset
    28
import polymodel
16
300f7606e100 Initial definition of the Work Model.
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    29
300f7606e100 Initial definition of the Work Model.
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    30
206
832335761384 Make use of PolyModel for Works, Documents, etc. Add some (but not all) of
Todd Larsen <tlarsen@google.com>
parents: 181
diff changeset
    31
class Work(polymodel.PolyModel):
832335761384 Make use of PolyModel for Works, Documents, etc. Add some (but not all) of
Todd Larsen <tlarsen@google.com>
parents: 181
diff changeset
    32
  """Model of a Work created by one or more Persons in Roles.
16
300f7606e100 Initial definition of the Work Model.
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    33
206
832335761384 Make use of PolyModel for Works, Documents, etc. Add some (but not all) of
Todd Larsen <tlarsen@google.com>
parents: 181
diff changeset
    34
  Work is a "base entity" of other more specific "works" created by Persons
832335761384 Make use of PolyModel for Works, Documents, etc. Add some (but not all) of
Todd Larsen <tlarsen@google.com>
parents: 181
diff changeset
    35
  serving in "roles".
832335761384 Make use of PolyModel for Works, Documents, etc. Add some (but not all) of
Todd Larsen <tlarsen@google.com>
parents: 181
diff changeset
    36
832335761384 Make use of PolyModel for Works, Documents, etc. Add some (but not all) of
Todd Larsen <tlarsen@google.com>
parents: 181
diff changeset
    37
   authors)  a many:many relationship with Roles, stored in a separate
832335761384 Make use of PolyModel for Works, Documents, etc. Add some (but not all) of
Todd Larsen <tlarsen@google.com>
parents: 181
diff changeset
    38
     WorksAuthors model, used to represent authorship of the Work.  See
832335761384 Make use of PolyModel for Works, Documents, etc. Add some (but not all) of
Todd Larsen <tlarsen@google.com>
parents: 181
diff changeset
    39
     the WorksAuthors model class for details.
16
300f7606e100 Initial definition of the Work Model.
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    40
300f7606e100 Initial definition of the Work Model.
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    41
   reviews)  a 1:many relationship between a Work and the zero or more
300f7606e100 Initial definition of the Work Model.
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    42
     Reviews of that Work.  This relation is implemented as the 'reviews'
300f7606e100 Initial definition of the Work Model.
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    43
     back-reference Query of the Review model 'reviewed' reference.
300f7606e100 Initial definition of the Work Model.
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    44
  """
300f7606e100 Initial definition of the Work Model.
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    45
300f7606e100 Initial definition of the Work Model.
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    46
  #: Required field indicating the "title" of the work, which may have
300f7606e100 Initial definition of the Work Model.
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    47
  #: different uses depending on the specific type of the work. Works
300f7606e100 Initial definition of the Work Model.
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    48
  #: can be indexed, filtered, and sorted by 'title'.
206
832335761384 Make use of PolyModel for Works, Documents, etc. Add some (but not all) of
Todd Larsen <tlarsen@google.com>
parents: 181
diff changeset
    49
  title = db.StringProperty(required=True,
832335761384 Make use of PolyModel for Works, Documents, etc. Add some (but not all) of
Todd Larsen <tlarsen@google.com>
parents: 181
diff changeset
    50
      verbose_name=ugettext_lazy('Title'))
832335761384 Make use of PolyModel for Works, Documents, etc. Add some (but not all) of
Todd Larsen <tlarsen@google.com>
parents: 181
diff changeset
    51
  title.help_text = ugettext_lazy(
832335761384 Make use of PolyModel for Works, Documents, etc. Add some (but not all) of
Todd Larsen <tlarsen@google.com>
parents: 181
diff changeset
    52
      'title of the document; often used in the window title')
832335761384 Make use of PolyModel for Works, Documents, etc. Add some (but not all) of
Todd Larsen <tlarsen@google.com>
parents: 181
diff changeset
    53
832335761384 Make use of PolyModel for Works, Documents, etc. Add some (but not all) of
Todd Larsen <tlarsen@google.com>
parents: 181
diff changeset
    54
  #: optional, indexed plain text field used for different purposes,
832335761384 Make use of PolyModel for Works, Documents, etc. Add some (but not all) of
Todd Larsen <tlarsen@google.com>
parents: 181
diff changeset
    55
  #: depending on the specific type of the work
832335761384 Make use of PolyModel for Works, Documents, etc. Add some (but not all) of
Todd Larsen <tlarsen@google.com>
parents: 181
diff changeset
    56
  abstract = db.StringProperty(multiline=True)
832335761384 Make use of PolyModel for Works, Documents, etc. Add some (but not all) of
Todd Larsen <tlarsen@google.com>
parents: 181
diff changeset
    57
  abstract.help_text = ugettext_lazy(
832335761384 Make use of PolyModel for Works, Documents, etc. Add some (but not all) of
Todd Larsen <tlarsen@google.com>
parents: 181
diff changeset
    58
      'short abstract, summary, or snippet;'
832335761384 Make use of PolyModel for Works, Documents, etc. Add some (but not all) of
Todd Larsen <tlarsen@google.com>
parents: 181
diff changeset
    59
      ' 500 characters or less, plain text displayed publicly')
16
300f7606e100 Initial definition of the Work Model.
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    60
220
3ebe00b44212 Add partial_path property explicitly to the Work model.
Todd Larsen <tlarsen@google.com>
parents: 206
diff changeset
    61
  #: Required path, prepended to a "link name" to form the document URL.
3ebe00b44212 Add partial_path property explicitly to the Work model.
Todd Larsen <tlarsen@google.com>
parents: 206
diff changeset
    62
  #: The combined path and link name must be globally unique on the
3ebe00b44212 Add partial_path property explicitly to the Work model.
Todd Larsen <tlarsen@google.com>
parents: 206
diff changeset
    63
  #: site.  Except in /site/docs (Developer) forms, this field is not
3ebe00b44212 Add partial_path property explicitly to the Work model.
Todd Larsen <tlarsen@google.com>
parents: 206
diff changeset
    64
  #: usually directly editable by the User, but is instead set by controller
3ebe00b44212 Add partial_path property explicitly to the Work model.
Todd Larsen <tlarsen@google.com>
parents: 206
diff changeset
    65
  #: logic to match the "scope" of the document.
3ebe00b44212 Add partial_path property explicitly to the Work model.
Todd Larsen <tlarsen@google.com>
parents: 206
diff changeset
    66
  partial_path = db.StringProperty(required=True,
3ebe00b44212 Add partial_path property explicitly to the Work model.
Todd Larsen <tlarsen@google.com>
parents: 206
diff changeset
    67
      verbose_name=ugettext_lazy('Partial path'))
3ebe00b44212 Add partial_path property explicitly to the Work model.
Todd Larsen <tlarsen@google.com>
parents: 206
diff changeset
    68
  partial_path.help_text = ugettext_lazy(
3ebe00b44212 Add partial_path property explicitly to the Work model.
Todd Larsen <tlarsen@google.com>
parents: 206
diff changeset
    69
    'path portion of URLs, prepended to link name')
3ebe00b44212 Add partial_path property explicitly to the Work model.
Todd Larsen <tlarsen@google.com>
parents: 206
diff changeset
    70
206
832335761384 Make use of PolyModel for Works, Documents, etc. Add some (but not all) of
Todd Larsen <tlarsen@google.com>
parents: 181
diff changeset
    71
  #: Required link name, appended to a "path" to form the document URL.
220
3ebe00b44212 Add partial_path property explicitly to the Work model.
Todd Larsen <tlarsen@google.com>
parents: 206
diff changeset
    72
  #: The combined path and link name must be globally unique on the
206
832335761384 Make use of PolyModel for Works, Documents, etc. Add some (but not all) of
Todd Larsen <tlarsen@google.com>
parents: 181
diff changeset
    73
  #: site (but, unlike some link names, a Work link name can be reused,
832335761384 Make use of PolyModel for Works, Documents, etc. Add some (but not all) of
Todd Larsen <tlarsen@google.com>
parents: 181
diff changeset
    74
  #: as long as the combination with the preceding path is unique).
832335761384 Make use of PolyModel for Works, Documents, etc. Add some (but not all) of
Todd Larsen <tlarsen@google.com>
parents: 181
diff changeset
    75
  link_name = db.StringProperty(required=True,
832335761384 Make use of PolyModel for Works, Documents, etc. Add some (but not all) of
Todd Larsen <tlarsen@google.com>
parents: 181
diff changeset
    76
      verbose_name=ugettext_lazy('Link name'))
832335761384 Make use of PolyModel for Works, Documents, etc. Add some (but not all) of
Todd Larsen <tlarsen@google.com>
parents: 181
diff changeset
    77
  link_name.help_text = ugettext_lazy('link name used in URLs')
832335761384 Make use of PolyModel for Works, Documents, etc. Add some (but not all) of
Todd Larsen <tlarsen@google.com>
parents: 181
diff changeset
    78
832335761384 Make use of PolyModel for Works, Documents, etc. Add some (but not all) of
Todd Larsen <tlarsen@google.com>
parents: 181
diff changeset
    79
  #: short name used in places such as the sidebar menu and breadcrumb trail
832335761384 Make use of PolyModel for Works, Documents, etc. Add some (but not all) of
Todd Larsen <tlarsen@google.com>
parents: 181
diff changeset
    80
  #: (optional: title will be used if short_name is not present)
832335761384 Make use of PolyModel for Works, Documents, etc. Add some (but not all) of
Todd Larsen <tlarsen@google.com>
parents: 181
diff changeset
    81
  short_name = db.StringProperty(verbose_name=ugettext_lazy('Short name'))
832335761384 Make use of PolyModel for Works, Documents, etc. Add some (but not all) of
Todd Larsen <tlarsen@google.com>
parents: 181
diff changeset
    82
  short_name.help_text = ugettext_lazy(
832335761384 Make use of PolyModel for Works, Documents, etc. Add some (but not all) of
Todd Larsen <tlarsen@google.com>
parents: 181
diff changeset
    83
      'short name used, for example, in the sidebar menu')
832335761384 Make use of PolyModel for Works, Documents, etc. Add some (but not all) of
Todd Larsen <tlarsen@google.com>
parents: 181
diff changeset
    84
  
832335761384 Make use of PolyModel for Works, Documents, etc. Add some (but not all) of
Todd Larsen <tlarsen@google.com>
parents: 181
diff changeset
    85
  #: date when the work was created
832335761384 Make use of PolyModel for Works, Documents, etc. Add some (but not all) of
Todd Larsen <tlarsen@google.com>
parents: 181
diff changeset
    86
  created = db.DateTimeProperty(auto_now_add=True)
832335761384 Make use of PolyModel for Works, Documents, etc. Add some (but not all) of
Todd Larsen <tlarsen@google.com>
parents: 181
diff changeset
    87
  
832335761384 Make use of PolyModel for Works, Documents, etc. Add some (but not all) of
Todd Larsen <tlarsen@google.com>
parents: 181
diff changeset
    88
  #: date when the work was last modified
832335761384 Make use of PolyModel for Works, Documents, etc. Add some (but not all) of
Todd Larsen <tlarsen@google.com>
parents: 181
diff changeset
    89
  modified = db.DateTimeProperty(auto_now=True)
242
17984abf0c74 Some TODOs on access control that I didn't want to forget.
Todd Larsen <tlarsen@google.com>
parents: 220
diff changeset
    90
17984abf0c74 Some TODOs on access control that I didn't want to forget.
Todd Larsen <tlarsen@google.com>
parents: 220
diff changeset
    91
  # TODO: some sort of access control preferences are needed at this basic
17984abf0c74 Some TODOs on access control that I didn't want to forget.
Todd Larsen <tlarsen@google.com>
parents: 220
diff changeset
    92
  #   level.  Works need to be restrict-able to:
17984abf0c74 Some TODOs on access control that I didn't want to forget.
Todd Larsen <tlarsen@google.com>
parents: 220
diff changeset
    93
  #    * the authors only
17984abf0c74 Some TODOs on access control that I didn't want to forget.
Todd Larsen <tlarsen@google.com>
parents: 220
diff changeset
    94
  #    * the administrators of the Groups that the authors are in
17984abf0c74 Some TODOs on access control that I didn't want to forget.
Todd Larsen <tlarsen@google.com>
parents: 220
diff changeset
    95
  #    * any member of the authors' Groups
17984abf0c74 Some TODOs on access control that I didn't want to forget.
Todd Larsen <tlarsen@google.com>
parents: 220
diff changeset
    96
  #    * logged-in User with a profile
17984abf0c74 Some TODOs on access control that I didn't want to forget.
Todd Larsen <tlarsen@google.com>
parents: 220
diff changeset
    97
  #    * logged-in Users, but no profile is necessary
17984abf0c74 Some TODOs on access control that I didn't want to forget.
Todd Larsen <tlarsen@google.com>
parents: 220
diff changeset
    98
  #    * anyone, even those not logged in
17984abf0c74 Some TODOs on access control that I didn't want to forget.
Todd Larsen <tlarsen@google.com>
parents: 220
diff changeset
    99
  #  (and possibly others)
17984abf0c74 Some TODOs on access control that I didn't want to forget.
Todd Larsen <tlarsen@google.com>
parents: 220
diff changeset
   100
329
2d90d49ce78a Add is_featured boolean property to the Work model, so that Works can be
Todd Larsen <tlarsen@google.com>
parents: 242
diff changeset
   101
  #: field storing whether a link to the Work should be featured in
2d90d49ce78a Add is_featured boolean property to the Work model, so that Works can be
Todd Larsen <tlarsen@google.com>
parents: 242
diff changeset
   102
  #: the sidebar menu (and possibly elsewhere); FAQs, Terms of Service,
2d90d49ce78a Add is_featured boolean property to the Work model, so that Works can be
Todd Larsen <tlarsen@google.com>
parents: 242
diff changeset
   103
  #: and the like are examples of "featured" Works
2d90d49ce78a Add is_featured boolean property to the Work model, so that Works can be
Todd Larsen <tlarsen@google.com>
parents: 242
diff changeset
   104
  is_featured = db.BooleanProperty(
2d90d49ce78a Add is_featured boolean property to the Work model, so that Works can be
Todd Larsen <tlarsen@google.com>
parents: 242
diff changeset
   105
      verbose_name=ugettext_lazy('Is Featured'))
2d90d49ce78a Add is_featured boolean property to the Work model, so that Works can be
Todd Larsen <tlarsen@google.com>
parents: 242
diff changeset
   106
  is_featured.help_text = ugettext_lazy(
2d90d49ce78a Add is_featured boolean property to the Work model, so that Works can be
Todd Larsen <tlarsen@google.com>
parents: 242
diff changeset
   107
      'Field used to indicate if a Work should be featured, for example,'
2d90d49ce78a Add is_featured boolean property to the Work model, so that Works can be
Todd Larsen <tlarsen@google.com>
parents: 242
diff changeset
   108
      ' in the sidebar menu.')