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