app/soc/models/linkable.py
author Todd Larsen <tlarsen@google.com>
Mon, 10 Nov 2008 18:00:47 +0000
changeset 467 07441582717a
child 468 198105fb00bc
permissions -rw-r--r--
Initial thoughts on a Linkable Model class. Please comment. Patch by: Todd Larsen
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
467
07441582717a Initial thoughts on a Linkable Model class. Please comment.
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
     1
#!/usr/bin/python2.5
07441582717a Initial thoughts on a Linkable Model class. Please comment.
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
     2
#
07441582717a Initial thoughts on a Linkable Model class. Please comment.
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
     3
# Copyright 2008 the Melange authors.
07441582717a Initial thoughts on a Linkable Model class. Please comment.
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
     4
#
07441582717a Initial thoughts on a Linkable Model class. Please comment.
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
     5
# Licensed under the Apache License, Version 2.0 (the "License");
07441582717a Initial thoughts on a Linkable Model class. Please comment.
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
     6
# you may not use this file except in compliance with the License.
07441582717a Initial thoughts on a Linkable Model class. Please comment.
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
     7
# You may obtain a copy of the License at
07441582717a Initial thoughts on a Linkable Model class. Please comment.
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
     8
# 
07441582717a Initial thoughts on a Linkable Model class. Please comment.
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
     9
#   http://www.apache.org/licenses/LICENSE-2.0
07441582717a Initial thoughts on a Linkable Model class. Please comment.
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    10
# 
07441582717a Initial thoughts on a Linkable Model class. Please comment.
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    11
# Unless required by applicable law or agreed to in writing, software
07441582717a Initial thoughts on a Linkable Model class. Please comment.
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    12
# distributed under the License is distributed on an "AS IS" BASIS,
07441582717a Initial thoughts on a Linkable Model class. Please comment.
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    13
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
07441582717a Initial thoughts on a Linkable Model class. Please comment.
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    14
# See the License for the specific language governing permissions and
07441582717a Initial thoughts on a Linkable Model class. Please comment.
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    15
# limitations under the License.
07441582717a Initial thoughts on a Linkable Model class. Please comment.
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    16
07441582717a Initial thoughts on a Linkable Model class. Please comment.
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    17
"""This module contains the Linkable base class Model."""
07441582717a Initial thoughts on a Linkable Model class. Please comment.
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    18
07441582717a Initial thoughts on a Linkable Model class. Please comment.
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    19
__authors__ = [
07441582717a Initial thoughts on a Linkable Model class. Please comment.
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    20
  '"Todd Larsen" <tlarsen@google.com>',
07441582717a Initial thoughts on a Linkable Model class. Please comment.
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    21
]
07441582717a Initial thoughts on a Linkable Model class. Please comment.
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    22
07441582717a Initial thoughts on a Linkable Model class. Please comment.
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    23
07441582717a Initial thoughts on a Linkable Model class. Please comment.
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    24
from google.appengine.ext import db
07441582717a Initial thoughts on a Linkable Model class. Please comment.
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    25
07441582717a Initial thoughts on a Linkable Model class. Please comment.
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    26
from django.utils.translation import ugettext_lazy
07441582717a Initial thoughts on a Linkable Model class. Please comment.
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    27
07441582717a Initial thoughts on a Linkable Model class. Please comment.
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    28
from soc.models import base
07441582717a Initial thoughts on a Linkable Model class. Please comment.
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    29
07441582717a Initial thoughts on a Linkable Model class. Please comment.
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    30
07441582717a Initial thoughts on a Linkable Model class. Please comment.
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    31
class Linkable(base.ModelWithFieldAttributes):
07441582717a Initial thoughts on a Linkable Model class. Please comment.
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    32
  """A base class for Model classes that are "linkable".
07441582717a Initial thoughts on a Linkable Model class. Please comment.
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    33
  
07441582717a Initial thoughts on a Linkable Model class. Please comment.
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    34
  Many entities in Melange are identified by a "link path" that is formed
07441582717a Initial thoughts on a Linkable Model class. Please comment.
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    35
  by two components:  a "link scope" and a "link ID".
07441582717a Initial thoughts on a Linkable Model class. Please comment.
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    36
  
07441582717a Initial thoughts on a Linkable Model class. Please comment.
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    37
  The link scope is a reference to another Linkable entity, but its exact
07441582717a Initial thoughts on a Linkable Model class. Please comment.
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    38
  usage varies depending on:
07441582717a Initial thoughts on a Linkable Model class. Please comment.
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    39
  
07441582717a Initial thoughts on a Linkable Model class. Please comment.
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    40
   * the Model type of the entity
07441582717a Initial thoughts on a Linkable Model class. Please comment.
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    41
   * the "ownership" of the entity
07441582717a Initial thoughts on a Linkable Model class. Please comment.
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    42
   
07441582717a Initial thoughts on a Linkable Model class. Please comment.
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    43
  This scope represents the "context" of the entity and is *not* user-
07441582717a Initial thoughts on a Linkable Model class. Please comment.
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    44
  editable (site Developers will be able to *carefully* edit the scope
07441582717a Initial thoughts on a Linkable Model class. Please comment.
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    45
  of a Linkable entity, but implementing this will be tricky).
07441582717a Initial thoughts on a Linkable Model class. Please comment.
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    46
  
07441582717a Initial thoughts on a Linkable Model class. Please comment.
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    47
  Appended to this "link path prefix" generated from the transitive
07441582717a Initial thoughts on a Linkable Model class. Please comment.
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    48
  closure of the link scopes is a link ID.  Unlike the rest of the link
07441582717a Initial thoughts on a Linkable Model class. Please comment.
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    49
  path, this ID, which must be unique within the scope defined by the link
07441582717a Initial thoughts on a Linkable Model class. Please comment.
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    50
  path, is *not* determined by context and *is* supplied by the user.
07441582717a Initial thoughts on a Linkable Model class. Please comment.
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    51
  
07441582717a Initial thoughts on a Linkable Model class. Please comment.
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    52
  For example, a Document containing containing the FAQs for the
07441582717a Initial thoughts on a Linkable Model class. Please comment.
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    53
  Apache Software Foundation participation in GSoC 2009 program sponsored
07441582717a Initial thoughts on a Linkable Model class. Please comment.
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    54
  by Google could be given a link ID by the Apache organization
07441582717a Initial thoughts on a Linkable Model class. Please comment.
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    55
  administrator of "faqs", but the rest of the link path would be
07441582717a Initial thoughts on a Linkable Model class. Please comment.
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    56
  determined by the transitive closure of the scopes of the Document:
07441582717a Initial thoughts on a Linkable Model class. Please comment.
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    57
  
07441582717a Initial thoughts on a Linkable Model class. Please comment.
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    58
    google/gsoc2009/asf/faqs
07441582717a Initial thoughts on a Linkable Model class. Please comment.
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    59
      ^       ^      ^   ^
07441582717a Initial thoughts on a Linkable Model class. Please comment.
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    60
      |       |      |   +---------  link ID assigned by Apache admin
07441582717a Initial thoughts on a Linkable Model class. Please comment.
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    61
      |       |      |
07441582717a Initial thoughts on a Linkable Model class. Please comment.
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    62
      |       |      +-------------  Apache org link ID (immutable)
07441582717a Initial thoughts on a Linkable Model class. Please comment.
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    63
      |       |
07441582717a Initial thoughts on a Linkable Model class. Please comment.
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    64
      |       +--------------------  GSoC 2009 program link ID (immutable)
07441582717a Initial thoughts on a Linkable Model class. Please comment.
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    65
      |
07441582717a Initial thoughts on a Linkable Model class. Please comment.
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    66
      +----------------------------  Google sponsor link ID (immutable)
07441582717a Initial thoughts on a Linkable Model class. Please comment.
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    67
      
07441582717a Initial thoughts on a Linkable Model class. Please comment.
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    68
  For many entities, link IDs, once specified, are immutable, since
07441582717a Initial thoughts on a Linkable Model class. Please comment.
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    69
  changing them can break bookmarked URLs.  Changing the link IDs of
07441582717a Initial thoughts on a Linkable Model class. Please comment.
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    70
  "leaf" entities (such as the Document in the example above) could
07441582717a Initial thoughts on a Linkable Model class. Please comment.
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    71
  be allowed. 
07441582717a Initial thoughts on a Linkable Model class. Please comment.
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    72
  """
07441582717a Initial thoughts on a Linkable Model class. Please comment.
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    73
  
07441582717a Initial thoughts on a Linkable Model class. Please comment.
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    74
  id = db.StringProperty(required=True,
07441582717a Initial thoughts on a Linkable Model class. Please comment.
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    75
      verbose_name=ugettext_lazy('Link ID'))
07441582717a Initial thoughts on a Linkable Model class. Please comment.
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    76
  id.help_text = ugettext_lazy(
07441582717a Initial thoughts on a Linkable Model class. Please comment.
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    77
      '"ID" used in URLs.'
07441582717a Initial thoughts on a Linkable Model class. Please comment.
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    78
      ' Lower ASCII characters, digits, and underscores only.')
07441582717a Initial thoughts on a Linkable Model class. Please comment.
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    79
07441582717a Initial thoughts on a Linkable Model class. Please comment.
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    80
  scope = db.SelfReferenceProperty(required=False,
07441582717a Initial thoughts on a Linkable Model class. Please comment.
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    81
      collection_name='links', verbose_name=ugettext_lazy('Link Scope'))
07441582717a Initial thoughts on a Linkable Model class. Please comment.
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    82
  scope.help_text = ugettext_lazy(
07441582717a Initial thoughts on a Linkable Model class. Please comment.
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    83
      'Reference to another Linkable entity that defines the "scope" of'
07441582717a Initial thoughts on a Linkable Model class. Please comment.
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    84
      ' this Linkable entity.')