author | Sverre Rabbelier <srabbelier@gmail.com> |
Sat, 06 Dec 2008 11:21:41 +0000 | |
changeset 671 | 2c02178037ff |
parent 662 | 0e89b027b140 |
child 710 | edb5dbb1dea7 |
permissions | -rw-r--r-- |
400
8f07048d84ef
Added a generic version of the Document views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
1 |
#!/usr/bin/python2.5 |
8f07048d84ef
Added a generic version of the Document views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
2 |
# |
8f07048d84ef
Added a generic version of the Document views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
3 |
# Copyright 2008 the Melange authors. |
8f07048d84ef
Added a generic version of the Document views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
4 |
# |
8f07048d84ef
Added a generic version of the Document views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
5 |
# Licensed under the Apache License, Version 2.0 (the "License"); |
8f07048d84ef
Added a generic version of the Document views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
6 |
# you may not use this file except in compliance with the License. |
8f07048d84ef
Added a generic version of the Document views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
7 |
# You may obtain a copy of the License at |
8f07048d84ef
Added a generic version of the Document views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
8 |
# |
8f07048d84ef
Added a generic version of the Document views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
9 |
# http://www.apache.org/licenses/LICENSE-2.0 |
8f07048d84ef
Added a generic version of the Document views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
10 |
# |
8f07048d84ef
Added a generic version of the Document views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
11 |
# Unless required by applicable law or agreed to in writing, software |
8f07048d84ef
Added a generic version of the Document views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
12 |
# distributed under the License is distributed on an "AS IS" BASIS, |
8f07048d84ef
Added a generic version of the Document views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
13 |
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
8f07048d84ef
Added a generic version of the Document views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
14 |
# See the License for the specific language governing permissions and |
8f07048d84ef
Added a generic version of the Document views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
15 |
# limitations under the License. |
8f07048d84ef
Added a generic version of the Document views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
16 |
|
404
44223e50e1fc
Added a Host profile and generalized some views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
402
diff
changeset
|
17 |
"""Views for Host profiles. |
400
8f07048d84ef
Added a generic version of the Document views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
18 |
""" |
8f07048d84ef
Added a generic version of the Document views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
19 |
|
8f07048d84ef
Added a generic version of the Document views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
20 |
__authors__ = [ |
429
e50e18936f06
Fixed typo in e-mail address
Sverre Rabbelier <srabbelier@gmail.com>
parents:
413
diff
changeset
|
21 |
'"Sverre Rabbelier" <sverre@rabbelier.nl>', |
400
8f07048d84ef
Added a generic version of the Document views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
22 |
] |
8f07048d84ef
Added a generic version of the Document views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
23 |
|
8f07048d84ef
Added a generic version of the Document views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
24 |
|
8f07048d84ef
Added a generic version of the Document views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
25 |
from soc.logic import dicts |
575 | 26 |
from soc.logic.models import user as user_logic |
27 |
from soc.logic.models import sponsor as sponsor_logic |
|
400
8f07048d84ef
Added a generic version of the Document views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
28 |
from soc.views import helper |
494
5e9c656a1b68
Refactored SiteMap to be generic
Sverre Rabbelier <srabbelier@gmail.com>
parents:
493
diff
changeset
|
29 |
from soc.views.models import role |
662
0e89b027b140
Make use of the new generic key_name by lookup up scope_path
Sverre Rabbelier <srabbelier@gmail.com>
parents:
657
diff
changeset
|
30 |
from soc.views.models import sponsor as sponsor_view |
617
9cc42981d40a
Now invited users can create a new Host profile
Sverre Rabbelier <srabbelier@gmail.com>
parents:
616
diff
changeset
|
31 |
from soc.views.helper import access |
400
8f07048d84ef
Added a generic version of the Document views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
32 |
|
404
44223e50e1fc
Added a Host profile and generalized some views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
402
diff
changeset
|
33 |
import soc.models.host |
44223e50e1fc
Added a Host profile and generalized some views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
402
diff
changeset
|
34 |
import soc.logic.models.host |
400
8f07048d84ef
Added a generic version of the Document views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
35 |
import soc.views.helper |
560
a32be584ee04
Requests are almost working now
Sverre Rabbelier <srabbelier@gmail.com>
parents:
554
diff
changeset
|
36 |
import soc.views.models.sponsor |
400
8f07048d84ef
Added a generic version of the Document views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
37 |
|
404
44223e50e1fc
Added a Host profile and generalized some views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
402
diff
changeset
|
38 |
|
408
7cd6bdfbf95c
Inherit from BaseForm in all forms instead of from DbModelForm. This change doesn't include changes to templates and usage of as_table everywhere (work in progress).
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
406
diff
changeset
|
39 |
class CreateForm(helper.forms.BaseForm): |
404
44223e50e1fc
Added a Host profile and generalized some views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
402
diff
changeset
|
40 |
"""Django form displayed when creating a Host. |
400
8f07048d84ef
Added a generic version of the Document views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
41 |
""" |
8f07048d84ef
Added a generic version of the Document views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
42 |
|
404
44223e50e1fc
Added a Host profile and generalized some views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
402
diff
changeset
|
43 |
class Meta: |
44223e50e1fc
Added a Host profile and generalized some views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
402
diff
changeset
|
44 |
"""Inner Meta class that defines some behavior for the form. |
44223e50e1fc
Added a Host profile and generalized some views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
402
diff
changeset
|
45 |
""" |
400
8f07048d84ef
Added a generic version of the Document views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
46 |
|
404
44223e50e1fc
Added a Host profile and generalized some views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
402
diff
changeset
|
47 |
#: db.Model subclass for which the form will gather information |
44223e50e1fc
Added a Host profile and generalized some views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
402
diff
changeset
|
48 |
model = soc.models.host.Host |
400
8f07048d84ef
Added a generic version of the Document views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
49 |
|
8f07048d84ef
Added a generic version of the Document views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
50 |
#: list of model fields which will *not* be gathered by the form |
575 | 51 |
exclude = ['scope', 'user'] |
404
44223e50e1fc
Added a Host profile and generalized some views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
402
diff
changeset
|
52 |
|
44223e50e1fc
Added a Host profile and generalized some views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
402
diff
changeset
|
53 |
def clean_empty(self, field): |
44223e50e1fc
Added a Host profile and generalized some views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
402
diff
changeset
|
54 |
data = self.cleaned_data.get(field) |
44223e50e1fc
Added a Host profile and generalized some views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
402
diff
changeset
|
55 |
if not data or data == u'': |
44223e50e1fc
Added a Host profile and generalized some views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
402
diff
changeset
|
56 |
return None |
44223e50e1fc
Added a Host profile and generalized some views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
402
diff
changeset
|
57 |
|
44223e50e1fc
Added a Host profile and generalized some views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
402
diff
changeset
|
58 |
return data |
400
8f07048d84ef
Added a generic version of the Document views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
59 |
|
404
44223e50e1fc
Added a Host profile and generalized some views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
402
diff
changeset
|
60 |
def clean_home_page(self): |
44223e50e1fc
Added a Host profile and generalized some views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
402
diff
changeset
|
61 |
return self.clean_empty('home_page') |
400
8f07048d84ef
Added a generic version of the Document views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
62 |
|
404
44223e50e1fc
Added a Host profile and generalized some views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
402
diff
changeset
|
63 |
def clean_blog(self): |
44223e50e1fc
Added a Host profile and generalized some views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
402
diff
changeset
|
64 |
return self.clean_empty('blog') |
44223e50e1fc
Added a Host profile and generalized some views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
402
diff
changeset
|
65 |
|
44223e50e1fc
Added a Host profile and generalized some views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
402
diff
changeset
|
66 |
def clean_photo_url(self): |
44223e50e1fc
Added a Host profile and generalized some views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
402
diff
changeset
|
67 |
return self.clean_empty('photo_url') |
400
8f07048d84ef
Added a generic version of the Document views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
68 |
|
8f07048d84ef
Added a generic version of the Document views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
69 |
|
8f07048d84ef
Added a generic version of the Document views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
70 |
class EditForm(CreateForm): |
404
44223e50e1fc
Added a Host profile and generalized some views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
402
diff
changeset
|
71 |
"""Django form displayed when editing a Host. |
400
8f07048d84ef
Added a generic version of the Document views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
72 |
""" |
8f07048d84ef
Added a generic version of the Document views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
73 |
|
431
96b6ee5efdc3
Added a missing 'pass' statement
Sverre Rabbelier <srabbelier@gmail.com>
parents:
429
diff
changeset
|
74 |
pass |
96b6ee5efdc3
Added a missing 'pass' statement
Sverre Rabbelier <srabbelier@gmail.com>
parents:
429
diff
changeset
|
75 |
|
657
c781de4f6d39
Rename role.RoleView to role.View
Sverre Rabbelier <srabbelier@gmail.com>
parents:
656
diff
changeset
|
76 |
class View(role.View): |
499
d22e4fe8e64b
Fix missing dots in doc strings and some other doc string corrections.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
497
diff
changeset
|
77 |
"""View methods for the Host model. |
400
8f07048d84ef
Added a generic version of the Document views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
78 |
""" |
8f07048d84ef
Added a generic version of the Document views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
79 |
|
656
a76f1b443ea4
Cleanups in the views module
Sverre Rabbelier <srabbelier@gmail.com>
parents:
642
diff
changeset
|
80 |
def __init__(self, params=None): |
400
8f07048d84ef
Added a generic version of the Document views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
81 |
"""Defines the fields and methods required for the base View class |
8f07048d84ef
Added a generic version of the Document views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
82 |
to provide the user with list, public, create, edit and delete views. |
8f07048d84ef
Added a generic version of the Document views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
83 |
|
8f07048d84ef
Added a generic version of the Document views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
84 |
Params: |
656
a76f1b443ea4
Cleanups in the views module
Sverre Rabbelier <srabbelier@gmail.com>
parents:
642
diff
changeset
|
85 |
params: a dict with params for this View |
400
8f07048d84ef
Added a generic version of the Document views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
86 |
""" |
8f07048d84ef
Added a generic version of the Document views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
87 |
|
617
9cc42981d40a
Now invited users can create a new Host profile
Sverre Rabbelier <srabbelier@gmail.com>
parents:
616
diff
changeset
|
88 |
rights = {} |
9cc42981d40a
Now invited users can create a new Host profile
Sverre Rabbelier <srabbelier@gmail.com>
parents:
616
diff
changeset
|
89 |
rights['edit'] = [access.checkIsInvited] |
9cc42981d40a
Now invited users can create a new Host profile
Sverre Rabbelier <srabbelier@gmail.com>
parents:
616
diff
changeset
|
90 |
|
656
a76f1b443ea4
Cleanups in the views module
Sverre Rabbelier <srabbelier@gmail.com>
parents:
642
diff
changeset
|
91 |
new_params = {} |
a76f1b443ea4
Cleanups in the views module
Sverre Rabbelier <srabbelier@gmail.com>
parents:
642
diff
changeset
|
92 |
new_params['rights'] = rights |
a76f1b443ea4
Cleanups in the views module
Sverre Rabbelier <srabbelier@gmail.com>
parents:
642
diff
changeset
|
93 |
new_params['logic'] = soc.logic.models.host.logic |
400
8f07048d84ef
Added a generic version of the Document views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
94 |
|
662
0e89b027b140
Make use of the new generic key_name by lookup up scope_path
Sverre Rabbelier <srabbelier@gmail.com>
parents:
657
diff
changeset
|
95 |
new_params['scope_view'] = sponsor_view |
0e89b027b140
Make use of the new generic key_name by lookup up scope_path
Sverre Rabbelier <srabbelier@gmail.com>
parents:
657
diff
changeset
|
96 |
|
656
a76f1b443ea4
Cleanups in the views module
Sverre Rabbelier <srabbelier@gmail.com>
parents:
642
diff
changeset
|
97 |
new_params['logic'] = soc.logic.models.host.logic |
a76f1b443ea4
Cleanups in the views module
Sverre Rabbelier <srabbelier@gmail.com>
parents:
642
diff
changeset
|
98 |
new_params['group_view'] = soc.views.models.sponsor.view |
a76f1b443ea4
Cleanups in the views module
Sverre Rabbelier <srabbelier@gmail.com>
parents:
642
diff
changeset
|
99 |
new_params['invite_filter'] = {'group_ln': 'link_id'} |
495
87afae6e4c51
Added basic 'invite' functionality
Sverre Rabbelier <srabbelier@gmail.com>
parents:
494
diff
changeset
|
100 |
|
656
a76f1b443ea4
Cleanups in the views module
Sverre Rabbelier <srabbelier@gmail.com>
parents:
642
diff
changeset
|
101 |
new_params['name'] = "Host" |
a76f1b443ea4
Cleanups in the views module
Sverre Rabbelier <srabbelier@gmail.com>
parents:
642
diff
changeset
|
102 |
new_params['name_short'] = "Host" |
a76f1b443ea4
Cleanups in the views module
Sverre Rabbelier <srabbelier@gmail.com>
parents:
642
diff
changeset
|
103 |
new_params['name_plural'] = "Hosts" |
a76f1b443ea4
Cleanups in the views module
Sverre Rabbelier <srabbelier@gmail.com>
parents:
642
diff
changeset
|
104 |
new_params['url_name'] = "host" |
a76f1b443ea4
Cleanups in the views module
Sverre Rabbelier <srabbelier@gmail.com>
parents:
642
diff
changeset
|
105 |
new_params['module_name'] = "host" |
400
8f07048d84ef
Added a generic version of the Document views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
106 |
|
656
a76f1b443ea4
Cleanups in the views module
Sverre Rabbelier <srabbelier@gmail.com>
parents:
642
diff
changeset
|
107 |
new_params['edit_form'] = EditForm |
a76f1b443ea4
Cleanups in the views module
Sverre Rabbelier <srabbelier@gmail.com>
parents:
642
diff
changeset
|
108 |
new_params['create_form'] = CreateForm |
400
8f07048d84ef
Added a generic version of the Document views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
109 |
|
656
a76f1b443ea4
Cleanups in the views module
Sverre Rabbelier <srabbelier@gmail.com>
parents:
642
diff
changeset
|
110 |
params = dicts.merge(params, new_params) |
400
8f07048d84ef
Added a generic version of the Document views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
111 |
|
657
c781de4f6d39
Rename role.RoleView to role.View
Sverre Rabbelier <srabbelier@gmail.com>
parents:
656
diff
changeset
|
112 |
super(View, self).__init__(params=params) |
400
8f07048d84ef
Added a generic version of the Document views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
113 |
|
575 | 114 |
def _editPost(self, request, entity, fields): |
115 |
"""See base.View._editPost(). |
|
116 |
""" |
|
117 |
||
662
0e89b027b140
Make use of the new generic key_name by lookup up scope_path
Sverre Rabbelier <srabbelier@gmail.com>
parents:
657
diff
changeset
|
118 |
user = user_logic.logic.getFromKeyName(fields['link_id']) |
575 | 119 |
fields['user'] = user |
120 |
||
662
0e89b027b140
Make use of the new generic key_name by lookup up scope_path
Sverre Rabbelier <srabbelier@gmail.com>
parents:
657
diff
changeset
|
121 |
super(View, self)._editPost(request, entity, fields) |
400
8f07048d84ef
Added a generic version of the Document views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
122 |
|
8f07048d84ef
Added a generic version of the Document views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
123 |
view = View() |
8f07048d84ef
Added a generic version of the Document views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
124 |
|
8f07048d84ef
Added a generic version of the Document views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
125 |
create = view.create |
404
44223e50e1fc
Added a Host profile and generalized some views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
402
diff
changeset
|
126 |
delete = view.delete |
400
8f07048d84ef
Added a generic version of the Document views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
127 |
edit = view.edit |
8f07048d84ef
Added a generic version of the Document views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
128 |
list = view.list |
8f07048d84ef
Added a generic version of the Document views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
129 |
public = view.public |
497
73666a7cd718
Added a default _editSeed method
Sverre Rabbelier <srabbelier@gmail.com>
parents:
495
diff
changeset
|
130 |
invite = view.invite |