author | Sverre Rabbelier <srabbelier@gmail.com> |
Sat, 12 Sep 2009 01:22:03 +0200 | |
changeset 2897 | c0e78185444c |
parent 2365 | a66e1dd8ced7 |
permissions | -rw-r--r-- |
2208
1bf4e904d5f5
Add priority groups (model, logic, and view)
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
1 |
#!/usr/bin/python2.5 |
1bf4e904d5f5
Add priority groups (model, logic, and view)
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
2 |
# |
1bf4e904d5f5
Add priority groups (model, logic, and view)
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
3 |
# Copyright 2009 the Melange authors. |
1bf4e904d5f5
Add priority groups (model, logic, and view)
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
4 |
# |
1bf4e904d5f5
Add priority groups (model, logic, and view)
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
5 |
# Licensed under the Apache License, Version 2.0 (the "License"); |
1bf4e904d5f5
Add priority groups (model, logic, and view)
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
6 |
# you may not use this file except in compliance with the License. |
1bf4e904d5f5
Add priority groups (model, logic, and view)
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
7 |
# You may obtain a copy of the License at |
1bf4e904d5f5
Add priority groups (model, logic, and view)
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
8 |
# |
1bf4e904d5f5
Add priority groups (model, logic, and view)
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
9 |
# http://www.apache.org/licenses/LICENSE-2.0 |
1bf4e904d5f5
Add priority groups (model, logic, and view)
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
10 |
# |
1bf4e904d5f5
Add priority groups (model, logic, and view)
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
11 |
# Unless required by applicable law or agreed to in writing, software |
1bf4e904d5f5
Add priority groups (model, logic, and view)
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
12 |
# distributed under the License is distributed on an "AS IS" BASIS, |
1bf4e904d5f5
Add priority groups (model, logic, and view)
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
13 |
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
1bf4e904d5f5
Add priority groups (model, logic, and view)
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
14 |
# See the License for the specific language governing permissions and |
1bf4e904d5f5
Add priority groups (model, logic, and view)
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
15 |
# limitations under the License. |
1bf4e904d5f5
Add priority groups (model, logic, and view)
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
16 |
|
1bf4e904d5f5
Add priority groups (model, logic, and view)
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
17 |
"""Priority Group (Model) query functions. |
1bf4e904d5f5
Add priority groups (model, logic, and view)
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
18 |
""" |
1bf4e904d5f5
Add priority groups (model, logic, and view)
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
19 |
|
1bf4e904d5f5
Add priority groups (model, logic, and view)
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
20 |
__authors__ = [ |
1bf4e904d5f5
Add priority groups (model, logic, and view)
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
21 |
'"Sverre Rabbelier" <sverre@rabbelier.nl>', |
1bf4e904d5f5
Add priority groups (model, logic, and view)
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
22 |
] |
1bf4e904d5f5
Add priority groups (model, logic, and view)
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
23 |
|
1bf4e904d5f5
Add priority groups (model, logic, and view)
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
24 |
|
1bf4e904d5f5
Add priority groups (model, logic, and view)
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
25 |
from soc.logic.models import base |
1bf4e904d5f5
Add priority groups (model, logic, and view)
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
26 |
|
1bf4e904d5f5
Add priority groups (model, logic, and view)
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
27 |
import soc.models.priority_group |
1bf4e904d5f5
Add priority groups (model, logic, and view)
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
28 |
|
1bf4e904d5f5
Add priority groups (model, logic, and view)
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
29 |
|
1bf4e904d5f5
Add priority groups (model, logic, and view)
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
30 |
class Logic(base.Logic): |
1bf4e904d5f5
Add priority groups (model, logic, and view)
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
31 |
"""Logic methods for the Priority Group model. |
1bf4e904d5f5
Add priority groups (model, logic, and view)
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
32 |
""" |
1bf4e904d5f5
Add priority groups (model, logic, and view)
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
33 |
|
1bf4e904d5f5
Add priority groups (model, logic, and view)
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
34 |
def __init__(self, model=soc.models.priority_group.PriorityGroup, |
1bf4e904d5f5
Add priority groups (model, logic, and view)
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
35 |
base_model=None, scope_logic=None): |
1bf4e904d5f5
Add priority groups (model, logic, and view)
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
36 |
"""Defines the name, key_name and model for this entity. |
1bf4e904d5f5
Add priority groups (model, logic, and view)
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
37 |
""" |
1bf4e904d5f5
Add priority groups (model, logic, and view)
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
38 |
|
2365
a66e1dd8ced7
Add pylint: disable-msg= where needed in Melange modules.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
2208
diff
changeset
|
39 |
# pylint: disable-msg=C0103 |
2208
1bf4e904d5f5
Add priority groups (model, logic, and view)
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
40 |
self.EMAIL = 'emails' |
1bf4e904d5f5
Add priority groups (model, logic, and view)
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
41 |
self.CONVERT = 'convert' |
1bf4e904d5f5
Add priority groups (model, logic, and view)
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
42 |
|
1bf4e904d5f5
Add priority groups (model, logic, and view)
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
43 |
self.groups = { |
1bf4e904d5f5
Add priority groups (model, logic, and view)
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
44 |
self.EMAIL: 'Send out emails', |
1bf4e904d5f5
Add priority groups (model, logic, and view)
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
45 |
self.CONVERT: 'Convert one entity to another type', |
1bf4e904d5f5
Add priority groups (model, logic, and view)
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
46 |
} |
1bf4e904d5f5
Add priority groups (model, logic, and view)
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
47 |
|
1bf4e904d5f5
Add priority groups (model, logic, and view)
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
48 |
super(Logic, self).__init__(model=model, base_model=base_model, |
1bf4e904d5f5
Add priority groups (model, logic, and view)
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
49 |
scope_logic=scope_logic) |
1bf4e904d5f5
Add priority groups (model, logic, and view)
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
50 |
|
1bf4e904d5f5
Add priority groups (model, logic, and view)
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
51 |
def getKeyValuesFromEntity(self, entity): |
1bf4e904d5f5
Add priority groups (model, logic, and view)
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
52 |
"""See base.Logic.getKeyValuesFromEntity. |
1bf4e904d5f5
Add priority groups (model, logic, and view)
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
53 |
""" |
1bf4e904d5f5
Add priority groups (model, logic, and view)
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
54 |
|
1bf4e904d5f5
Add priority groups (model, logic, and view)
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
55 |
return [entity.link_id] |
1bf4e904d5f5
Add priority groups (model, logic, and view)
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
56 |
|
1bf4e904d5f5
Add priority groups (model, logic, and view)
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
57 |
def getKeyValuesFromFields(self, fields): |
1bf4e904d5f5
Add priority groups (model, logic, and view)
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
58 |
"""See base.Logic.getKeyValuesFromFields. |
1bf4e904d5f5
Add priority groups (model, logic, and view)
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
59 |
""" |
1bf4e904d5f5
Add priority groups (model, logic, and view)
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
60 |
|
1bf4e904d5f5
Add priority groups (model, logic, and view)
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
61 |
return [fields['link_id']] |
1bf4e904d5f5
Add priority groups (model, logic, and view)
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
62 |
|
1bf4e904d5f5
Add priority groups (model, logic, and view)
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
63 |
def getKeyFieldNames(self): |
1bf4e904d5f5
Add priority groups (model, logic, and view)
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
64 |
"""See base.Logic.getKeyFieldNames. |
1bf4e904d5f5
Add priority groups (model, logic, and view)
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
65 |
""" |
1bf4e904d5f5
Add priority groups (model, logic, and view)
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
66 |
|
1bf4e904d5f5
Add priority groups (model, logic, and view)
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
67 |
return ['link_id'] |
1bf4e904d5f5
Add priority groups (model, logic, and view)
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
68 |
|
1bf4e904d5f5
Add priority groups (model, logic, and view)
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
69 |
def getGroup(self, key_name): |
1bf4e904d5f5
Add priority groups (model, logic, and view)
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
70 |
"""Return the specified Priority Group entity. |
1bf4e904d5f5
Add priority groups (model, logic, and view)
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
71 |
""" |
1bf4e904d5f5
Add priority groups (model, logic, and view)
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
72 |
|
1bf4e904d5f5
Add priority groups (model, logic, and view)
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
73 |
if key_name not in self.groups: |
1bf4e904d5f5
Add priority groups (model, logic, and view)
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
74 |
raise base.InvalidArgumentError("Unknown priority group %s." % key_name) |
1bf4e904d5f5
Add priority groups (model, logic, and view)
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
75 |
|
1bf4e904d5f5
Add priority groups (model, logic, and view)
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
76 |
group = self.getFromKeyName(key_name) |
1bf4e904d5f5
Add priority groups (model, logic, and view)
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
77 |
|
1bf4e904d5f5
Add priority groups (model, logic, and view)
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
78 |
if not group: |
1bf4e904d5f5
Add priority groups (model, logic, and view)
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
79 |
fields = { |
1bf4e904d5f5
Add priority groups (model, logic, and view)
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
80 |
'link_id': key_name, |
1bf4e904d5f5
Add priority groups (model, logic, and view)
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
81 |
'name': self.groups[key_name], |
1bf4e904d5f5
Add priority groups (model, logic, and view)
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
82 |
'priority': 0, |
1bf4e904d5f5
Add priority groups (model, logic, and view)
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
83 |
} |
1bf4e904d5f5
Add priority groups (model, logic, and view)
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
84 |
|
1bf4e904d5f5
Add priority groups (model, logic, and view)
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
85 |
group = self.updateOrCreateFromKeyName(fields, key_name) |
1bf4e904d5f5
Add priority groups (model, logic, and view)
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
86 |
|
1bf4e904d5f5
Add priority groups (model, logic, and view)
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
87 |
return group |
1bf4e904d5f5
Add priority groups (model, logic, and view)
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
88 |
|
1bf4e904d5f5
Add priority groups (model, logic, and view)
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
89 |
|
1bf4e904d5f5
Add priority groups (model, logic, and view)
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
90 |
logic = Logic() |