app/soc/logic/models/review.py
author Lennard de Rijk <ljvderijk@gmail.com>
Fri, 14 Aug 2009 10:21:09 -0700
changeset 2774 14b51b124ccb
parent 1757 0f909179ccf2
permissions -rw-r--r--
Fixed call to get QueryForFields due to changes in r0548101922. The order argument was given as ancestor instead of order.
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
1710
9003103d01a1 Added Logic for the Review Model.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
     1
#!/usr/bin/python2.5
9003103d01a1 Added Logic for the Review Model.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
     2
#
9003103d01a1 Added Logic for the Review Model.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
     3
# Copyright 2008 the Melange authors.
9003103d01a1 Added Logic for the Review Model.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
     4
#
9003103d01a1 Added Logic for the Review Model.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
     5
# Licensed under the Apache License, Version 2.0 (the "License");
9003103d01a1 Added Logic for the Review Model.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
     6
# you may not use this file except in compliance with the License.
9003103d01a1 Added Logic for the Review Model.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
     7
# You may obtain a copy of the License at
9003103d01a1 Added Logic for the Review Model.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
     8
#
9003103d01a1 Added Logic for the Review Model.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
     9
#   http://www.apache.org/licenses/LICENSE-2.0
9003103d01a1 Added Logic for the Review Model.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    10
#
9003103d01a1 Added Logic for the Review Model.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    11
# Unless required by applicable law or agreed to in writing, software
9003103d01a1 Added Logic for the Review Model.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    12
# distributed under the License is distributed on an "AS IS" BASIS,
9003103d01a1 Added Logic for the Review Model.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    13
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
9003103d01a1 Added Logic for the Review Model.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    14
# See the License for the specific language governing permissions and
9003103d01a1 Added Logic for the Review Model.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    15
# limitations under the License.
9003103d01a1 Added Logic for the Review Model.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    16
9003103d01a1 Added Logic for the Review Model.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    17
"""Review (Model) query functions.
9003103d01a1 Added Logic for the Review Model.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    18
"""
9003103d01a1 Added Logic for the Review Model.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    19
9003103d01a1 Added Logic for the Review Model.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    20
__authors__ = [
9003103d01a1 Added Logic for the Review Model.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    21
  '"Lennard de Rijk" <ljvderijk@gmail.com>',
9003103d01a1 Added Logic for the Review Model.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    22
  ]
9003103d01a1 Added Logic for the Review Model.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    23
9003103d01a1 Added Logic for the Review Model.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    24
9003103d01a1 Added Logic for the Review Model.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    25
from soc.logic.models import base
9003103d01a1 Added Logic for the Review Model.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    26
from soc.logic.models import linkable as linkable_logic
9003103d01a1 Added Logic for the Review Model.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    27
9003103d01a1 Added Logic for the Review Model.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    28
import soc.models.comment
9003103d01a1 Added Logic for the Review Model.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    29
import soc.models.review
9003103d01a1 Added Logic for the Review Model.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    30
9003103d01a1 Added Logic for the Review Model.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    31
9003103d01a1 Added Logic for the Review Model.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    32
class Logic(base.Logic):
1757
0f909179ccf2 Some minor style fixes.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1740
diff changeset
    33
  """Logic methods for the review model.
1710
9003103d01a1 Added Logic for the Review Model.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    34
  """
9003103d01a1 Added Logic for the Review Model.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    35
9003103d01a1 Added Logic for the Review Model.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    36
  def __init__(self, model=soc.models.review.Review,
9003103d01a1 Added Logic for the Review Model.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    37
               base_model=soc.models.comment.Comment,
9003103d01a1 Added Logic for the Review Model.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    38
               scope_logic=linkable_logic):
9003103d01a1 Added Logic for the Review Model.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    39
    """Defines the name, key_name and model for this entity.
9003103d01a1 Added Logic for the Review Model.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    40
    """
9003103d01a1 Added Logic for the Review Model.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    41
9003103d01a1 Added Logic for the Review Model.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    42
    super(Logic, self).__init__(model=model, base_model=base_model,
9003103d01a1 Added Logic for the Review Model.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    43
                                scope_logic=scope_logic)
9003103d01a1 Added Logic for the Review Model.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    44
1740
fbc2ad561c4b Added a new method in the review logic to return all reviews for the given entity as scope.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1710
diff changeset
    45
  def getReviewsForEntity(self, entity, is_public, order=None):
fbc2ad561c4b Added a new method in the review logic to return all reviews for the given entity as scope.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1710
diff changeset
    46
    """Returns the reviews that have the given entity as scope.
fbc2ad561c4b Added a new method in the review logic to return all reviews for the given entity as scope.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1710
diff changeset
    47
    
fbc2ad561c4b Added a new method in the review logic to return all reviews for the given entity as scope.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1710
diff changeset
    48
    Args:
fbc2ad561c4b Added a new method in the review logic to return all reviews for the given entity as scope.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1710
diff changeset
    49
      entity: the entity which is the scope of the review
fbc2ad561c4b Added a new method in the review logic to return all reviews for the given entity as scope.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1710
diff changeset
    50
      is_public: determines if the public or non-public reviews are returned
fbc2ad561c4b Added a new method in the review logic to return all reviews for the given entity as scope.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1710
diff changeset
    51
      order: the optional ordering in which the reviews are returned
fbc2ad561c4b Added a new method in the review logic to return all reviews for the given entity as scope.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1710
diff changeset
    52
    """
fbc2ad561c4b Added a new method in the review logic to return all reviews for the given entity as scope.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1710
diff changeset
    53
fbc2ad561c4b Added a new method in the review logic to return all reviews for the given entity as scope.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1710
diff changeset
    54
    fields = {'scope': entity,
fbc2ad561c4b Added a new method in the review logic to return all reviews for the given entity as scope.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1710
diff changeset
    55
              'is_public': is_public}
fbc2ad561c4b Added a new method in the review logic to return all reviews for the given entity as scope.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1710
diff changeset
    56
2774
14b51b124ccb Fixed call to get QueryForFields due to changes in r0548101922.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1757
diff changeset
    57
    query = self.getQueryForFields(fields, order=order)
1740
fbc2ad561c4b Added a new method in the review logic to return all reviews for the given entity as scope.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1710
diff changeset
    58
fbc2ad561c4b Added a new method in the review logic to return all reviews for the given entity as scope.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1710
diff changeset
    59
    return self.getAll(query)
fbc2ad561c4b Added a new method in the review logic to return all reviews for the given entity as scope.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1710
diff changeset
    60
1710
9003103d01a1 Added Logic for the Review Model.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    61
logic = Logic()