author | Lennard de Rijk <ljvderijk@gmail.com> |
Sat, 24 Oct 2009 15:14:11 -0700 | |
changeset 3036 | c703f3802841 |
parent 2678 | a525a55833f1 |
child 3047 | cdc652533fcc |
permissions | -rw-r--r-- |
495
87afae6e4c51
Added basic 'invite' functionality
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
1 |
#!/usr/bin/python2.5 |
87afae6e4c51
Added basic 'invite' functionality
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. |
495
87afae6e4c51
Added basic 'invite' functionality
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
4 |
# |
87afae6e4c51
Added basic 'invite' functionality
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
5 |
# Licensed under the Apache License, Version 2.0 (the "License"); |
87afae6e4c51
Added basic 'invite' functionality
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
6 |
# you may not use this file except in compliance with the License. |
87afae6e4c51
Added basic 'invite' functionality
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
7 |
# You may obtain a copy of the License at |
87afae6e4c51
Added basic 'invite' functionality
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
8 |
# |
87afae6e4c51
Added basic 'invite' functionality
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
9 |
# http://www.apache.org/licenses/LICENSE-2.0 |
87afae6e4c51
Added basic 'invite' functionality
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
10 |
# |
87afae6e4c51
Added basic 'invite' functionality
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
11 |
# Unless required by applicable law or agreed to in writing, software |
87afae6e4c51
Added basic 'invite' functionality
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
12 |
# distributed under the License is distributed on an "AS IS" BASIS, |
87afae6e4c51
Added basic 'invite' functionality
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
13 |
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
87afae6e4c51
Added basic 'invite' functionality
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
14 |
# See the License for the specific language governing permissions and |
87afae6e4c51
Added basic 'invite' functionality
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
15 |
# limitations under the License. |
87afae6e4c51
Added basic 'invite' functionality
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
16 |
|
631
3763d36bcebc
Fix typo and too long lines in soc.logic.models.request module.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
620
diff
changeset
|
17 |
"""Request (Model) query functions. |
495
87afae6e4c51
Added basic 'invite' functionality
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
18 |
""" |
87afae6e4c51
Added basic 'invite' functionality
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
19 |
|
87afae6e4c51
Added basic 'invite' functionality
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
20 |
__authors__ = [ |
674
0158b11cbf6d
More DI on scope_logic
Sverre Rabbelier <srabbelier@gmail.com>
parents:
655
diff
changeset
|
21 |
'"Sverre Rabbelier" <sverre@rabbelier.nl>', |
618
b2319f2633bc
Added invitation received message upon creating a new invite.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
562
diff
changeset
|
22 |
'"Lennard de Rijk" <ljvderijk@gmail.com>' |
495
87afae6e4c51
Added basic 'invite' functionality
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
23 |
] |
87afae6e4c51
Added basic 'invite' functionality
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
24 |
|
635
2f5322ad1f5b
Moved sendInviteMessage to a new module in logic/helper/notifications.py.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
631
diff
changeset
|
25 |
import soc.models.request |
495
87afae6e4c51
Added basic 'invite' functionality
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
26 |
|
635
2f5322ad1f5b
Moved sendInviteMessage to a new module in logic/helper/notifications.py.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
631
diff
changeset
|
27 |
from soc.logic.helper import notifications |
495
87afae6e4c51
Added basic 'invite' functionality
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
28 |
from soc.logic.models import base |
1123
9b53bc4b2ea7
Changed scope_logic for requests to linkable_logic.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
1115
diff
changeset
|
29 |
from soc.logic.models import linkable as linkable_logic |
495
87afae6e4c51
Added basic 'invite' functionality
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
30 |
|
87afae6e4c51
Added basic 'invite' functionality
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
31 |
|
87afae6e4c51
Added basic 'invite' functionality
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
32 |
class Logic(base.Logic): |
499
d22e4fe8e64b
Fix missing dots in doc strings and some other doc string corrections.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
495
diff
changeset
|
33 |
"""Logic methods for the Request model. |
495
87afae6e4c51
Added basic 'invite' functionality
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
34 |
""" |
87afae6e4c51
Added basic 'invite' functionality
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
35 |
|
535
9045b8888772
Refactor classes in soc/logic/models to make more use of inheritance. Add
Todd Larsen <tlarsen@google.com>
parents:
530
diff
changeset
|
36 |
def __init__(self, model=soc.models.request.Request, |
1123
9b53bc4b2ea7
Changed scope_logic for requests to linkable_logic.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
1115
diff
changeset
|
37 |
base_model=None, scope_logic=linkable_logic): |
495
87afae6e4c51
Added basic 'invite' functionality
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
38 |
"""Defines the name, key_name and model for this entity. |
87afae6e4c51
Added basic 'invite' functionality
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
39 |
""" |
87afae6e4c51
Added basic 'invite' functionality
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
40 |
|
674
0158b11cbf6d
More DI on scope_logic
Sverre Rabbelier <srabbelier@gmail.com>
parents:
655
diff
changeset
|
41 |
super(Logic, self).__init__(model, base_model=base_model, |
0158b11cbf6d
More DI on scope_logic
Sverre Rabbelier <srabbelier@gmail.com>
parents:
655
diff
changeset
|
42 |
scope_logic=scope_logic) |
495
87afae6e4c51
Added basic 'invite' functionality
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
43 |
|
1115
0a723ff3d27c
Cleanups in base.Logic
Sverre Rabbelier <srabbelier@gmail.com>
parents:
1106
diff
changeset
|
44 |
def getKeyValuesFromEntity(self, entity): |
495
87afae6e4c51
Added basic 'invite' functionality
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
45 |
"""See base.Logic.getKeyNameValues. |
87afae6e4c51
Added basic 'invite' functionality
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
46 |
""" |
87afae6e4c51
Added basic 'invite' functionality
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
47 |
|
676
c6433532ddff
Swap the order of request key fields
Sverre Rabbelier <srabbelier@gmail.com>
parents:
674
diff
changeset
|
48 |
return [entity.scope.link_id, entity.role, entity.link_id] |
495
87afae6e4c51
Added basic 'invite' functionality
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
49 |
|
87afae6e4c51
Added basic 'invite' functionality
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
50 |
def getKeyValuesFromFields(self, fields): |
87afae6e4c51
Added basic 'invite' functionality
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
51 |
"""See base.Logic.getKeyValuesFromFields. |
87afae6e4c51
Added basic 'invite' functionality
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
52 |
""" |
87afae6e4c51
Added basic 'invite' functionality
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
53 |
|
676
c6433532ddff
Swap the order of request key fields
Sverre Rabbelier <srabbelier@gmail.com>
parents:
674
diff
changeset
|
54 |
return [fields['scope_path'], fields['role'], fields['link_id']] |
495
87afae6e4c51
Added basic 'invite' functionality
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
55 |
|
87afae6e4c51
Added basic 'invite' functionality
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
56 |
def getKeyFieldNames(self): |
499
d22e4fe8e64b
Fix missing dots in doc strings and some other doc string corrections.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
495
diff
changeset
|
57 |
"""See base.Logic.getKeyFieldNames. |
495
87afae6e4c51
Added basic 'invite' functionality
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
58 |
""" |
87afae6e4c51
Added basic 'invite' functionality
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
59 |
|
676
c6433532ddff
Swap the order of request key fields
Sverre Rabbelier <srabbelier@gmail.com>
parents:
674
diff
changeset
|
60 |
return ['scope_path', 'role', 'link_id'] |
1948
25cd704fdfdf
Fixed double sending of notifications on creating a new invite.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
1308
diff
changeset
|
61 |
|
618
b2319f2633bc
Added invitation received message upon creating a new invite.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
562
diff
changeset
|
62 |
def _onCreate(self, entity): |
b2319f2633bc
Added invitation received message upon creating a new invite.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
562
diff
changeset
|
63 |
"""Sends out a message notifying users about the new invite/request. |
b2319f2633bc
Added invitation received message upon creating a new invite.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
562
diff
changeset
|
64 |
""" |
818
ddd102e82107
Fixed whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents:
676
diff
changeset
|
65 |
|
1085
0afbdd0905ef
Renamed state to status where appropriate.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
928
diff
changeset
|
66 |
if entity.status == 'group_accepted': |
618
b2319f2633bc
Added invitation received message upon creating a new invite.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
562
diff
changeset
|
67 |
# this is an invite |
635
2f5322ad1f5b
Moved sendInviteMessage to a new module in logic/helper/notifications.py.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
631
diff
changeset
|
68 |
notifications.sendInviteNotification(entity) |
1085
0afbdd0905ef
Renamed state to status where appropriate.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
928
diff
changeset
|
69 |
elif entity.status == 'new': |
618
b2319f2633bc
Added invitation received message upon creating a new invite.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
562
diff
changeset
|
70 |
# this is a request |
2678
a525a55833f1
Send out a Notification upon creation of a new Request entity.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
1954
diff
changeset
|
71 |
notifications.sendNewRequestNotification(entity) |
495
87afae6e4c51
Added basic 'invite' functionality
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
72 |
|
1106
e14b0995cf29
Flush sidebar when creating a new entity
Sverre Rabbelier <srabbelier@gmail.com>
parents:
1085
diff
changeset
|
73 |
super(Logic, self)._onCreate(entity) |
e14b0995cf29
Flush sidebar when creating a new entity
Sverre Rabbelier <srabbelier@gmail.com>
parents:
1085
diff
changeset
|
74 |
|
1948
25cd704fdfdf
Fixed double sending of notifications on creating a new invite.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
1308
diff
changeset
|
75 |
def _updateField(self, entity, entity_properties, name): |
25cd704fdfdf
Fixed double sending of notifications on creating a new invite.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
1308
diff
changeset
|
76 |
"""Called when the fields of the request are updated. |
25cd704fdfdf
Fixed double sending of notifications on creating a new invite.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
1308
diff
changeset
|
77 |
|
1954 | 78 |
Sends out a message depending on the change of status. |
1948
25cd704fdfdf
Fixed double sending of notifications on creating a new invite.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
1308
diff
changeset
|
79 |
""" |
25cd704fdfdf
Fixed double sending of notifications on creating a new invite.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
1308
diff
changeset
|
80 |
|
25cd704fdfdf
Fixed double sending of notifications on creating a new invite.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
1308
diff
changeset
|
81 |
value = entity_properties[name] |
25cd704fdfdf
Fixed double sending of notifications on creating a new invite.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
1308
diff
changeset
|
82 |
|
25cd704fdfdf
Fixed double sending of notifications on creating a new invite.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
1308
diff
changeset
|
83 |
if name == 'status' and entity.status != value: |
25cd704fdfdf
Fixed double sending of notifications on creating a new invite.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
1308
diff
changeset
|
84 |
if value == 'group_accepted': |
25cd704fdfdf
Fixed double sending of notifications on creating a new invite.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
1308
diff
changeset
|
85 |
# this is an invite |
25cd704fdfdf
Fixed double sending of notifications on creating a new invite.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
1308
diff
changeset
|
86 |
notifications.sendInviteNotification(entity) |
25cd704fdfdf
Fixed double sending of notifications on creating a new invite.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
1308
diff
changeset
|
87 |
elif value == 'new': |
25cd704fdfdf
Fixed double sending of notifications on creating a new invite.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
1308
diff
changeset
|
88 |
# this is a request |
2678
a525a55833f1
Send out a Notification upon creation of a new Request entity.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
1954
diff
changeset
|
89 |
notifications.sendNewRequestNotification(entity) |
1948
25cd704fdfdf
Fixed double sending of notifications on creating a new invite.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
1308
diff
changeset
|
90 |
|
25cd704fdfdf
Fixed double sending of notifications on creating a new invite.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
1308
diff
changeset
|
91 |
return super(Logic, self)._updateField(entity, entity_properties, name) |
25cd704fdfdf
Fixed double sending of notifications on creating a new invite.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
1308
diff
changeset
|
92 |
|
495
87afae6e4c51
Added basic 'invite' functionality
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
93 |
|
87afae6e4c51
Added basic 'invite' functionality
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
94 |
logic = Logic() |