app/soc/logic/__init__.py
changeset 310 0386d634ad9f
parent 299 a1cc853a56e5
child 2065 edac5ddc8ef0
equal deleted inserted replaced
309:7190b224c701 310:0386d634ad9f
     1 #!/usr/bin/python2.5
       
     2 #
       
     3 # Copyright 2008 the Melange authors.
       
     4 #
       
     5 # Licensed under the Apache License, Version 2.0 (the "License");
       
     6 # you may not use this file except in compliance with the License.
       
     7 # You may obtain a copy of the License at
       
     8 #
       
     9 #   http://www.apache.org/licenses/LICENSE-2.0
       
    10 #
       
    11 # Unless required by applicable law or agreed to in writing, software
       
    12 # distributed under the License is distributed on an "AS IS" BASIS,
       
    13 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
       
    14 # See the License for the specific language governing permissions and
       
    15 # limitations under the License.
       
    16 
       
    17 """Various (Model) query functions.
       
    18 """
       
    19 
       
    20 __authors__ = [
       
    21   '"Sverre Rabbelier" <sverer@rabbelier.nl>',
       
    22   ]
       
    23 
       
    24 
       
    25 import key_name
       
    26 import model
       
    27 import soc.models.document
       
    28 import soc.models.sponsor
       
    29 import soc.models.work
       
    30 import soc.models.site_settings
       
    31 
       
    32 
       
    33 class DocumentLogic(model.BaseLogic):
       
    34   """Logic methods for the Document model
       
    35   """
       
    36 
       
    37   def __init__(self):
       
    38     """Defines the name, key_name and model for this entity.
       
    39     """
       
    40 
       
    41     self._name = "document"
       
    42     self._model = soc.models.document.Document
       
    43     self._keyName = key_name.nameDocument
       
    44     self._skip_properties = []
       
    45 
       
    46 
       
    47 class SettingsLogic(model.BaseLogic):
       
    48   """Logic methods for the Settings model
       
    49   """
       
    50 
       
    51 
       
    52   def __init__(self):
       
    53     """Defines the name, key_name and model for this entity.
       
    54     """
       
    55 
       
    56     self._name = "settings"
       
    57     self._model = soc.models.site_settings.SiteSettings
       
    58     self._keyName = key_name.nameSiteSettings
       
    59     self._skip_properties = []
       
    60 
       
    61 
       
    62 class SponsorLogic(model.BaseLogic):
       
    63   """Logic methods for the Sponsor model
       
    64   """
       
    65 
       
    66   def __init__(self):
       
    67     """Defines the name, key_name and model for this entity.
       
    68     """
       
    69 
       
    70     self._name = "sponsor"
       
    71     self._model = soc.models.sponsor.Sponsor
       
    72     self._keyName = key_name.nameSponsor
       
    73     self._skip_properties = []
       
    74 
       
    75 
       
    76 class UserLogic(model.BaseLogic):
       
    77   """Logic methods for the User model
       
    78   """
       
    79 
       
    80   def __init__(self):
       
    81     """Defines the name, key_name and model for this entity.
       
    82     """
       
    83 
       
    84     self._name = "user"
       
    85     self._model = soc.models.user.User
       
    86     self._keyName = key_name.nameUser
       
    87     self._skip_properties = ['former_ids']
       
    88 
       
    89   def _updateField(self, model, name, value):
       
    90     """Special case logic for id.
       
    91 
       
    92     When the id is changed, the former_ids field should be appended
       
    93     with the old id.
       
    94     """
       
    95     if name == 'id' and model.id != value:
       
    96       model.former_ids.append(model.id)
       
    97 
       
    98     return True
       
    99 
       
   100 class WorkLogic(model.BaseLogic):
       
   101   """Logic methods for the Work model
       
   102   """
       
   103 
       
   104   def __init__(self):
       
   105     """Defines the name, key_name and model for this entity.
       
   106     """
       
   107 
       
   108     self._name = "work"
       
   109     self._model = soc.models.work.Work
       
   110     self._keyName = key_name.nameWork
       
   111     self._skip_properties = []
       
   112     # TODO(tlarsen) write a nameWork method
       
   113 
       
   114 
       
   115 document_logic = DocumentLogic()
       
   116 settings_logic = SettingsLogic()
       
   117 sponsor_logic = SponsorLogic()
       
   118 user_logic = UserLogic()
       
   119 work_logic = WorkLogic()