app/soc/logic/models/host.py
author Todd Larsen <tlarsen@google.com>
Thu, 20 Nov 2008 18:50:30 +0000
changeset 512 aae25d2b4464
parent 499 d22e4fe8e64b
child 530 8d5adb2b8d48
permissions -rw-r--r--
Rename link_name to link_id everywhere, regardless of case (so LINK_NAME becomes LINK_ID, "link name" becomes "link id", etc.). Also, rename LINKNAME to LINK_ID. Patch by: Todd Larsen
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__ = [
429
e50e18936f06 Fixed typo in e-mail address
Sverre Rabbelier <srabbelier@gmail.com>
parents: 410
diff changeset
    21
  '"Sverre Rabbelier" <sverre@rabbelier.nl>',
404
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
481
94834a1e6c01 Attempt to rename User.id to User.account, in preparation for making User be
Todd Larsen <tlarsen@google.com>
parents: 444
diff changeset
    29
import soc.models.role
19
f2a5ec8fb780 Initial definition of the Host Model.
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    30
207
8ecc2e4198cd Take advantage of the Model inheritance provided by polymodel.PolyModel to
Todd Larsen <tlarsen@google.com>
parents: 181
diff changeset
    31
404
44223e50e1fc Added a Host profile and generalized some views
Sverre Rabbelier <srabbelier@gmail.com>
parents: 244
diff changeset
    32
class Logic(base.Logic):
499
d22e4fe8e64b Fix missing dots in doc strings and some other doc string corrections.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 481
diff changeset
    33
  """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
    34
  """
19
f2a5ec8fb780 Initial definition of the Host Model.
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    35
404
44223e50e1fc Added a Host profile and generalized some views
Sverre Rabbelier <srabbelier@gmail.com>
parents: 244
diff changeset
    36
  def __init__(self):
44223e50e1fc Added a Host profile and generalized some views
Sverre Rabbelier <srabbelier@gmail.com>
parents: 244
diff changeset
    37
    """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
    38
    """
481
94834a1e6c01 Attempt to rename User.id to User.account, in preparation for making User be
Todd Larsen <tlarsen@google.com>
parents: 444
diff changeset
    39
    base.Logic.__init__(self, soc.models.host.Host,
94834a1e6c01 Attempt to rename User.id to User.account, in preparation for making User be
Todd Larsen <tlarsen@google.com>
parents: 444
diff changeset
    40
                        base_model=soc.models.role.Role)
19
f2a5ec8fb780 Initial definition of the Host Model.
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    41
410
2af7f84f4fc7 Moved all key_name related things to the logic modules
Sverre Rabbelier <srabbelier@gmail.com>
parents: 409
diff changeset
    42
  def getKeyValues(self, entity):
2af7f84f4fc7 Moved all key_name related things to the logic modules
Sverre Rabbelier <srabbelier@gmail.com>
parents: 409
diff changeset
    43
    """See base.Logic.getKeyNameValues.
2af7f84f4fc7 Moved all key_name related things to the logic modules
Sverre Rabbelier <srabbelier@gmail.com>
parents: 409
diff changeset
    44
    """
2af7f84f4fc7 Moved all key_name related things to the logic modules
Sverre Rabbelier <srabbelier@gmail.com>
parents: 409
diff changeset
    45
512
aae25d2b4464 Rename link_name to link_id everywhere, regardless of case (so LINK_NAME
Todd Larsen <tlarsen@google.com>
parents: 499
diff changeset
    46
    return [entity.sponsor.link_id, entity.user.link_id]
410
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
  def getKeyValuesFromFields(self, fields):
2af7f84f4fc7 Moved all key_name related things to the logic modules
Sverre Rabbelier <srabbelier@gmail.com>
parents: 409
diff changeset
    49
    """See base.Logic.getKeyValuesFromFields.
2af7f84f4fc7 Moved all key_name related things to the logic modules
Sverre Rabbelier <srabbelier@gmail.com>
parents: 409
diff changeset
    50
    """
2af7f84f4fc7 Moved all key_name related things to the logic modules
Sverre Rabbelier <srabbelier@gmail.com>
parents: 409
diff changeset
    51
444
6e50bfc6e5a7 Fix sponsor key field extraction
Sverre Rabbelier <srabbelier@gmail.com>
parents: 432
diff changeset
    52
    return [fields['sponsor_ln'], fields['user_ln']]
410
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
  def getKeyFieldNames(self):
499
d22e4fe8e64b Fix missing dots in doc strings and some other doc string corrections.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 481
diff changeset
    55
    """See base.Logic.getKeyFieldNames.
410
2af7f84f4fc7 Moved all key_name related things to the logic modules
Sverre Rabbelier <srabbelier@gmail.com>
parents: 409
diff changeset
    56
    """
2af7f84f4fc7 Moved all key_name related things to the logic modules
Sverre Rabbelier <srabbelier@gmail.com>
parents: 409
diff changeset
    57
2af7f84f4fc7 Moved all key_name related things to the logic modules
Sverre Rabbelier <srabbelier@gmail.com>
parents: 409
diff changeset
    58
    return ['sponsor_ln', 'user_ln']
19
f2a5ec8fb780 Initial definition of the Host Model.
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    59
404
44223e50e1fc Added a Host profile and generalized some views
Sverre Rabbelier <srabbelier@gmail.com>
parents: 244
diff changeset
    60
logic = Logic()