app/soc/logic/models/host.py
author Sverre Rabbelier <srabbelier@gmail.com>
Thu, 23 Oct 2008 05:21:41 +0000
changeset 410 2af7f84f4fc7
parent 409 9d24850db88f
child 429 e50e18936f06
permissions -rw-r--r--
Moved all key_name related things to the logic modules Patch by: Sverre Rabbelier Reviewed by: to-be-reviewed
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
19
f2a5ec8fb780 Initial definition of the Host Model.
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
     1
#!/usr/bin/python2.5
f2a5ec8fb780 Initial definition of the Host Model.
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
     2
#
f2a5ec8fb780 Initial definition of the Host Model.
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
     3
# Copyright 2008 the Melange authors.
f2a5ec8fb780 Initial definition of the Host Model.
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
     4
#
f2a5ec8fb780 Initial definition of the Host Model.
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
     5
# Licensed under the Apache License, Version 2.0 (the "License");
f2a5ec8fb780 Initial definition of the Host Model.
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
     6
# you may not use this file except in compliance with the License.
f2a5ec8fb780 Initial definition of the Host Model.
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
     7
# You may obtain a copy of the License at
404
44223e50e1fc Added a Host profile and generalized some views
Sverre Rabbelier <srabbelier@gmail.com>
parents: 244
diff changeset
     8
#
19
f2a5ec8fb780 Initial definition of the Host Model.
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
     9
#   http://www.apache.org/licenses/LICENSE-2.0
404
44223e50e1fc Added a Host profile and generalized some views
Sverre Rabbelier <srabbelier@gmail.com>
parents: 244
diff changeset
    10
#
19
f2a5ec8fb780 Initial definition of the Host Model.
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    11
# Unless required by applicable law or agreed to in writing, software
f2a5ec8fb780 Initial definition of the Host Model.
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    12
# distributed under the License is distributed on an "AS IS" BASIS,
f2a5ec8fb780 Initial definition of the Host Model.
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    13
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
f2a5ec8fb780 Initial definition of the Host Model.
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    14
# See the License for the specific language governing permissions and
f2a5ec8fb780 Initial definition of the Host Model.
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    15
# limitations under the License.
f2a5ec8fb780 Initial definition of the Host Model.
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    16
404
44223e50e1fc Added a Host profile and generalized some views
Sverre Rabbelier <srabbelier@gmail.com>
parents: 244
diff changeset
    17
"""Host (Model) query functions.
44223e50e1fc Added a Host profile and generalized some views
Sverre Rabbelier <srabbelier@gmail.com>
parents: 244
diff changeset
    18
"""
19
f2a5ec8fb780 Initial definition of the Host Model.
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    19
f2a5ec8fb780 Initial definition of the Host Model.
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    20
__authors__ = [
404
44223e50e1fc Added a Host profile and generalized some views
Sverre Rabbelier <srabbelier@gmail.com>
parents: 244
diff changeset
    21
  '"Sverre Rabbelier" <sverer@rabbelier.nl>',
44223e50e1fc Added a Host profile and generalized some views
Sverre Rabbelier <srabbelier@gmail.com>
parents: 244
diff changeset
    22
  ]
44223e50e1fc Added a Host profile and generalized some views
Sverre Rabbelier <srabbelier@gmail.com>
parents: 244
diff changeset
    23
44223e50e1fc Added a Host profile and generalized some views
Sverre Rabbelier <srabbelier@gmail.com>
parents: 244
diff changeset
    24
44223e50e1fc Added a Host profile and generalized some views
Sverre Rabbelier <srabbelier@gmail.com>
parents: 244
diff changeset
    25
from soc.logic import key_name
44223e50e1fc Added a Host profile and generalized some views
Sverre Rabbelier <srabbelier@gmail.com>
parents: 244
diff changeset
    26
from soc.logic.models import base
44223e50e1fc Added a Host profile and generalized some views
Sverre Rabbelier <srabbelier@gmail.com>
parents: 244
diff changeset
    27
44223e50e1fc Added a Host profile and generalized some views
Sverre Rabbelier <srabbelier@gmail.com>
parents: 244
diff changeset
    28
import soc.models.host
19
f2a5ec8fb780 Initial definition of the Host Model.
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    29
207
8ecc2e4198cd Take advantage of the Model inheritance provided by polymodel.PolyModel to
Todd Larsen <tlarsen@google.com>
parents: 181
diff changeset
    30
404
44223e50e1fc Added a Host profile and generalized some views
Sverre Rabbelier <srabbelier@gmail.com>
parents: 244
diff changeset
    31
class Logic(base.Logic):
409
9d24850db88f Addressed comments by Pawel and Todd
Sverre Rabbelier <srabbelier@gmail.com>
parents: 404
diff changeset
    32
  """Logic methods for the Host model
404
44223e50e1fc Added a Host profile and generalized some views
Sverre Rabbelier <srabbelier@gmail.com>
parents: 244
diff changeset
    33
  """
19
f2a5ec8fb780 Initial definition of the Host Model.
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    34
404
44223e50e1fc Added a Host profile and generalized some views
Sverre Rabbelier <srabbelier@gmail.com>
parents: 244
diff changeset
    35
  def __init__(self):
44223e50e1fc Added a Host profile and generalized some views
Sverre Rabbelier <srabbelier@gmail.com>
parents: 244
diff changeset
    36
    """Defines the name, key_name and model for this entity.
44223e50e1fc Added a Host profile and generalized some views
Sverre Rabbelier <srabbelier@gmail.com>
parents: 244
diff changeset
    37
    """
44223e50e1fc Added a Host profile and generalized some views
Sverre Rabbelier <srabbelier@gmail.com>
parents: 244
diff changeset
    38
44223e50e1fc Added a Host profile and generalized some views
Sverre Rabbelier <srabbelier@gmail.com>
parents: 244
diff changeset
    39
    self._name = "host"
44223e50e1fc Added a Host profile and generalized some views
Sverre Rabbelier <srabbelier@gmail.com>
parents: 244
diff changeset
    40
    self._model = soc.models.host.Host
44223e50e1fc Added a Host profile and generalized some views
Sverre Rabbelier <srabbelier@gmail.com>
parents: 244
diff changeset
    41
    self._keyName = key_name.nameHost
44223e50e1fc Added a Host profile and generalized some views
Sverre Rabbelier <srabbelier@gmail.com>
parents: 244
diff changeset
    42
    self._skip_properties = []
19
f2a5ec8fb780 Initial definition of the Host Model.
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    43
410
2af7f84f4fc7 Moved all key_name related things to the logic modules
Sverre Rabbelier <srabbelier@gmail.com>
parents: 409
diff changeset
    44
  def getKeyValues(self, entity):
2af7f84f4fc7 Moved all key_name related things to the logic modules
Sverre Rabbelier <srabbelier@gmail.com>
parents: 409
diff changeset
    45
    """See base.Logic.getKeyNameValues.
2af7f84f4fc7 Moved all key_name related things to the logic modules
Sverre Rabbelier <srabbelier@gmail.com>
parents: 409
diff changeset
    46
    """
2af7f84f4fc7 Moved all key_name related things to the logic modules
Sverre Rabbelier <srabbelier@gmail.com>
parents: 409
diff changeset
    47
2af7f84f4fc7 Moved all key_name related things to the logic modules
Sverre Rabbelier <srabbelier@gmail.com>
parents: 409
diff changeset
    48
    return [entity.sponsor.link_name, entity.user.link_name]
2af7f84f4fc7 Moved all key_name related things to the logic modules
Sverre Rabbelier <srabbelier@gmail.com>
parents: 409
diff changeset
    49
2af7f84f4fc7 Moved all key_name related things to the logic modules
Sverre Rabbelier <srabbelier@gmail.com>
parents: 409
diff changeset
    50
  def getKeyValuesFromFields(self, fields):
2af7f84f4fc7 Moved all key_name related things to the logic modules
Sverre Rabbelier <srabbelier@gmail.com>
parents: 409
diff changeset
    51
    """See base.Logic.getKeyValuesFromFields.
2af7f84f4fc7 Moved all key_name related things to the logic modules
Sverre Rabbelier <srabbelier@gmail.com>
parents: 409
diff changeset
    52
    """
2af7f84f4fc7 Moved all key_name related things to the logic modules
Sverre Rabbelier <srabbelier@gmail.com>
parents: 409
diff changeset
    53
2af7f84f4fc7 Moved all key_name related things to the logic modules
Sverre Rabbelier <srabbelier@gmail.com>
parents: 409
diff changeset
    54
    return [fields['sponsor'].link_name, fields['user'].link_name]
2af7f84f4fc7 Moved all key_name related things to the logic modules
Sverre Rabbelier <srabbelier@gmail.com>
parents: 409
diff changeset
    55
2af7f84f4fc7 Moved all key_name related things to the logic modules
Sverre Rabbelier <srabbelier@gmail.com>
parents: 409
diff changeset
    56
  def getKeyFieldNames(self):
2af7f84f4fc7 Moved all key_name related things to the logic modules
Sverre Rabbelier <srabbelier@gmail.com>
parents: 409
diff changeset
    57
    """See base.Logic.getKeyFieldNames
2af7f84f4fc7 Moved all key_name related things to the logic modules
Sverre Rabbelier <srabbelier@gmail.com>
parents: 409
diff changeset
    58
    """
2af7f84f4fc7 Moved all key_name related things to the logic modules
Sverre Rabbelier <srabbelier@gmail.com>
parents: 409
diff changeset
    59
2af7f84f4fc7 Moved all key_name related things to the logic modules
Sverre Rabbelier <srabbelier@gmail.com>
parents: 409
diff changeset
    60
    return ['sponsor_ln', 'user_ln']
19
f2a5ec8fb780 Initial definition of the Host Model.
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    61
404
44223e50e1fc Added a Host profile and generalized some views
Sverre Rabbelier <srabbelier@gmail.com>
parents: 244
diff changeset
    62
logic = Logic()