app/soc/logic/models/host.py
author Madhusudan.C.S <madhusudancs@gmail.com>
Sat, 22 Aug 2009 03:56:25 +0530
changeset 2784 801eee4eda9a
parent 2673 cecb3a669527
permissions -rw-r--r--
Added timeline view for GHOP. Moved the method _createTimelineForType from Views to Logic for both core Program and GHOPProgram. Added default values parameter to apps_tasks_limit and slots in Program model. Registered timeline view for the sitemap in GHOP callback.py. Added timeline view module and class which overrides the edit method. Overriding the params['edit_form'] to accommodate dynainclude and dynaexclude fields.
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
#
1308
35b75ffcbb37 Partially reverted "Update the copyright notice for 2009."
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1307
diff changeset
     3
# Copyright 2008 the Melange authors.
19
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>',
1062
f7ee38ebfe1c Creating a new host or club_admin will set the group state to active if it's new.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 671
diff changeset
    22
  '"Lennard de Rijk" <ljvderijk@gmail.com>',
404
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
535
9045b8888772 Refactor classes in soc/logic/models to make more use of inheritance. Add
Todd Larsen <tlarsen@google.com>
parents: 530
diff changeset
    26
from soc.logic.models import role
671
2c02178037ff Apply DI on the scope logic
Sverre Rabbelier <srabbelier@gmail.com>
parents: 655
diff changeset
    27
from soc.logic.models import sponsor as sponsor_logic
404
44223e50e1fc Added a Host profile and generalized some views
Sverre Rabbelier <srabbelier@gmail.com>
parents: 244
diff changeset
    28
44223e50e1fc Added a Host profile and generalized some views
Sverre Rabbelier <srabbelier@gmail.com>
parents: 244
diff changeset
    29
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
    30
import soc.models.role
19
f2a5ec8fb780 Initial definition of the Host Model.
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    31
207
8ecc2e4198cd Take advantage of the Model inheritance provided by polymodel.PolyModel to
Todd Larsen <tlarsen@google.com>
parents: 181
diff changeset
    32
535
9045b8888772 Refactor classes in soc/logic/models to make more use of inheritance. Add
Todd Larsen <tlarsen@google.com>
parents: 530
diff changeset
    33
class Logic(role.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
    34
  """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
    35
  """
19
f2a5ec8fb780 Initial definition of the Host Model.
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    36
2664
06d4f4d06f64 Added registerRole to Role Logic where all roles are registered.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1955
diff changeset
    37
  def __init__(self, model=soc.models.host.Host,
1955
06ed84dbb1ed Moved canResign check to role logic so subclasses can override.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1308
diff changeset
    38
               base_model=soc.models.role.Role, scope_logic=sponsor_logic,
2664
06d4f4d06f64 Added registerRole to Role Logic where all roles are registered.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1955
diff changeset
    39
               role_name='host', disallow_last_resign=True):
404
44223e50e1fc Added a Host profile and generalized some views
Sverre Rabbelier <srabbelier@gmail.com>
parents: 244
diff changeset
    40
    """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
    41
    """
655
9635cbaa2dcd Cleanups to the logic module
Sverre Rabbelier <srabbelier@gmail.com>
parents: 535
diff changeset
    42
2673
cecb3a669527 Added missing role_name to org_admin Logic.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2664
diff changeset
    43
    super(Logic, self).__init__(model=model, base_model=base_model,
cecb3a669527 Added missing role_name to org_admin Logic.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2664
diff changeset
    44
                                scope_logic=scope_logic,
cecb3a669527 Added missing role_name to org_admin Logic.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2664
diff changeset
    45
                                role_name=role_name,
1955
06ed84dbb1ed Moved canResign check to role logic so subclasses can override.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1308
diff changeset
    46
                                disallow_last_resign=disallow_last_resign)
19
f2a5ec8fb780 Initial definition of the Host Model.
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    47
1062
f7ee38ebfe1c Creating a new host or club_admin will set the group state to active if it's new.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 671
diff changeset
    48
  def _onCreate(self, entity):
1085
0afbdd0905ef Renamed state to status where appropriate.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1062
diff changeset
    49
    """Marks the Sponsor for this Host as active it's status is new.
1062
f7ee38ebfe1c Creating a new host or club_admin will set the group state to active if it's new.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 671
diff changeset
    50
    """
f7ee38ebfe1c Creating a new host or club_admin will set the group state to active if it's new.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 671
diff changeset
    51
f7ee38ebfe1c Creating a new host or club_admin will set the group state to active if it's new.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 671
diff changeset
    52
    sponsor_entity = entity.scope
f7ee38ebfe1c Creating a new host or club_admin will set the group state to active if it's new.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 671
diff changeset
    53
1085
0afbdd0905ef Renamed state to status where appropriate.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1062
diff changeset
    54
    if sponsor_entity.status == 'new':
1062
f7ee38ebfe1c Creating a new host or club_admin will set the group state to active if it's new.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 671
diff changeset
    55
      # this sponsor is new so mark as active
1140
a8eaea0b268d Style fixes in soc.logic.models modules (basically removing of extra whitespaces).
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 1085
diff changeset
    56
      fields = {'status': 'active'}
1062
f7ee38ebfe1c Creating a new host or club_admin will set the group state to active if it's new.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 671
diff changeset
    57
      sponsor_logic.logic.updateEntityProperties(sponsor_entity, fields)
f7ee38ebfe1c Creating a new host or club_admin will set the group state to active if it's new.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 671
diff changeset
    58
f7ee38ebfe1c Creating a new host or club_admin will set the group state to active if it's new.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 671
diff changeset
    59
    # call super
f7ee38ebfe1c Creating a new host or club_admin will set the group state to active if it's new.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 671
diff changeset
    60
    super(Logic, self)._onCreate(entity)
f7ee38ebfe1c Creating a new host or club_admin will set the group state to active if it's new.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 671
diff changeset
    61
f7ee38ebfe1c Creating a new host or club_admin will set the group state to active if it's new.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 671
diff changeset
    62
404
44223e50e1fc Added a Host profile and generalized some views
Sverre Rabbelier <srabbelier@gmail.com>
parents: 244
diff changeset
    63
logic = Logic()