app/soc/logic/models/user.py
author Pawel Solyga <Pawel.Solyga@gmail.com>
Mon, 13 Oct 2008 21:54:51 +0000
changeset 316 9efdc7bc3565
parent 308 740090cd17c9
child 429 e50e18936f06
permissions -rw-r--r--
Add missing blank lines between imports and sort all of the imports. Patch by: Pawel Solyga Review by: to-be-reviewed
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
308
740090cd17c9 Added invididual model logic files
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
     1
#!/usr/bin/python2.5
740090cd17c9 Added invididual model logic files
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
     2
#
740090cd17c9 Added invididual model logic files
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
     3
# Copyright 2008 the Melange authors.
740090cd17c9 Added invididual model logic files
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
     4
#
740090cd17c9 Added invididual model logic files
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
     5
# Licensed under the Apache License, Version 2.0 (the "License");
740090cd17c9 Added invididual model logic files
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
     6
# you may not use this file except in compliance with the License.
740090cd17c9 Added invididual model logic files
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
     7
# You may obtain a copy of the License at
740090cd17c9 Added invididual model logic files
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
     8
#
740090cd17c9 Added invididual model logic files
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
     9
#   http://www.apache.org/licenses/LICENSE-2.0
740090cd17c9 Added invididual model logic files
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    10
#
740090cd17c9 Added invididual model logic files
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    11
# Unless required by applicable law or agreed to in writing, software
740090cd17c9 Added invididual model logic files
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    12
# distributed under the License is distributed on an "AS IS" BASIS,
740090cd17c9 Added invididual model logic files
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    13
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
740090cd17c9 Added invididual model logic files
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    14
# See the License for the specific language governing permissions and
740090cd17c9 Added invididual model logic files
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    15
# limitations under the License.
740090cd17c9 Added invididual model logic files
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    16
740090cd17c9 Added invididual model logic files
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    17
"""User (Model) query functions.
740090cd17c9 Added invididual model logic files
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    18
"""
740090cd17c9 Added invididual model logic files
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    19
740090cd17c9 Added invididual model logic files
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    20
__authors__ = [
740090cd17c9 Added invididual model logic files
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    21
  '"Sverre Rabbelier" <sverer@rabbelier.nl>',
740090cd17c9 Added invididual model logic files
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    22
  ]
740090cd17c9 Added invididual model logic files
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    23
740090cd17c9 Added invididual model logic files
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    24
740090cd17c9 Added invididual model logic files
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    25
from soc.logic import key_name
740090cd17c9 Added invididual model logic files
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    26
from soc.logic.models import base
316
9efdc7bc3565 Add missing blank lines between imports and sort all of the imports.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 308
diff changeset
    27
308
740090cd17c9 Added invididual model logic files
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    28
import soc.models.user
740090cd17c9 Added invididual model logic files
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    29
740090cd17c9 Added invididual model logic files
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    30
740090cd17c9 Added invididual model logic files
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    31
class Logic(base.Logic):
740090cd17c9 Added invididual model logic files
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    32
  """Logic methods for the User model
740090cd17c9 Added invididual model logic files
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    33
  """
740090cd17c9 Added invididual model logic files
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    34
740090cd17c9 Added invididual model logic files
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    35
  def __init__(self):
740090cd17c9 Added invididual model logic files
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    36
    """Defines the name, key_name and model for this entity.
740090cd17c9 Added invididual model logic files
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    37
    """
740090cd17c9 Added invididual model logic files
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    38
740090cd17c9 Added invididual model logic files
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    39
    self._name = "user"
740090cd17c9 Added invididual model logic files
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    40
    self._model = soc.models.user.User
740090cd17c9 Added invididual model logic files
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    41
    self._keyName = key_name.nameUser
740090cd17c9 Added invididual model logic files
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    42
    self._skip_properties = ['former_ids']
740090cd17c9 Added invididual model logic files
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    43
740090cd17c9 Added invididual model logic files
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    44
  def _updateField(self, model, name, value):
740090cd17c9 Added invididual model logic files
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    45
    """Special case logic for id.
740090cd17c9 Added invididual model logic files
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    46
740090cd17c9 Added invididual model logic files
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    47
    When the id is changed, the former_ids field should be appended
740090cd17c9 Added invididual model logic files
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    48
    with the old id.
740090cd17c9 Added invididual model logic files
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    49
    """
740090cd17c9 Added invididual model logic files
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    50
    if name == 'id' and model.id != value:
740090cd17c9 Added invididual model logic files
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    51
      model.former_ids.append(model.id)
740090cd17c9 Added invididual model logic files
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    52
740090cd17c9 Added invididual model logic files
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    53
    return True
740090cd17c9 Added invididual model logic files
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    54
740090cd17c9 Added invididual model logic files
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    55
740090cd17c9 Added invididual model logic files
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    56
logic = Logic()