author | Lennard de Rijk <ljvderijk@gmail.com> |
Sun, 01 Feb 2009 17:31:09 +0000 | |
changeset 1159 | 3fefc88b0965 |
parent 1115 | 0a723ff3d27c |
child 1218 | 569a3fe9cb88 |
permissions | -rw-r--r-- |
1051
c532dd9def48
Create a new Tossed layer in the MVC
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
1 |
#!/usr/bin/python2.5 |
c532dd9def48
Create a new Tossed layer in the MVC
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
2 |
# |
c532dd9def48
Create a new Tossed layer in the MVC
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
3 |
# Copyright 2008 the Melange authors. |
c532dd9def48
Create a new Tossed layer in the MVC
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
4 |
# |
c532dd9def48
Create a new Tossed layer in the MVC
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
5 |
# Licensed under the Apache License, Version 2.0 (the "License"); |
c532dd9def48
Create a new Tossed layer in the MVC
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
6 |
# you may not use this file except in compliance with the License. |
c532dd9def48
Create a new Tossed layer in the MVC
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
7 |
# You may obtain a copy of the License at |
c532dd9def48
Create a new Tossed layer in the MVC
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
8 |
# |
c532dd9def48
Create a new Tossed layer in the MVC
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
9 |
# http://www.apache.org/licenses/LICENSE-2.0 |
c532dd9def48
Create a new Tossed layer in the MVC
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
10 |
# |
c532dd9def48
Create a new Tossed layer in the MVC
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
11 |
# Unless required by applicable law or agreed to in writing, software |
c532dd9def48
Create a new Tossed layer in the MVC
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
12 |
# distributed under the License is distributed on an "AS IS" BASIS, |
c532dd9def48
Create a new Tossed layer in the MVC
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
13 |
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
c532dd9def48
Create a new Tossed layer in the MVC
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
14 |
# See the License for the specific language governing permissions and |
c532dd9def48
Create a new Tossed layer in the MVC
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
15 |
# limitations under the License. |
c532dd9def48
Create a new Tossed layer in the MVC
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
16 |
|
1053
3b9552cf748a
Rename the confusing Tossed Model class to PresenceWithToS.
Todd Larsen <tlarsen@google.com>
parents:
1051
diff
changeset
|
17 |
"""Views for PresenceWithToS. |
1051
c532dd9def48
Create a new Tossed layer in the MVC
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
18 |
""" |
c532dd9def48
Create a new Tossed layer in the MVC
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
19 |
|
c532dd9def48
Create a new Tossed layer in the MVC
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
20 |
__authors__ = [ |
c532dd9def48
Create a new Tossed layer in the MVC
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
21 |
'"Sverre Rabbelier" <sverre@rabbelier.nl>', |
c532dd9def48
Create a new Tossed layer in the MVC
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
22 |
] |
c532dd9def48
Create a new Tossed layer in the MVC
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
23 |
|
c532dd9def48
Create a new Tossed layer in the MVC
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
24 |
|
c532dd9def48
Create a new Tossed layer in the MVC
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
25 |
from google.appengine.ext import db |
c532dd9def48
Create a new Tossed layer in the MVC
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
26 |
|
c532dd9def48
Create a new Tossed layer in the MVC
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
27 |
from django import forms |
c532dd9def48
Create a new Tossed layer in the MVC
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
28 |
from django.utils.translation import ugettext |
c532dd9def48
Create a new Tossed layer in the MVC
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
29 |
|
c532dd9def48
Create a new Tossed layer in the MVC
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
30 |
from soc.logic import dicts |
c532dd9def48
Create a new Tossed layer in the MVC
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
31 |
from soc.logic.models import document as document_logic |
c532dd9def48
Create a new Tossed layer in the MVC
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
32 |
from soc.views.models import presence |
c532dd9def48
Create a new Tossed layer in the MVC
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
33 |
|
1053
3b9552cf748a
Rename the confusing Tossed Model class to PresenceWithToS.
Todd Larsen <tlarsen@google.com>
parents:
1051
diff
changeset
|
34 |
import soc.logic.models.presence_with_tos |
1051
c532dd9def48
Create a new Tossed layer in the MVC
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
35 |
import soc.models.work |
c532dd9def48
Create a new Tossed layer in the MVC
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
36 |
|
c532dd9def48
Create a new Tossed layer in the MVC
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
37 |
|
c532dd9def48
Create a new Tossed layer in the MVC
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
38 |
class View(presence.View): |
1053
3b9552cf748a
Rename the confusing Tossed Model class to PresenceWithToS.
Todd Larsen <tlarsen@google.com>
parents:
1051
diff
changeset
|
39 |
"""View methods for the PresenceWithToS model. |
1051
c532dd9def48
Create a new Tossed layer in the MVC
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
40 |
""" |
c532dd9def48
Create a new Tossed layer in the MVC
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
41 |
|
c532dd9def48
Create a new Tossed layer in the MVC
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
42 |
def __init__(self, params=None): |
c532dd9def48
Create a new Tossed layer in the MVC
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
43 |
"""Defines the fields and methods required for the base View class |
c532dd9def48
Create a new Tossed layer in the MVC
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
44 |
to provide the user with list, public, create, edit and delete views. |
c532dd9def48
Create a new Tossed layer in the MVC
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
45 |
|
c532dd9def48
Create a new Tossed layer in the MVC
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
46 |
Params: |
c532dd9def48
Create a new Tossed layer in the MVC
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
47 |
params: a dict with params for this View |
c532dd9def48
Create a new Tossed layer in the MVC
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
48 |
""" |
c532dd9def48
Create a new Tossed layer in the MVC
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
49 |
|
c532dd9def48
Create a new Tossed layer in the MVC
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
50 |
new_params = {} |
1053
3b9552cf748a
Rename the confusing Tossed Model class to PresenceWithToS.
Todd Larsen <tlarsen@google.com>
parents:
1051
diff
changeset
|
51 |
new_params['logic'] = soc.logic.models.presence_with_tos.logic |
1051
c532dd9def48
Create a new Tossed layer in the MVC
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
52 |
|
c532dd9def48
Create a new Tossed layer in the MVC
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
53 |
new_params['create_extra_dynafields'] = { |
c532dd9def48
Create a new Tossed layer in the MVC
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
54 |
'tos_link_id': forms.CharField(required=False, |
c532dd9def48
Create a new Tossed layer in the MVC
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
55 |
label=ugettext('Terms of Service Document link ID'), |
c532dd9def48
Create a new Tossed layer in the MVC
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
56 |
help_text=soc.models.work.Work.link_id.help_text), |
c532dd9def48
Create a new Tossed layer in the MVC
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
57 |
} |
c532dd9def48
Create a new Tossed layer in the MVC
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
58 |
|
c532dd9def48
Create a new Tossed layer in the MVC
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
59 |
params = dicts.merge(params, new_params, sub_merge=True) |
c532dd9def48
Create a new Tossed layer in the MVC
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
60 |
|
c532dd9def48
Create a new Tossed layer in the MVC
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
61 |
super(View, self).__init__(params=params) |
c532dd9def48
Create a new Tossed layer in the MVC
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
62 |
|
c532dd9def48
Create a new Tossed layer in the MVC
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
63 |
def _editGet(self, request, entity, form): |
c532dd9def48
Create a new Tossed layer in the MVC
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
64 |
"""See base.View._editGet(). |
c532dd9def48
Create a new Tossed layer in the MVC
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
65 |
""" |
c532dd9def48
Create a new Tossed layer in the MVC
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
66 |
|
c532dd9def48
Create a new Tossed layer in the MVC
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
67 |
try: |
c532dd9def48
Create a new Tossed layer in the MVC
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
68 |
if entity.tos: |
c532dd9def48
Create a new Tossed layer in the MVC
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
69 |
form.fields['tos_link_id'].initial = entity.tos.link_id |
c532dd9def48
Create a new Tossed layer in the MVC
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
70 |
except db.Error: |
c532dd9def48
Create a new Tossed layer in the MVC
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
71 |
pass |
c532dd9def48
Create a new Tossed layer in the MVC
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
72 |
|
c532dd9def48
Create a new Tossed layer in the MVC
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
73 |
super(View, self)._editGet(request, entity, form) |
c532dd9def48
Create a new Tossed layer in the MVC
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
74 |
|
c532dd9def48
Create a new Tossed layer in the MVC
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
75 |
def _editPost(self, request, entity, fields): |
c532dd9def48
Create a new Tossed layer in the MVC
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
76 |
"""See base.View._editPost(). |
c532dd9def48
Create a new Tossed layer in the MVC
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
77 |
""" |
c532dd9def48
Create a new Tossed layer in the MVC
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
78 |
|
1115
0a723ff3d27c
Cleanups in base.Logic
Sverre Rabbelier <srabbelier@gmail.com>
parents:
1101
diff
changeset
|
79 |
key_fields = self._logic.getKeyFieldsFromFields(fields) |
0a723ff3d27c
Cleanups in base.Logic
Sverre Rabbelier <srabbelier@gmail.com>
parents:
1101
diff
changeset
|
80 |
scope_path = self._logic.getKeyNameFromFields(key_fields) |
1051
c532dd9def48
Create a new Tossed layer in the MVC
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
81 |
|
1115
0a723ff3d27c
Cleanups in base.Logic
Sverre Rabbelier <srabbelier@gmail.com>
parents:
1101
diff
changeset
|
82 |
key_fields = { |
0a723ff3d27c
Cleanups in base.Logic
Sverre Rabbelier <srabbelier@gmail.com>
parents:
1101
diff
changeset
|
83 |
'scope_path': scope_path, |
0a723ff3d27c
Cleanups in base.Logic
Sverre Rabbelier <srabbelier@gmail.com>
parents:
1101
diff
changeset
|
84 |
'link_id': fields['tos_link_id'], |
0a723ff3d27c
Cleanups in base.Logic
Sverre Rabbelier <srabbelier@gmail.com>
parents:
1101
diff
changeset
|
85 |
'prefix': self._params['document_prefix'], |
0a723ff3d27c
Cleanups in base.Logic
Sverre Rabbelier <srabbelier@gmail.com>
parents:
1101
diff
changeset
|
86 |
} |
1051
c532dd9def48
Create a new Tossed layer in the MVC
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
87 |
|
c532dd9def48
Create a new Tossed layer in the MVC
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
88 |
# TODO notify the user if tos_doc is not found |
1115
0a723ff3d27c
Cleanups in base.Logic
Sverre Rabbelier <srabbelier@gmail.com>
parents:
1101
diff
changeset
|
89 |
tos_doc = document_logic.logic.getFromKeyFields(key_fields) |
1051
c532dd9def48
Create a new Tossed layer in the MVC
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
90 |
|
c532dd9def48
Create a new Tossed layer in the MVC
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
91 |
fields['tos'] = tos_doc |
c532dd9def48
Create a new Tossed layer in the MVC
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
92 |
|
c532dd9def48
Create a new Tossed layer in the MVC
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
93 |
super(View, self)._editPost(request, entity, fields) |