author | Sverre Rabbelier <srabbelier@gmail.com> |
Mon, 02 Feb 2009 15:39:22 +0000 | |
changeset 1183 | 03db1f6d222a |
parent 1117 | 5785d9af5c5d |
child 1307 | 091a21cf3627 |
permissions | -rw-r--r-- |
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 |
|
535
9045b8888772
Refactor classes in soc/logic/models to make more use of inheritance. Add
Todd Larsen <tlarsen@google.com>
parents:
530
diff
changeset
|
17 |
"""Role (Model) query functions. |
404
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>', |
715
51703b18ef2e
Adds the removal of requests from the datastore when a new role entity is created.
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 |
|
991
becede26c37f
Added cache flush for the user who creates a group and the user whose role has been activated.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
978
diff
changeset
|
26 |
from soc.cache import sidebar |
404
44223e50e1fc
Added a Host profile and generalized some views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
244
diff
changeset
|
27 |
from soc.logic.models import base |
44223e50e1fc
Added a Host profile and generalized some views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
244
diff
changeset
|
28 |
|
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): |
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 |
"""Logic methods for the Role 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 |
|
671
2c02178037ff
Apply DI on the scope logic
Sverre Rabbelier <srabbelier@gmail.com>
parents:
655
diff
changeset
|
36 |
def __init__(self, model=soc.models.role.Role, |
2c02178037ff
Apply DI on the scope logic
Sverre Rabbelier <srabbelier@gmail.com>
parents:
655
diff
changeset
|
37 |
base_model=None, scope_logic=None): |
404
44223e50e1fc
Added a Host profile and generalized some views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
244
diff
changeset
|
38 |
"""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
|
39 |
""" |
655
9635cbaa2dcd
Cleanups to the logic module
Sverre Rabbelier <srabbelier@gmail.com>
parents:
535
diff
changeset
|
40 |
|
671
2c02178037ff
Apply DI on the scope logic
Sverre Rabbelier <srabbelier@gmail.com>
parents:
655
diff
changeset
|
41 |
super(Logic, self).__init__(model, base_model=base_model, |
2c02178037ff
Apply DI on the scope logic
Sverre Rabbelier <srabbelier@gmail.com>
parents:
655
diff
changeset
|
42 |
scope_logic=scope_logic) |
410
2af7f84f4fc7
Moved all key_name related things to the logic modules
Sverre Rabbelier <srabbelier@gmail.com>
parents:
409
diff
changeset
|
43 |
|
19
f2a5ec8fb780
Initial definition of the Host Model.
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
44 |
|
978
e05b09b53486
Moved getGroupEntityFromScopePath to logic/models/role.py.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
916
diff
changeset
|
45 |
def getGroupEntityFromScopePath(self, group_logic, scope_path): |
e05b09b53486
Moved getGroupEntityFromScopePath to logic/models/role.py.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
916
diff
changeset
|
46 |
"""Returns a group entity by using the given scope_path. |
e05b09b53486
Moved getGroupEntityFromScopePath to logic/models/role.py.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
916
diff
changeset
|
47 |
|
e05b09b53486
Moved getGroupEntityFromScopePath to logic/models/role.py.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
916
diff
changeset
|
48 |
Args: |
e05b09b53486
Moved getGroupEntityFromScopePath to logic/models/role.py.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
916
diff
changeset
|
49 |
group_logic: logic for the group which should be retrieved |
e05b09b53486
Moved getGroupEntityFromScopePath to logic/models/role.py.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
916
diff
changeset
|
50 |
scope_path : the scope path of the entity |
e05b09b53486
Moved getGroupEntityFromScopePath to logic/models/role.py.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
916
diff
changeset
|
51 |
""" |
e05b09b53486
Moved getGroupEntityFromScopePath to logic/models/role.py.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
916
diff
changeset
|
52 |
group_key_fields = scope_path.rsplit('/',1) |
e05b09b53486
Moved getGroupEntityFromScopePath to logic/models/role.py.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
916
diff
changeset
|
53 |
|
e05b09b53486
Moved getGroupEntityFromScopePath to logic/models/role.py.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
916
diff
changeset
|
54 |
if len(group_key_fields) == 1: |
e05b09b53486
Moved getGroupEntityFromScopePath to logic/models/role.py.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
916
diff
changeset
|
55 |
# there is only a link_id |
e05b09b53486
Moved getGroupEntityFromScopePath to logic/models/role.py.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
916
diff
changeset
|
56 |
fields = {'link_id' : group_key_fields[0]} |
e05b09b53486
Moved getGroupEntityFromScopePath to logic/models/role.py.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
916
diff
changeset
|
57 |
else: |
e05b09b53486
Moved getGroupEntityFromScopePath to logic/models/role.py.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
916
diff
changeset
|
58 |
# there is a scope_path and link_id |
e05b09b53486
Moved getGroupEntityFromScopePath to logic/models/role.py.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
916
diff
changeset
|
59 |
fields = {'scope_path' : group_key_fields[0], |
e05b09b53486
Moved getGroupEntityFromScopePath to logic/models/role.py.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
916
diff
changeset
|
60 |
'link_id' : group_key_fields[1]} |
e05b09b53486
Moved getGroupEntityFromScopePath to logic/models/role.py.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
916
diff
changeset
|
61 |
|
e05b09b53486
Moved getGroupEntityFromScopePath to logic/models/role.py.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
916
diff
changeset
|
62 |
group = group_logic.getForFields(fields, unique=True) |
e05b09b53486
Moved getGroupEntityFromScopePath to logic/models/role.py.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
916
diff
changeset
|
63 |
|
e05b09b53486
Moved getGroupEntityFromScopePath to logic/models/role.py.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
916
diff
changeset
|
64 |
return group |
e05b09b53486
Moved getGroupEntityFromScopePath to logic/models/role.py.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
916
diff
changeset
|
65 |
|
991
becede26c37f
Added cache flush for the user who creates a group and the user whose role has been activated.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
978
diff
changeset
|
66 |
def _updateField(self, entity, name, value): |
1085
0afbdd0905ef
Renamed state to status where appropriate.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
1001
diff
changeset
|
67 |
"""Special logic for role. If status changes to active we flush the sidebar. |
991
becede26c37f
Added cache flush for the user who creates a group and the user whose role has been activated.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
978
diff
changeset
|
68 |
""" |
becede26c37f
Added cache flush for the user who creates a group and the user whose role has been activated.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
978
diff
changeset
|
69 |
|
1085
0afbdd0905ef
Renamed state to status where appropriate.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
1001
diff
changeset
|
70 |
if (name == 'status') and (entity.status != value) and value == 'active': |
0afbdd0905ef
Renamed state to status where appropriate.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
1001
diff
changeset
|
71 |
# in case the status of the role changes to active we flush the sidebar |
991
becede26c37f
Added cache flush for the user who creates a group and the user whose role has been activated.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
978
diff
changeset
|
72 |
# cache. Other changes will be visible after the retention time expires. |
becede26c37f
Added cache flush for the user who creates a group and the user whose role has been activated.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
978
diff
changeset
|
73 |
sidebar.flush(entity.user.account) |
becede26c37f
Added cache flush for the user who creates a group and the user whose role has been activated.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
978
diff
changeset
|
74 |
|
becede26c37f
Added cache flush for the user who creates a group and the user whose role has been activated.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
978
diff
changeset
|
75 |
return True |
1001
2faa7f80e8b2
Flush the sidebar cache when a new active role entity has been created.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
991
diff
changeset
|
76 |
|
2faa7f80e8b2
Flush the sidebar cache when a new active role entity has been created.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
991
diff
changeset
|
77 |
def _onCreate(self, entity): |
2faa7f80e8b2
Flush the sidebar cache when a new active role entity has been created.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
991
diff
changeset
|
78 |
"""Flush the sidebar cache when a new active role entity has been created. |
2faa7f80e8b2
Flush the sidebar cache when a new active role entity has been created.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
991
diff
changeset
|
79 |
""" |
2faa7f80e8b2
Flush the sidebar cache when a new active role entity has been created.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
991
diff
changeset
|
80 |
|
1085
0afbdd0905ef
Renamed state to status where appropriate.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
1001
diff
changeset
|
81 |
if entity.status == 'active': |
1001
2faa7f80e8b2
Flush the sidebar cache when a new active role entity has been created.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
991
diff
changeset
|
82 |
sidebar.flush(entity.user.account) |
991
becede26c37f
Added cache flush for the user who creates a group and the user whose role has been activated.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
978
diff
changeset
|
83 |
|
1117
5785d9af5c5d
Fixed a bug in role.py that made it call the wrong superclass.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
1106
diff
changeset
|
84 |
super(Logic, self)._onCreate(entity) |
1106
e14b0995cf29
Flush sidebar when creating a new entity
Sverre Rabbelier <srabbelier@gmail.com>
parents:
1085
diff
changeset
|
85 |
|
978
e05b09b53486
Moved getGroupEntityFromScopePath to logic/models/role.py.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
916
diff
changeset
|
86 |
|
404
44223e50e1fc
Added a Host profile and generalized some views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
244
diff
changeset
|
87 |
logic = Logic() |