app/soc/models/work.py
author Mario Ferraro <fadinlight@gmail.com>
Sun, 15 Nov 2009 22:12:20 +0100
changeset 3093 d1be59b6b627
parent 2558 ba32a4f5716b
permissions -rw-r--r--
GMaps related JS changed to use new google namespace. Google is going to change permanently in the future the way to load its services, so better stay safe. Also this commit shows uses of the new melange.js module. Fixes Issue 634.
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
#
1308
35b75ffcbb37 Partially reverted "Update the copyright notice for 2009."
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1307
diff changeset
     3
# Copyright 2008 the Melange authors.
16
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
342
72482d8e5b34 Remove the proposed WorksAuthors many:many relation and promote the "founder"
Todd Larsen <tlarsen@google.com>
parents: 329
diff changeset
    24
16
300f7606e100 Initial definition of the Work Model.
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    25
from google.appengine.ext import db
300f7606e100 Initial definition of the Work Model.
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    26
970
8b5611d5b053 Use ugettext instead of ugettext_lazy
Sverre Rabbelier <srabbelier@gmail.com>
parents: 621
diff changeset
    27
from django.utils.translation import ugettext
16
300f7606e100 Initial definition of the Work Model.
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    28
533
ba3309b2fd30 Move LINK_ID and SCOPE_PATH regular expressions to soc/models/linkable.py.
Todd Larsen <tlarsen@google.com>
parents: 513
diff changeset
    29
import soc.models.linkable
342
72482d8e5b34 Remove the proposed WorksAuthors many:many relation and promote the "founder"
Todd Larsen <tlarsen@google.com>
parents: 329
diff changeset
    30
import soc.models.user
16
300f7606e100 Initial definition of the Work Model.
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    31
300f7606e100 Initial definition of the Work Model.
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    32
533
ba3309b2fd30 Move LINK_ID and SCOPE_PATH regular expressions to soc/models/linkable.py.
Todd Larsen <tlarsen@google.com>
parents: 513
diff changeset
    33
class Work(soc.models.linkable.Linkable):
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
  """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
    35
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
    36
  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
    37
  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
    38
342
72482d8e5b34 Remove the proposed WorksAuthors many:many relation and promote the "founder"
Todd Larsen <tlarsen@google.com>
parents: 329
diff changeset
    39
    reviews)  a 1:many relationship between a Work and the zero or more
72482d8e5b34 Remove the proposed WorksAuthors many:many relation and promote the "founder"
Todd Larsen <tlarsen@google.com>
parents: 329
diff changeset
    40
      Reviews of that Work.  This relation is implemented as the 'reviews'
72482d8e5b34 Remove the proposed WorksAuthors many:many relation and promote the "founder"
Todd Larsen <tlarsen@google.com>
parents: 329
diff changeset
    41
      back-reference Query of the Review model 'reviewed' reference.
16
300f7606e100 Initial definition of the Work Model.
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    42
  """
400
8f07048d84ef Added a generic version of the Document views
Sverre Rabbelier <srabbelier@gmail.com>
parents: 351
diff changeset
    43
342
72482d8e5b34 Remove the proposed WorksAuthors many:many relation and promote the "founder"
Todd Larsen <tlarsen@google.com>
parents: 329
diff changeset
    44
  #: Required 1:1 relationship indicating the User who initially authored the
72482d8e5b34 Remove the proposed WorksAuthors many:many relation and promote the "founder"
Todd Larsen <tlarsen@google.com>
parents: 329
diff changeset
    45
  #: Work (this relationship is needed to keep track of lifetime document
72482d8e5b34 Remove the proposed WorksAuthors many:many relation and promote the "founder"
Todd Larsen <tlarsen@google.com>
parents: 329
diff changeset
    46
  #: creation limits, used to prevent spamming, etc.).
72482d8e5b34 Remove the proposed WorksAuthors many:many relation and promote the "founder"
Todd Larsen <tlarsen@google.com>
parents: 329
diff changeset
    47
  author = db.ReferenceProperty(reference_class=soc.models.user.User,
621
21aea6e45a9d Fix too long lines in soc.model.work.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 584
diff changeset
    48
                                required=True,
21aea6e45a9d Fix too long lines in soc.model.work.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 584
diff changeset
    49
                                collection_name="created_documents",
970
8b5611d5b053 Use ugettext instead of ugettext_lazy
Sverre Rabbelier <srabbelier@gmail.com>
parents: 621
diff changeset
    50
                                verbose_name=ugettext('Created by'))
16
300f7606e100 Initial definition of the Work Model.
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    51
300f7606e100 Initial definition of the Work Model.
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    52
  #: 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
    53
  #: 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
    54
  #: 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
    55
  title = db.StringProperty(required=True,
970
8b5611d5b053 Use ugettext instead of ugettext_lazy
Sverre Rabbelier <srabbelier@gmail.com>
parents: 621
diff changeset
    56
      verbose_name=ugettext('Title'))
8b5611d5b053 Use ugettext instead of ugettext_lazy
Sverre Rabbelier <srabbelier@gmail.com>
parents: 621
diff changeset
    57
  title.help_text = ugettext(
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
    58
      '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
    59
832335761384 Make use of PolyModel for Works, Documents, etc. Add some (but not all) of
Todd Larsen <tlarsen@google.com>
parents: 181
diff changeset
    60
  #: 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
    61
  #: (optional: title will be used if short_name is not present)
970
8b5611d5b053 Use ugettext instead of ugettext_lazy
Sverre Rabbelier <srabbelier@gmail.com>
parents: 621
diff changeset
    62
  short_name = db.StringProperty(verbose_name=ugettext('Short name'))
8b5611d5b053 Use ugettext instead of ugettext_lazy
Sverre Rabbelier <srabbelier@gmail.com>
parents: 621
diff changeset
    63
  short_name.help_text = ugettext(
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
    64
      'short name used, for example, in the sidebar menu')
351
b37fc4c1e189 Eliminate the Work.abstract property and move the Document.content property
Todd Larsen <tlarsen@google.com>
parents: 342
diff changeset
    65
b37fc4c1e189 Eliminate the Work.abstract property and move the Document.content property
Todd Larsen <tlarsen@google.com>
parents: 342
diff changeset
    66
  #: Required db.TextProperty containing the contents of the Work.
b37fc4c1e189 Eliminate the Work.abstract property and move the Document.content property
Todd Larsen <tlarsen@google.com>
parents: 342
diff changeset
    67
  #: The content is only to be displayed to Persons in Roles eligible to
b37fc4c1e189 Eliminate the Work.abstract property and move the Document.content property
Todd Larsen <tlarsen@google.com>
parents: 342
diff changeset
    68
  #: view them (which may be anyone, for example, with the site front page).
970
8b5611d5b053 Use ugettext instead of ugettext_lazy
Sverre Rabbelier <srabbelier@gmail.com>
parents: 621
diff changeset
    69
  content = db.TextProperty(verbose_name=ugettext('Content'))
2558
ba32a4f5716b Added the possiblitity to add a description to the top of the Survey.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1687
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
  #: 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
    72
  created = db.DateTimeProperty(auto_now_add=True)
2558
ba32a4f5716b Added the possiblitity to add a description to the top of the Survey.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1687
diff changeset
    73
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
    74
  #: 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
    75
  modified = db.DateTimeProperty(auto_now=True)
2558
ba32a4f5716b Added the possiblitity to add a description to the top of the Survey.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1687
diff changeset
    76
584
ba8a624506e5 Adds and uses a modified_by property in models/work.py
Lennard de Rijk <ljvderijk@gmail.com>
parents: 545
diff changeset
    77
  # indicating wich user last modified the work. Used in displaying Work
ba8a624506e5 Adds and uses a modified_by property in models/work.py
Lennard de Rijk <ljvderijk@gmail.com>
parents: 545
diff changeset
    78
  modified_by = db.ReferenceProperty(reference_class=soc.models.user.User,
621
21aea6e45a9d Fix too long lines in soc.model.work.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 584
diff changeset
    79
                                     required=True,
21aea6e45a9d Fix too long lines in soc.model.work.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 584
diff changeset
    80
                                     collection_name="modified_documents",
970
8b5611d5b053 Use ugettext instead of ugettext_lazy
Sverre Rabbelier <srabbelier@gmail.com>
parents: 621
diff changeset
    81
                                     verbose_name=ugettext('Modified by'))
242
17984abf0c74 Some TODOs on access control that I didn't want to forget.
Todd Larsen <tlarsen@google.com>
parents: 220
diff changeset
    82
545
217921e76f50 Include name of entity in the text of the link to the read-only public view
Todd Larsen <tlarsen@google.com>
parents: 533
diff changeset
    83
  def name(self):
217921e76f50 Include name of entity in the text of the link to the read-only public view
Todd Larsen <tlarsen@google.com>
parents: 533
diff changeset
    84
    """Alias 'title' Property as 'name' for use in common templates.
217921e76f50 Include name of entity in the text of the link to the read-only public view
Todd Larsen <tlarsen@google.com>
parents: 533
diff changeset
    85
    """
217921e76f50 Include name of entity in the text of the link to the read-only public view
Todd Larsen <tlarsen@google.com>
parents: 533
diff changeset
    86
    return self.title