author | Lennard de Rijk <ljvderijk@gmail.com> |
Sat, 24 Oct 2009 15:14:11 -0700 | |
changeset 3036 | c703f3802841 |
parent 2427 | 0dee663d6582 |
permissions | -rw-r--r-- |
308
740090cd17c9
Added invididual model logic files
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
1 |
#!/usr/bin/python2.5 |
740090cd17c9
Added invididual model logic files
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. |
308
740090cd17c9
Added invididual model logic files
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
4 |
# |
740090cd17c9
Added invididual model logic files
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
5 |
# Licensed under the Apache License, Version 2.0 (the "License"); |
740090cd17c9
Added invididual model logic files
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
6 |
# you may not use this file except in compliance with the License. |
740090cd17c9
Added invididual model logic files
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
7 |
# You may obtain a copy of the License at |
740090cd17c9
Added invididual model logic files
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
8 |
# |
740090cd17c9
Added invididual model logic files
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
9 |
# http://www.apache.org/licenses/LICENSE-2.0 |
740090cd17c9
Added invididual model logic files
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
10 |
# |
740090cd17c9
Added invididual model logic files
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
11 |
# Unless required by applicable law or agreed to in writing, software |
740090cd17c9
Added invididual model logic files
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
12 |
# distributed under the License is distributed on an "AS IS" BASIS, |
740090cd17c9
Added invididual model logic files
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
13 |
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
740090cd17c9
Added invididual model logic files
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
14 |
# See the License for the specific language governing permissions and |
740090cd17c9
Added invididual model logic files
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
15 |
# limitations under the License. |
740090cd17c9
Added invididual model logic files
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
16 |
|
740090cd17c9
Added invididual model logic files
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
17 |
"""Document (Model) query functions. |
740090cd17c9
Added invididual model logic files
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
18 |
""" |
740090cd17c9
Added invididual model logic files
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
19 |
|
740090cd17c9
Added invididual model logic files
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>', |
308
740090cd17c9
Added invididual model logic files
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
22 |
] |
740090cd17c9
Added invididual model logic files
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
23 |
|
740090cd17c9
Added invididual model logic files
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
24 |
|
1019
0cd056f2c739
Flush cache if user makes a document featured
Sverre Rabbelier <srabbelier@gmail.com>
parents:
678
diff
changeset
|
25 |
from soc.cache import sidebar |
1419
5d0f80ad7b9f
Add caching to the homepage
Sverre Rabbelier <srabbelier@gmail.com>
parents:
1308
diff
changeset
|
26 |
from soc.cache import home |
535
9045b8888772
Refactor classes in soc/logic/models to make more use of inheritance. Add
Todd Larsen <tlarsen@google.com>
parents:
530
diff
changeset
|
27 |
from soc.logic.models import work |
678
b982d9175605
Added a linkable logic module
Sverre Rabbelier <srabbelier@gmail.com>
parents:
655
diff
changeset
|
28 |
from soc.logic.models import linkable as linkable_logic |
316
9efdc7bc3565
Add missing blank lines between imports and sort all of the imports.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
308
diff
changeset
|
29 |
|
308
740090cd17c9
Added invididual model logic files
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
30 |
import soc.models.document |
481
94834a1e6c01
Attempt to rename User.id to User.account, in preparation for making User be
Todd Larsen <tlarsen@google.com>
parents:
432
diff
changeset
|
31 |
import soc.models.work |
308
740090cd17c9
Added invididual model logic files
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
32 |
|
740090cd17c9
Added invididual model logic files
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
33 |
|
535
9045b8888772
Refactor classes in soc/logic/models to make more use of inheritance. Add
Todd Larsen <tlarsen@google.com>
parents:
530
diff
changeset
|
34 |
class Logic(work.Logic): |
308
740090cd17c9
Added invididual model logic files
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
35 |
"""Logic methods for the Document model |
740090cd17c9
Added invididual model logic files
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
36 |
""" |
740090cd17c9
Added invididual model logic files
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
37 |
|
535
9045b8888772
Refactor classes in soc/logic/models to make more use of inheritance. Add
Todd Larsen <tlarsen@google.com>
parents:
530
diff
changeset
|
38 |
def __init__(self, model=soc.models.document.Document, |
678
b982d9175605
Added a linkable logic module
Sverre Rabbelier <srabbelier@gmail.com>
parents:
655
diff
changeset
|
39 |
base_model=soc.models.work.Work, scope_logic=linkable_logic): |
308
740090cd17c9
Added invididual model logic files
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
40 |
"""Defines the name, key_name and model for this entity. |
740090cd17c9
Added invididual model logic files
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
41 |
""" |
655
9635cbaa2dcd
Cleanups to the logic module
Sverre Rabbelier <srabbelier@gmail.com>
parents:
535
diff
changeset
|
42 |
|
678
b982d9175605
Added a linkable logic module
Sverre Rabbelier <srabbelier@gmail.com>
parents:
655
diff
changeset
|
43 |
super(Logic, self).__init__(model=model, base_model=base_model, |
b982d9175605
Added a linkable logic module
Sverre Rabbelier <srabbelier@gmail.com>
parents:
655
diff
changeset
|
44 |
scope_logic=scope_logic) |
410
2af7f84f4fc7
Moved all key_name related things to the logic modules
Sverre Rabbelier <srabbelier@gmail.com>
parents:
316
diff
changeset
|
45 |
|
1115
0a723ff3d27c
Cleanups in base.Logic
Sverre Rabbelier <srabbelier@gmail.com>
parents:
1106
diff
changeset
|
46 |
def getKeyValuesFromEntity(self, entity): |
1095
0122dc66e5d2
Add access control to document model and view
Sverre Rabbelier <srabbelier@gmail.com>
parents:
1019
diff
changeset
|
47 |
"""See base.Logic.getKeyNameValues. |
0122dc66e5d2
Add access control to document model and view
Sverre Rabbelier <srabbelier@gmail.com>
parents:
1019
diff
changeset
|
48 |
""" |
0122dc66e5d2
Add access control to document model and view
Sverre Rabbelier <srabbelier@gmail.com>
parents:
1019
diff
changeset
|
49 |
|
0122dc66e5d2
Add access control to document model and view
Sverre Rabbelier <srabbelier@gmail.com>
parents:
1019
diff
changeset
|
50 |
return [entity.prefix, entity.scope_path, entity.link_id] |
0122dc66e5d2
Add access control to document model and view
Sverre Rabbelier <srabbelier@gmail.com>
parents:
1019
diff
changeset
|
51 |
|
0122dc66e5d2
Add access control to document model and view
Sverre Rabbelier <srabbelier@gmail.com>
parents:
1019
diff
changeset
|
52 |
def getKeyValuesFromFields(self, fields): |
0122dc66e5d2
Add access control to document model and view
Sverre Rabbelier <srabbelier@gmail.com>
parents:
1019
diff
changeset
|
53 |
"""See base.Logic.getKeyValuesFromFields. |
0122dc66e5d2
Add access control to document model and view
Sverre Rabbelier <srabbelier@gmail.com>
parents:
1019
diff
changeset
|
54 |
""" |
0122dc66e5d2
Add access control to document model and view
Sverre Rabbelier <srabbelier@gmail.com>
parents:
1019
diff
changeset
|
55 |
|
0122dc66e5d2
Add access control to document model and view
Sverre Rabbelier <srabbelier@gmail.com>
parents:
1019
diff
changeset
|
56 |
return [fields['prefix'], fields['scope_path'], fields['link_id']] |
0122dc66e5d2
Add access control to document model and view
Sverre Rabbelier <srabbelier@gmail.com>
parents:
1019
diff
changeset
|
57 |
|
0122dc66e5d2
Add access control to document model and view
Sverre Rabbelier <srabbelier@gmail.com>
parents:
1019
diff
changeset
|
58 |
def getKeyFieldNames(self): |
0122dc66e5d2
Add access control to document model and view
Sverre Rabbelier <srabbelier@gmail.com>
parents:
1019
diff
changeset
|
59 |
"""See base.Logic.getKeyFieldNames. |
0122dc66e5d2
Add access control to document model and view
Sverre Rabbelier <srabbelier@gmail.com>
parents:
1019
diff
changeset
|
60 |
""" |
0122dc66e5d2
Add access control to document model and view
Sverre Rabbelier <srabbelier@gmail.com>
parents:
1019
diff
changeset
|
61 |
|
0122dc66e5d2
Add access control to document model and view
Sverre Rabbelier <srabbelier@gmail.com>
parents:
1019
diff
changeset
|
62 |
return ['prefix', 'scope_path', 'link_id'] |
0122dc66e5d2
Add access control to document model and view
Sverre Rabbelier <srabbelier@gmail.com>
parents:
1019
diff
changeset
|
63 |
|
1594
b80bf089d5f7
Display a notice if the entity cannot be deleted
Sverre Rabbelier <srabbelier@gmail.com>
parents:
1517
diff
changeset
|
64 |
def isDeletable(self, entity): |
b80bf089d5f7
Display a notice if the entity cannot be deleted
Sverre Rabbelier <srabbelier@gmail.com>
parents:
1517
diff
changeset
|
65 |
"""See base.Logic.isDeletable. |
b80bf089d5f7
Display a notice if the entity cannot be deleted
Sverre Rabbelier <srabbelier@gmail.com>
parents:
1517
diff
changeset
|
66 |
""" |
b80bf089d5f7
Display a notice if the entity cannot be deleted
Sverre Rabbelier <srabbelier@gmail.com>
parents:
1517
diff
changeset
|
67 |
|
1669
47c1048fc4ef
Fixed a bug in document logic
Sverre Rabbelier <srabbelier@gmail.com>
parents:
1594
diff
changeset
|
68 |
return not entity.home_for |
1594
b80bf089d5f7
Display a notice if the entity cannot be deleted
Sverre Rabbelier <srabbelier@gmail.com>
parents:
1517
diff
changeset
|
69 |
|
1517
a467d13e34ea
Pass _updateField the entity_properties dict instead of just the value
Sverre Rabbelier <srabbelier@gmail.com>
parents:
1419
diff
changeset
|
70 |
def _updateField(self, entity, entity_properties, name): |
2427
0dee663d6582
Fixed docstring in Document Logic.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
1669
diff
changeset
|
71 |
"""Special logic for Document. |
0dee663d6582
Fixed docstring in Document Logic.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
1669
diff
changeset
|
72 |
|
0dee663d6582
Fixed docstring in Document Logic.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
1669
diff
changeset
|
73 |
- Flush the sidebar when a document is featured. |
0dee663d6582
Fixed docstring in Document Logic.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
1669
diff
changeset
|
74 |
- Remove the document from the homepage cache when the home_for is updated |
1019
0cd056f2c739
Flush cache if user makes a document featured
Sverre Rabbelier <srabbelier@gmail.com>
parents:
678
diff
changeset
|
75 |
""" |
0cd056f2c739
Flush cache if user makes a document featured
Sverre Rabbelier <srabbelier@gmail.com>
parents:
678
diff
changeset
|
76 |
|
1517
a467d13e34ea
Pass _updateField the entity_properties dict instead of just the value
Sverre Rabbelier <srabbelier@gmail.com>
parents:
1419
diff
changeset
|
77 |
value = entity_properties[name] |
a467d13e34ea
Pass _updateField the entity_properties dict instead of just the value
Sverre Rabbelier <srabbelier@gmail.com>
parents:
1419
diff
changeset
|
78 |
|
1019
0cd056f2c739
Flush cache if user makes a document featured
Sverre Rabbelier <srabbelier@gmail.com>
parents:
678
diff
changeset
|
79 |
if (name == 'is_featured') and (entity.is_featured != value): |
0cd056f2c739
Flush cache if user makes a document featured
Sverre Rabbelier <srabbelier@gmail.com>
parents:
678
diff
changeset
|
80 |
sidebar.flush() |
0cd056f2c739
Flush cache if user makes a document featured
Sverre Rabbelier <srabbelier@gmail.com>
parents:
678
diff
changeset
|
81 |
|
1419
5d0f80ad7b9f
Add caching to the homepage
Sverre Rabbelier <srabbelier@gmail.com>
parents:
1308
diff
changeset
|
82 |
home_for = entity.home_for |
5d0f80ad7b9f
Add caching to the homepage
Sverre Rabbelier <srabbelier@gmail.com>
parents:
1308
diff
changeset
|
83 |
|
5d0f80ad7b9f
Add caching to the homepage
Sverre Rabbelier <srabbelier@gmail.com>
parents:
1308
diff
changeset
|
84 |
if (name != 'home_for') and home_for: |
5d0f80ad7b9f
Add caching to the homepage
Sverre Rabbelier <srabbelier@gmail.com>
parents:
1308
diff
changeset
|
85 |
home.flush(home_for) |
5d0f80ad7b9f
Add caching to the homepage
Sverre Rabbelier <srabbelier@gmail.com>
parents:
1308
diff
changeset
|
86 |
|
1019
0cd056f2c739
Flush cache if user makes a document featured
Sverre Rabbelier <srabbelier@gmail.com>
parents:
678
diff
changeset
|
87 |
return True |
0cd056f2c739
Flush cache if user makes a document featured
Sverre Rabbelier <srabbelier@gmail.com>
parents:
678
diff
changeset
|
88 |
|
308
740090cd17c9
Added invididual model logic files
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
89 |
|
740090cd17c9
Added invididual model logic files
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
90 |
logic = Logic() |