app/soc/logic/document.py
author Todd Larsen <tlarsen@google.com>
Wed, 01 Oct 2008 20:52:39 +0000
changeset 251 8f23804302d0
parent 248 95e0b84e71c5
child 263 9b39d93b677f
permissions -rw-r--r--
Move path and link_name related functions and regex patterns to a new soc/logic/path_linkname.py module, and fix all dependencies. path/link_name functionality is becoming the generic way to identify entities in the Datastore in a URL-compatible way.
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
141
e120c24b89e2 Added Melange front page edit view where you can change title, content, feed url. Created SiteSettings and Document models and some logic for them. Added isFeedURLValid function in soc/logic/feed.py. Created some functions for handling datastore updates of different kinds of Models (soc/logic/model.py). Fixed some typos and too long lines of code.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
     1
#!/usr/bin/python2.5
e120c24b89e2 Added Melange front page edit view where you can change title, content, feed url. Created SiteSettings and Document models and some logic for them. Added isFeedURLValid function in soc/logic/feed.py. Created some functions for handling datastore updates of different kinds of Models (soc/logic/model.py). Fixed some typos and too long lines of code.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
     2
#
e120c24b89e2 Added Melange front page edit view where you can change title, content, feed url. Created SiteSettings and Document models and some logic for them. Added isFeedURLValid function in soc/logic/feed.py. Created some functions for handling datastore updates of different kinds of Models (soc/logic/model.py). Fixed some typos and too long lines of code.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
     3
# Copyright 2008 the Melange authors.
e120c24b89e2 Added Melange front page edit view where you can change title, content, feed url. Created SiteSettings and Document models and some logic for them. Added isFeedURLValid function in soc/logic/feed.py. Created some functions for handling datastore updates of different kinds of Models (soc/logic/model.py). Fixed some typos and too long lines of code.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
     4
#
e120c24b89e2 Added Melange front page edit view where you can change title, content, feed url. Created SiteSettings and Document models and some logic for them. Added isFeedURLValid function in soc/logic/feed.py. Created some functions for handling datastore updates of different kinds of Models (soc/logic/model.py). Fixed some typos and too long lines of code.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
     5
# Licensed under the Apache License, Version 2.0 (the "License");
e120c24b89e2 Added Melange front page edit view where you can change title, content, feed url. Created SiteSettings and Document models and some logic for them. Added isFeedURLValid function in soc/logic/feed.py. Created some functions for handling datastore updates of different kinds of Models (soc/logic/model.py). Fixed some typos and too long lines of code.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
     6
# you may not use this file except in compliance with the License.
e120c24b89e2 Added Melange front page edit view where you can change title, content, feed url. Created SiteSettings and Document models and some logic for them. Added isFeedURLValid function in soc/logic/feed.py. Created some functions for handling datastore updates of different kinds of Models (soc/logic/model.py). Fixed some typos and too long lines of code.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
     7
# You may obtain a copy of the License at
e120c24b89e2 Added Melange front page edit view where you can change title, content, feed url. Created SiteSettings and Document models and some logic for them. Added isFeedURLValid function in soc/logic/feed.py. Created some functions for handling datastore updates of different kinds of Models (soc/logic/model.py). Fixed some typos and too long lines of code.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
     8
#
e120c24b89e2 Added Melange front page edit view where you can change title, content, feed url. Created SiteSettings and Document models and some logic for them. Added isFeedURLValid function in soc/logic/feed.py. Created some functions for handling datastore updates of different kinds of Models (soc/logic/model.py). Fixed some typos and too long lines of code.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
     9
#   http://www.apache.org/licenses/LICENSE-2.0
e120c24b89e2 Added Melange front page edit view where you can change title, content, feed url. Created SiteSettings and Document models and some logic for them. Added isFeedURLValid function in soc/logic/feed.py. Created some functions for handling datastore updates of different kinds of Models (soc/logic/model.py). Fixed some typos and too long lines of code.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
    10
#
e120c24b89e2 Added Melange front page edit view where you can change title, content, feed url. Created SiteSettings and Document models and some logic for them. Added isFeedURLValid function in soc/logic/feed.py. Created some functions for handling datastore updates of different kinds of Models (soc/logic/model.py). Fixed some typos and too long lines of code.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
    11
# Unless required by applicable law or agreed to in writing, software
e120c24b89e2 Added Melange front page edit view where you can change title, content, feed url. Created SiteSettings and Document models and some logic for them. Added isFeedURLValid function in soc/logic/feed.py. Created some functions for handling datastore updates of different kinds of Models (soc/logic/model.py). Fixed some typos and too long lines of code.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
    12
# distributed under the License is distributed on an "AS IS" BASIS,
e120c24b89e2 Added Melange front page edit view where you can change title, content, feed url. Created SiteSettings and Document models and some logic for them. Added isFeedURLValid function in soc/logic/feed.py. Created some functions for handling datastore updates of different kinds of Models (soc/logic/model.py). Fixed some typos and too long lines of code.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
    13
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
e120c24b89e2 Added Melange front page edit view where you can change title, content, feed url. Created SiteSettings and Document models and some logic for them. Added isFeedURLValid function in soc/logic/feed.py. Created some functions for handling datastore updates of different kinds of Models (soc/logic/model.py). Fixed some typos and too long lines of code.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
    14
# See the License for the specific language governing permissions and
e120c24b89e2 Added Melange front page edit view where you can change title, content, feed url. Created SiteSettings and Document models and some logic for them. Added isFeedURLValid function in soc/logic/feed.py. Created some functions for handling datastore updates of different kinds of Models (soc/logic/model.py). Fixed some typos and too long lines of code.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
    15
# limitations under the License.
e120c24b89e2 Added Melange front page edit view where you can change title, content, feed url. Created SiteSettings and Document models and some logic for them. Added isFeedURLValid function in soc/logic/feed.py. Created some functions for handling datastore updates of different kinds of Models (soc/logic/model.py). Fixed some typos and too long lines of code.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
    16
e120c24b89e2 Added Melange front page edit view where you can change title, content, feed url. Created SiteSettings and Document models and some logic for them. Added isFeedURLValid function in soc/logic/feed.py. Created some functions for handling datastore updates of different kinds of Models (soc/logic/model.py). Fixed some typos and too long lines of code.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
    17
"""Document (Model) query functions.
e120c24b89e2 Added Melange front page edit view where you can change title, content, feed url. Created SiteSettings and Document models and some logic for them. Added isFeedURLValid function in soc/logic/feed.py. Created some functions for handling datastore updates of different kinds of Models (soc/logic/model.py). Fixed some typos and too long lines of code.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
    18
"""
e120c24b89e2 Added Melange front page edit view where you can change title, content, feed url. Created SiteSettings and Document models and some logic for them. Added isFeedURLValid function in soc/logic/feed.py. Created some functions for handling datastore updates of different kinds of Models (soc/logic/model.py). Fixed some typos and too long lines of code.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
    19
e120c24b89e2 Added Melange front page edit view where you can change title, content, feed url. Created SiteSettings and Document models and some logic for them. Added isFeedURLValid function in soc/logic/feed.py. Created some functions for handling datastore updates of different kinds of Models (soc/logic/model.py). Fixed some typos and too long lines of code.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
    20
__authors__ = [
e120c24b89e2 Added Melange front page edit view where you can change title, content, feed url. Created SiteSettings and Document models and some logic for them. Added isFeedURLValid function in soc/logic/feed.py. Created some functions for handling datastore updates of different kinds of Models (soc/logic/model.py). Fixed some typos and too long lines of code.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
    21
  '"Pawel Solyga" <pawel.solyga@gmail.com>',
251
8f23804302d0 Move path and link_name related functions and regex patterns to a new
Todd Larsen <tlarsen@google.com>
parents: 248
diff changeset
    22
  '"Todd Larsen" <tlarsen@google.com>',
141
e120c24b89e2 Added Melange front page edit view where you can change title, content, feed url. Created SiteSettings and Document models and some logic for them. Added isFeedURLValid function in soc/logic/feed.py. Created some functions for handling datastore updates of different kinds of Models (soc/logic/model.py). Fixed some typos and too long lines of code.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
    23
  ]
e120c24b89e2 Added Melange front page edit view where you can change title, content, feed url. Created SiteSettings and Document models and some logic for them. Added isFeedURLValid function in soc/logic/feed.py. Created some functions for handling datastore updates of different kinds of Models (soc/logic/model.py). Fixed some typos and too long lines of code.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
    24
206
832335761384 Make use of PolyModel for Works, Documents, etc. Add some (but not all) of
Todd Larsen <tlarsen@google.com>
parents: 143
diff changeset
    25
225
2590d6b83568 Add functions to soc/logic/document.py for dealing with partial_paths combined
Todd Larsen <tlarsen@google.com>
parents: 206
diff changeset
    26
import re
2590d6b83568 Add functions to soc/logic/document.py for dealing with partial_paths combined
Todd Larsen <tlarsen@google.com>
parents: 206
diff changeset
    27
141
e120c24b89e2 Added Melange front page edit view where you can change title, content, feed url. Created SiteSettings and Document models and some logic for them. Added isFeedURLValid function in soc/logic/feed.py. Created some functions for handling datastore updates of different kinds of Models (soc/logic/model.py). Fixed some typos and too long lines of code.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
    28
from google.appengine.ext import db
e120c24b89e2 Added Melange front page edit view where you can change title, content, feed url. Created SiteSettings and Document models and some logic for them. Added isFeedURLValid function in soc/logic/feed.py. Created some functions for handling datastore updates of different kinds of Models (soc/logic/model.py). Fixed some typos and too long lines of code.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
    29
206
832335761384 Make use of PolyModel for Works, Documents, etc. Add some (but not all) of
Todd Larsen <tlarsen@google.com>
parents: 143
diff changeset
    30
from soc.logic import key_name
225
2590d6b83568 Add functions to soc/logic/document.py for dealing with partial_paths combined
Todd Larsen <tlarsen@google.com>
parents: 206
diff changeset
    31
from soc.logic import out_of_band
2590d6b83568 Add functions to soc/logic/document.py for dealing with partial_paths combined
Todd Larsen <tlarsen@google.com>
parents: 206
diff changeset
    32
from soc.logic.site import id_user
2590d6b83568 Add functions to soc/logic/document.py for dealing with partial_paths combined
Todd Larsen <tlarsen@google.com>
parents: 206
diff changeset
    33
2590d6b83568 Add functions to soc/logic/document.py for dealing with partial_paths combined
Todd Larsen <tlarsen@google.com>
parents: 206
diff changeset
    34
import soc.logic.model
206
832335761384 Make use of PolyModel for Works, Documents, etc. Add some (but not all) of
Todd Larsen <tlarsen@google.com>
parents: 143
diff changeset
    35
141
e120c24b89e2 Added Melange front page edit view where you can change title, content, feed url. Created SiteSettings and Document models and some logic for them. Added isFeedURLValid function in soc/logic/feed.py. Created some functions for handling datastore updates of different kinds of Models (soc/logic/model.py). Fixed some typos and too long lines of code.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
    36
import soc.models.document
225
2590d6b83568 Add functions to soc/logic/document.py for dealing with partial_paths combined
Todd Larsen <tlarsen@google.com>
parents: 206
diff changeset
    37
import soc.models.work
2590d6b83568 Add functions to soc/logic/document.py for dealing with partial_paths combined
Todd Larsen <tlarsen@google.com>
parents: 206
diff changeset
    38
248
95e0b84e71c5 Add missing blank line to follow PythonStyleGuide in document.py
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 225
diff changeset
    39
225
2590d6b83568 Add functions to soc/logic/document.py for dealing with partial_paths combined
Todd Larsen <tlarsen@google.com>
parents: 206
diff changeset
    40
def getDocument(path, link_name=None):
141
e120c24b89e2 Added Melange front page edit view where you can change title, content, feed url. Created SiteSettings and Document models and some logic for them. Added isFeedURLValid function in soc/logic/feed.py. Created some functions for handling datastore updates of different kinds of Models (soc/logic/model.py). Fixed some typos and too long lines of code.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
    41
  """Returns Document entity for a given path, or None if not found.  
e120c24b89e2 Added Melange front page edit view where you can change title, content, feed url. Created SiteSettings and Document models and some logic for them. Added isFeedURLValid function in soc/logic/feed.py. Created some functions for handling datastore updates of different kinds of Models (soc/logic/model.py). Fixed some typos and too long lines of code.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
    42
    
e120c24b89e2 Added Melange front page edit view where you can change title, content, feed url. Created SiteSettings and Document models and some logic for them. Added isFeedURLValid function in soc/logic/feed.py. Created some functions for handling datastore updates of different kinds of Models (soc/logic/model.py). Fixed some typos and too long lines of code.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
    43
  Args:
143
b419121f7b3e FIxed documentation in soc/logic/document.py for getDocumentFromPath function
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 141
diff changeset
    44
    path: a request path of the Document that uniquely identifies it
225
2590d6b83568 Add functions to soc/logic/document.py for dealing with partial_paths combined
Todd Larsen <tlarsen@google.com>
parents: 206
diff changeset
    45
    link_name: optional link name to append to path (when supplied,
2590d6b83568 Add functions to soc/logic/document.py for dealing with partial_paths combined
Todd Larsen <tlarsen@google.com>
parents: 206
diff changeset
    46
      path is actually a "partial path" that needs to link name appended
2590d6b83568 Add functions to soc/logic/document.py for dealing with partial_paths combined
Todd Larsen <tlarsen@google.com>
parents: 206
diff changeset
    47
      to it)
141
e120c24b89e2 Added Melange front page edit view where you can change title, content, feed url. Created SiteSettings and Document models and some logic for them. Added isFeedURLValid function in soc/logic/feed.py. Created some functions for handling datastore updates of different kinds of Models (soc/logic/model.py). Fixed some typos and too long lines of code.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
    48
  """
e120c24b89e2 Added Melange front page edit view where you can change title, content, feed url. Created SiteSettings and Document models and some logic for them. Added isFeedURLValid function in soc/logic/feed.py. Created some functions for handling datastore updates of different kinds of Models (soc/logic/model.py). Fixed some typos and too long lines of code.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
    49
  # lookup by Doc:path key name
225
2590d6b83568 Add functions to soc/logic/document.py for dealing with partial_paths combined
Todd Larsen <tlarsen@google.com>
parents: 206
diff changeset
    50
  name = key_name.nameDocument(path, link_name=link_name)
141
e120c24b89e2 Added Melange front page edit view where you can change title, content, feed url. Created SiteSettings and Document models and some logic for them. Added isFeedURLValid function in soc/logic/feed.py. Created some functions for handling datastore updates of different kinds of Models (soc/logic/model.py). Fixed some typos and too long lines of code.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
    51
  
206
832335761384 Make use of PolyModel for Works, Documents, etc. Add some (but not all) of
Todd Larsen <tlarsen@google.com>
parents: 143
diff changeset
    52
  if name:
832335761384 Make use of PolyModel for Works, Documents, etc. Add some (but not all) of
Todd Larsen <tlarsen@google.com>
parents: 143
diff changeset
    53
    document = soc.models.document.Document.get_by_key_name(name)
141
e120c24b89e2 Added Melange front page edit view where you can change title, content, feed url. Created SiteSettings and Document models and some logic for them. Added isFeedURLValid function in soc/logic/feed.py. Created some functions for handling datastore updates of different kinds of Models (soc/logic/model.py). Fixed some typos and too long lines of code.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
    54
  else:
e120c24b89e2 Added Melange front page edit view where you can change title, content, feed url. Created SiteSettings and Document models and some logic for them. Added isFeedURLValid function in soc/logic/feed.py. Created some functions for handling datastore updates of different kinds of Models (soc/logic/model.py). Fixed some typos and too long lines of code.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
    55
    document = None
e120c24b89e2 Added Melange front page edit view where you can change title, content, feed url. Created SiteSettings and Document models and some logic for them. Added isFeedURLValid function in soc/logic/feed.py. Created some functions for handling datastore updates of different kinds of Models (soc/logic/model.py). Fixed some typos and too long lines of code.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
    56
  
e120c24b89e2 Added Melange front page edit view where you can change title, content, feed url. Created SiteSettings and Document models and some logic for them. Added isFeedURLValid function in soc/logic/feed.py. Created some functions for handling datastore updates of different kinds of Models (soc/logic/model.py). Fixed some typos and too long lines of code.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
    57
  return document
e120c24b89e2 Added Melange front page edit view where you can change title, content, feed url. Created SiteSettings and Document models and some logic for them. Added isFeedURLValid function in soc/logic/feed.py. Created some functions for handling datastore updates of different kinds of Models (soc/logic/model.py). Fixed some typos and too long lines of code.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
    58
e120c24b89e2 Added Melange front page edit view where you can change title, content, feed url. Created SiteSettings and Document models and some logic for them. Added isFeedURLValid function in soc/logic/feed.py. Created some functions for handling datastore updates of different kinds of Models (soc/logic/model.py). Fixed some typos and too long lines of code.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
    59
225
2590d6b83568 Add functions to soc/logic/document.py for dealing with partial_paths combined
Todd Larsen <tlarsen@google.com>
parents: 206
diff changeset
    60
def getDocumentIfPath(path, link_name=None):
2590d6b83568 Add functions to soc/logic/document.py for dealing with partial_paths combined
Todd Larsen <tlarsen@google.com>
parents: 206
diff changeset
    61
  """Returns Document entity for supplied path if one exists.
2590d6b83568 Add functions to soc/logic/document.py for dealing with partial_paths combined
Todd Larsen <tlarsen@google.com>
parents: 206
diff changeset
    62
  
2590d6b83568 Add functions to soc/logic/document.py for dealing with partial_paths combined
Todd Larsen <tlarsen@google.com>
parents: 206
diff changeset
    63
  Args:
2590d6b83568 Add functions to soc/logic/document.py for dealing with partial_paths combined
Todd Larsen <tlarsen@google.com>
parents: 206
diff changeset
    64
    path: path used in URLs to identify document
2590d6b83568 Add functions to soc/logic/document.py for dealing with partial_paths combined
Todd Larsen <tlarsen@google.com>
parents: 206
diff changeset
    65
2590d6b83568 Add functions to soc/logic/document.py for dealing with partial_paths combined
Todd Larsen <tlarsen@google.com>
parents: 206
diff changeset
    66
  Returns:
2590d6b83568 Add functions to soc/logic/document.py for dealing with partial_paths combined
Todd Larsen <tlarsen@google.com>
parents: 206
diff changeset
    67
    * None if path is false.
2590d6b83568 Add functions to soc/logic/document.py for dealing with partial_paths combined
Todd Larsen <tlarsen@google.com>
parents: 206
diff changeset
    68
    * Document entity that has supplied path
2590d6b83568 Add functions to soc/logic/document.py for dealing with partial_paths combined
Todd Larsen <tlarsen@google.com>
parents: 206
diff changeset
    69
2590d6b83568 Add functions to soc/logic/document.py for dealing with partial_paths combined
Todd Larsen <tlarsen@google.com>
parents: 206
diff changeset
    70
  Raises:
2590d6b83568 Add functions to soc/logic/document.py for dealing with partial_paths combined
Todd Larsen <tlarsen@google.com>
parents: 206
diff changeset
    71
    out_of_band.ErrorResponse if path is not false, but no Document entity
2590d6b83568 Add functions to soc/logic/document.py for dealing with partial_paths combined
Todd Larsen <tlarsen@google.com>
parents: 206
diff changeset
    72
    with the supplied path exists in the Datastore
2590d6b83568 Add functions to soc/logic/document.py for dealing with partial_paths combined
Todd Larsen <tlarsen@google.com>
parents: 206
diff changeset
    73
  """
2590d6b83568 Add functions to soc/logic/document.py for dealing with partial_paths combined
Todd Larsen <tlarsen@google.com>
parents: 206
diff changeset
    74
  if not path:
2590d6b83568 Add functions to soc/logic/document.py for dealing with partial_paths combined
Todd Larsen <tlarsen@google.com>
parents: 206
diff changeset
    75
    # exit without error, to let view know that link_name was not supplied
2590d6b83568 Add functions to soc/logic/document.py for dealing with partial_paths combined
Todd Larsen <tlarsen@google.com>
parents: 206
diff changeset
    76
    return None
2590d6b83568 Add functions to soc/logic/document.py for dealing with partial_paths combined
Todd Larsen <tlarsen@google.com>
parents: 206
diff changeset
    77
2590d6b83568 Add functions to soc/logic/document.py for dealing with partial_paths combined
Todd Larsen <tlarsen@google.com>
parents: 206
diff changeset
    78
  path_doc = getDocument(path, link_name=link_name)
2590d6b83568 Add functions to soc/logic/document.py for dealing with partial_paths combined
Todd Larsen <tlarsen@google.com>
parents: 206
diff changeset
    79
    
2590d6b83568 Add functions to soc/logic/document.py for dealing with partial_paths combined
Todd Larsen <tlarsen@google.com>
parents: 206
diff changeset
    80
  if path_doc:
2590d6b83568 Add functions to soc/logic/document.py for dealing with partial_paths combined
Todd Larsen <tlarsen@google.com>
parents: 206
diff changeset
    81
    # a Document has this path, so return that corresponding Document entity
2590d6b83568 Add functions to soc/logic/document.py for dealing with partial_paths combined
Todd Larsen <tlarsen@google.com>
parents: 206
diff changeset
    82
    return path_doc
2590d6b83568 Add functions to soc/logic/document.py for dealing with partial_paths combined
Todd Larsen <tlarsen@google.com>
parents: 206
diff changeset
    83
2590d6b83568 Add functions to soc/logic/document.py for dealing with partial_paths combined
Todd Larsen <tlarsen@google.com>
parents: 206
diff changeset
    84
  # else: a path was supplied, but there is no Document that has it
2590d6b83568 Add functions to soc/logic/document.py for dealing with partial_paths combined
Todd Larsen <tlarsen@google.com>
parents: 206
diff changeset
    85
  raise out_of_band.ErrorResponse(
2590d6b83568 Add functions to soc/logic/document.py for dealing with partial_paths combined
Todd Larsen <tlarsen@google.com>
parents: 206
diff changeset
    86
      'There is no document with a "path" of "%s".' % path, status=404)
2590d6b83568 Add functions to soc/logic/document.py for dealing with partial_paths combined
Todd Larsen <tlarsen@google.com>
parents: 206
diff changeset
    87
2590d6b83568 Add functions to soc/logic/document.py for dealing with partial_paths combined
Todd Larsen <tlarsen@google.com>
parents: 206
diff changeset
    88
2590d6b83568 Add functions to soc/logic/document.py for dealing with partial_paths combined
Todd Larsen <tlarsen@google.com>
parents: 206
diff changeset
    89
def updateOrCreateDocument(**document_properties):
141
e120c24b89e2 Added Melange front page edit view where you can change title, content, feed url. Created SiteSettings and Document models and some logic for them. Added isFeedURLValid function in soc/logic/feed.py. Created some functions for handling datastore updates of different kinds of Models (soc/logic/model.py). Fixed some typos and too long lines of code.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
    90
  """Update existing Document entity, or create new one with supplied properties.
e120c24b89e2 Added Melange front page edit view where you can change title, content, feed url. Created SiteSettings and Document models and some logic for them. Added isFeedURLValid function in soc/logic/feed.py. Created some functions for handling datastore updates of different kinds of Models (soc/logic/model.py). Fixed some typos and too long lines of code.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
    91
e120c24b89e2 Added Melange front page edit view where you can change title, content, feed url. Created SiteSettings and Document models and some logic for them. Added isFeedURLValid function in soc/logic/feed.py. Created some functions for handling datastore updates of different kinds of Models (soc/logic/model.py). Fixed some typos and too long lines of code.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
    92
  Args:
e120c24b89e2 Added Melange front page edit view where you can change title, content, feed url. Created SiteSettings and Document models and some logic for them. Added isFeedURLValid function in soc/logic/feed.py. Created some functions for handling datastore updates of different kinds of Models (soc/logic/model.py). Fixed some typos and too long lines of code.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
    93
    path: a request path of the Document that uniquely identifies it
e120c24b89e2 Added Melange front page edit view where you can change title, content, feed url. Created SiteSettings and Document models and some logic for them. Added isFeedURLValid function in soc/logic/feed.py. Created some functions for handling datastore updates of different kinds of Models (soc/logic/model.py). Fixed some typos and too long lines of code.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
    94
    **document_properties: keyword arguments that correspond to Document entity
e120c24b89e2 Added Melange front page edit view where you can change title, content, feed url. Created SiteSettings and Document models and some logic for them. Added isFeedURLValid function in soc/logic/feed.py. Created some functions for handling datastore updates of different kinds of Models (soc/logic/model.py). Fixed some typos and too long lines of code.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
    95
      properties and their values
e120c24b89e2 Added Melange front page edit view where you can change title, content, feed url. Created SiteSettings and Document models and some logic for them. Added isFeedURLValid function in soc/logic/feed.py. Created some functions for handling datastore updates of different kinds of Models (soc/logic/model.py). Fixed some typos and too long lines of code.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
    96
e120c24b89e2 Added Melange front page edit view where you can change title, content, feed url. Created SiteSettings and Document models and some logic for them. Added isFeedURLValid function in soc/logic/feed.py. Created some functions for handling datastore updates of different kinds of Models (soc/logic/model.py). Fixed some typos and too long lines of code.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
    97
  Returns:
e120c24b89e2 Added Melange front page edit view where you can change title, content, feed url. Created SiteSettings and Document models and some logic for them. Added isFeedURLValid function in soc/logic/feed.py. Created some functions for handling datastore updates of different kinds of Models (soc/logic/model.py). Fixed some typos and too long lines of code.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
    98
    the Document entity corresponding to the path, with any supplied
e120c24b89e2 Added Melange front page edit view where you can change title, content, feed url. Created SiteSettings and Document models and some logic for them. Added isFeedURLValid function in soc/logic/feed.py. Created some functions for handling datastore updates of different kinds of Models (soc/logic/model.py). Fixed some typos and too long lines of code.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
    99
    properties changed, or a new Document entity now associated with the 
e120c24b89e2 Added Melange front page edit view where you can change title, content, feed url. Created SiteSettings and Document models and some logic for them. Added isFeedURLValid function in soc/logic/feed.py. Created some functions for handling datastore updates of different kinds of Models (soc/logic/model.py). Fixed some typos and too long lines of code.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
   100
    supplied path and properties.
e120c24b89e2 Added Melange front page edit view where you can change title, content, feed url. Created SiteSettings and Document models and some logic for them. Added isFeedURLValid function in soc/logic/feed.py. Created some functions for handling datastore updates of different kinds of Models (soc/logic/model.py). Fixed some typos and too long lines of code.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
   101
  """
e120c24b89e2 Added Melange front page edit view where you can change title, content, feed url. Created SiteSettings and Document models and some logic for them. Added isFeedURLValid function in soc/logic/feed.py. Created some functions for handling datastore updates of different kinds of Models (soc/logic/model.py). Fixed some typos and too long lines of code.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
   102
  # attempt to retrieve the existing Document
225
2590d6b83568 Add functions to soc/logic/document.py for dealing with partial_paths combined
Todd Larsen <tlarsen@google.com>
parents: 206
diff changeset
   103
  document = getDocument(document_properties['partial_path'],
2590d6b83568 Add functions to soc/logic/document.py for dealing with partial_paths combined
Todd Larsen <tlarsen@google.com>
parents: 206
diff changeset
   104
                         link_name=document_properties['link_name'])
141
e120c24b89e2 Added Melange front page edit view where you can change title, content, feed url. Created SiteSettings and Document models and some logic for them. Added isFeedURLValid function in soc/logic/feed.py. Created some functions for handling datastore updates of different kinds of Models (soc/logic/model.py). Fixed some typos and too long lines of code.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
   105
e120c24b89e2 Added Melange front page edit view where you can change title, content, feed url. Created SiteSettings and Document models and some logic for them. Added isFeedURLValid function in soc/logic/feed.py. Created some functions for handling datastore updates of different kinds of Models (soc/logic/model.py). Fixed some typos and too long lines of code.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
   106
  if not document:
e120c24b89e2 Added Melange front page edit view where you can change title, content, feed url. Created SiteSettings and Document models and some logic for them. Added isFeedURLValid function in soc/logic/feed.py. Created some functions for handling datastore updates of different kinds of Models (soc/logic/model.py). Fixed some typos and too long lines of code.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
   107
    # document did not exist, so create one in a transaction
225
2590d6b83568 Add functions to soc/logic/document.py for dealing with partial_paths combined
Todd Larsen <tlarsen@google.com>
parents: 206
diff changeset
   108
    name = key_name.nameDocument(document_properties['partial_path'],
2590d6b83568 Add functions to soc/logic/document.py for dealing with partial_paths combined
Todd Larsen <tlarsen@google.com>
parents: 206
diff changeset
   109
                                 document_properties['link_name'])
141
e120c24b89e2 Added Melange front page edit view where you can change title, content, feed url. Created SiteSettings and Document models and some logic for them. Added isFeedURLValid function in soc/logic/feed.py. Created some functions for handling datastore updates of different kinds of Models (soc/logic/model.py). Fixed some typos and too long lines of code.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
   110
    document = soc.models.document.Document.get_or_insert(
206
832335761384 Make use of PolyModel for Works, Documents, etc. Add some (but not all) of
Todd Larsen <tlarsen@google.com>
parents: 143
diff changeset
   111
        name, **document_properties)
141
e120c24b89e2 Added Melange front page edit view where you can change title, content, feed url. Created SiteSettings and Document models and some logic for them. Added isFeedURLValid function in soc/logic/feed.py. Created some functions for handling datastore updates of different kinds of Models (soc/logic/model.py). Fixed some typos and too long lines of code.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
   112
e120c24b89e2 Added Melange front page edit view where you can change title, content, feed url. Created SiteSettings and Document models and some logic for them. Added isFeedURLValid function in soc/logic/feed.py. Created some functions for handling datastore updates of different kinds of Models (soc/logic/model.py). Fixed some typos and too long lines of code.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
   113
  # there is no way to be sure if get_or_insert() returned a new Document or
e120c24b89e2 Added Melange front page edit view where you can change title, content, feed url. Created SiteSettings and Document models and some logic for them. Added isFeedURLValid function in soc/logic/feed.py. Created some functions for handling datastore updates of different kinds of Models (soc/logic/model.py). Fixed some typos and too long lines of code.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
   114
  # got an existing one due to a race, so update with document_properties anyway,
e120c24b89e2 Added Melange front page edit view where you can change title, content, feed url. Created SiteSettings and Document models and some logic for them. Added isFeedURLValid function in soc/logic/feed.py. Created some functions for handling datastore updates of different kinds of Models (soc/logic/model.py). Fixed some typos and too long lines of code.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
   115
  # in a transaction
e120c24b89e2 Added Melange front page edit view where you can change title, content, feed url. Created SiteSettings and Document models and some logic for them. Added isFeedURLValid function in soc/logic/feed.py. Created some functions for handling datastore updates of different kinds of Models (soc/logic/model.py). Fixed some typos and too long lines of code.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
   116
  return soc.logic.model.updateModelProperties(document, **document_properties)
e120c24b89e2 Added Melange front page edit view where you can change title, content, feed url. Created SiteSettings and Document models and some logic for them. Added isFeedURLValid function in soc/logic/feed.py. Created some functions for handling datastore updates of different kinds of Models (soc/logic/model.py). Fixed some typos and too long lines of code.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
   117
e120c24b89e2 Added Melange front page edit view where you can change title, content, feed url. Created SiteSettings and Document models and some logic for them. Added isFeedURLValid function in soc/logic/feed.py. Created some functions for handling datastore updates of different kinds of Models (soc/logic/model.py). Fixed some typos and too long lines of code.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
   118
225
2590d6b83568 Add functions to soc/logic/document.py for dealing with partial_paths combined
Todd Larsen <tlarsen@google.com>
parents: 206
diff changeset
   119
def getWorksForOffsetAndLimit(offset=0, limit=0, cls=soc.models.work.Work):
2590d6b83568 Add functions to soc/logic/document.py for dealing with partial_paths combined
Todd Larsen <tlarsen@google.com>
parents: 206
diff changeset
   120
  """Returns Works for given offset and limit or None if not found.
2590d6b83568 Add functions to soc/logic/document.py for dealing with partial_paths combined
Todd Larsen <tlarsen@google.com>
parents: 206
diff changeset
   121
    
2590d6b83568 Add functions to soc/logic/document.py for dealing with partial_paths combined
Todd Larsen <tlarsen@google.com>
parents: 206
diff changeset
   122
  Args:
2590d6b83568 Add functions to soc/logic/document.py for dealing with partial_paths combined
Todd Larsen <tlarsen@google.com>
parents: 206
diff changeset
   123
    offset: offset in entities list which defines first entity to return
2590d6b83568 Add functions to soc/logic/document.py for dealing with partial_paths combined
Todd Larsen <tlarsen@google.com>
parents: 206
diff changeset
   124
    limit: max amount of entities to return
2590d6b83568 Add functions to soc/logic/document.py for dealing with partial_paths combined
Todd Larsen <tlarsen@google.com>
parents: 206
diff changeset
   125
    cls: Model class of items to return (including sub-classes of that type);
2590d6b83568 Add functions to soc/logic/document.py for dealing with partial_paths combined
Todd Larsen <tlarsen@google.com>
parents: 206
diff changeset
   126
      default is Work
2590d6b83568 Add functions to soc/logic/document.py for dealing with partial_paths combined
Todd Larsen <tlarsen@google.com>
parents: 206
diff changeset
   127
  """
2590d6b83568 Add functions to soc/logic/document.py for dealing with partial_paths combined
Todd Larsen <tlarsen@google.com>
parents: 206
diff changeset
   128
  query = db.GqlQuery(
2590d6b83568 Add functions to soc/logic/document.py for dealing with partial_paths combined
Todd Larsen <tlarsen@google.com>
parents: 206
diff changeset
   129
      'SELECT * FROM Work WHERE inheritance_line = :1 ORDER BY title',
2590d6b83568 Add functions to soc/logic/document.py for dealing with partial_paths combined
Todd Larsen <tlarsen@google.com>
parents: 206
diff changeset
   130
      key_name.getFullClassName(cls))
141
e120c24b89e2 Added Melange front page edit view where you can change title, content, feed url. Created SiteSettings and Document models and some logic for them. Added isFeedURLValid function in soc/logic/feed.py. Created some functions for handling datastore updates of different kinds of Models (soc/logic/model.py). Fixed some typos and too long lines of code.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
   131
225
2590d6b83568 Add functions to soc/logic/document.py for dealing with partial_paths combined
Todd Larsen <tlarsen@google.com>
parents: 206
diff changeset
   132
  # Fetch one more to see if there should be a 'next' link
2590d6b83568 Add functions to soc/logic/document.py for dealing with partial_paths combined
Todd Larsen <tlarsen@google.com>
parents: 206
diff changeset
   133
  return query.fetch(limit+1, offset)