app/soc/logic/models/group.py
changeset 535 9045b8888772
parent 530 8d5adb2b8d48
child 655 9635cbaa2dcd
equal deleted inserted replaced
534:c31cfbf1a20f 535:9045b8888772
       
     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 """Group (Model) query functions.
       
    18 """
       
    19 
       
    20 __authors__ = [
       
    21   '"Sverre Rabbelier" <sverre@rabbelier.nl>',
       
    22   ]
       
    23 
       
    24 
       
    25 from soc.logic.models import base
       
    26 
       
    27 import soc.models.group
       
    28 
       
    29 
       
    30 class Logic(base.Logic):
       
    31   """Logic methods for the Group model.
       
    32   """
       
    33 
       
    34   def __init__(self, model=soc.models.group.Group, base_model=None):
       
    35     """Defines the name, key_name and model for this entity.
       
    36     """
       
    37     base.Logic.__init__(self, model, base_model=base_model)
       
    38 
       
    39   def getKeyValues(self, entity):
       
    40     """Extracts the key values from entity and returns them.
       
    41 
       
    42     The default implementation for Groups assumes that the Group is site-wide
       
    43     and thus has no scope.  Such Groups include Sponsors and Clubs.  Any
       
    44     Group that exists per-Program or per-Year will need to override this
       
    45     method.
       
    46 
       
    47     Args:
       
    48       entity: the entity from which to extract the key values
       
    49     """
       
    50 
       
    51     return [entity.link_id]
       
    52 
       
    53   def getKeyValuesFromFields(self, fields):
       
    54     """Extracts the key values from a dict and returns them.
       
    55 
       
    56     The default implementation for Groups assumes that the Group is site-wide
       
    57     and thus has no scope.  Such Groups include Sponsors and Clubs.  Any
       
    58     Group that exists per-Program or per-Year will need to override this
       
    59     method.
       
    60 
       
    61     Args:
       
    62       fields: the dict from which to extract the key values
       
    63     """
       
    64 
       
    65     return [fields['link_id']]
       
    66 
       
    67   def getKeyFieldNames(self):
       
    68     """Returns an array with the names of the Key Fields.
       
    69 
       
    70     The default implementation for Groups assumes that the Group is site-wide
       
    71     and thus has no scope.  Such Groups include Sponsors and Clubs.  Any
       
    72     Group that exists per-Program or per-Year will need to override this
       
    73     method.
       
    74     """
       
    75 
       
    76     return ['link_id']
       
    77 
       
    78 
       
    79   def isDeletable(self, entity):
       
    80     """Returns whether the specified Group entity can be deleted.
       
    81 
       
    82     Generically, a Group can always be deleted.  Subclasses of group.Logic
       
    83     should add their own deletion prerequisites.
       
    84     
       
    85     Args:
       
    86       entity: an existing Group entity in the Datastore
       
    87     """
       
    88 
       
    89     return True
       
    90 
       
    91 
       
    92 logic = Logic()