3 # Copyright 2008 the Melange authors.
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
9 # http://www.apache.org/licenses/LICENSE-2.0
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.
17 """Views for Sponsor profiles.
21 '"Sverre Rabbelier" <sverre@rabbelier.nl>',
22 '"Lennard de Rijk" <ljvderijk@gmail.com>',
23 '"Pawel Solyga" <pawel.solyga@gmail.com>',
27 from django
import forms
29 from soc
.logic
import dicts
30 from soc
.logic
.models
.host
import logic
as host_logic
31 from soc
.logic
.models
.sponsor
import logic
as sponsor_logic
32 from soc
.views
.helper
import access
33 from soc
.views
.helper
import decorators
34 from soc
.views
.helper
import redirects
35 from soc
.views
.models
import group
37 import soc
.models
.sponsor
38 import soc
.logic
.dicts
39 import soc
.logic
.models
.sponsor
42 class View(group
.View
):
43 """View methods for the Sponsor model.
46 def __init__(self
, params
=None):
47 """Defines the fields and methods required for the base View class
48 to provide the user with list, public, create, edit and delete views.
51 params: a dict with params for this View
54 rights
= access
.Checker(params
)
55 rights
['create'] = ['checkIsDeveloper']
56 rights
['edit'] = [('checkHasActiveRoleForLinkIdAsScope', host_logic
),
57 ('checkGroupIsActiveForLinkId', sponsor_logic
)]
58 rights
['delete'] = ['checkIsDeveloper']
59 rights
['home'] = [('checkHasActiveRoleForScope', host_logic
)]
60 rights
['list'] = ['checkIsDeveloper']
61 rights
['list_requests'] = [('checkHasActiveRoleForLinkIdAsScope',
63 rights
['list_roles'] = [('checkHasActiveRoleForLinkIdAsScope', host_logic
)]
66 new_params
['logic'] = soc
.logic
.models
.sponsor
.logic
67 new_params
['rights'] = rights
69 new_params
['name'] = "Program Owner"
70 new_params
['module_name'] = "sponsor"
71 new_params
['document_prefix'] = "sponsor"
72 new_params
['sidebar_grouping'] = 'Programs'
74 new_params
['create_dynafields'] = [
76 'base': forms
.fields
.CharField
,
77 'label': 'Sponsor Link ID',
81 params
= dicts
.merge(params
, new_params
)
83 super(View
, self
).__init
__(params
=params
)
85 def _getExtraMenuItems(self
, role_description
, params
=None):
86 """Used to create the specific Sponsor menu entries.
88 For args see group.View._getExtraMenuItems().
93 group_entity
= role_description
['group']
94 roles
= role_description
['roles']
97 # add a link to create a new program
98 submenu
= (redirects
.getCreateRedirect(group_entity
,
99 {'url_name': 'program'}),"Create a New Program", 'any_access')
100 submenus
.append(submenu
)
102 # add a link to the management page
103 submenu
= (redirects
.getListRolesRedirect(group_entity
, params
),
104 "Manage Program Administrators", 'any_access')
105 submenus
.append(submenu
)
107 # add a link to invite an a host
108 submenu
= (redirects
.getInviteRedirectForRole(group_entity
, 'host'),
109 "Invite a Program Administrator", 'any_access')
110 submenus
.append(submenu
)
112 # add a link to the request page
113 submenu
= (redirects
.getListRequestsRedirect(group_entity
, params
),
114 "List Program Administrator Invites", 'any_access')
115 submenus
.append(submenu
)
117 # add a link to the edit page
118 submenu
= (redirects
.getEditRedirect(group_entity
, params
),
119 "Edit Program Owner Profile", 'any_access')
120 submenus
.append(submenu
)
122 # add a link to resign as a host
123 submenu
= (redirects
.getManageRedirect(roles
['host'],
124 {'url_name': 'host'}),
125 "Resign as Program Administrator", 'any_access')
126 submenus
.append(submenu
)
128 # add a link to create a new document
129 submenu
= (redirects
.getCreateDocumentRedirect(group_entity
, 'sponsor'),
130 "Create a New Document", 'any_access')
131 submenus
.append(submenu
)
133 # add a link to list all documents
134 submenu
= (redirects
.getListDocumentsRedirect(group_entity
, 'sponsor'),
135 "List Documents", 'any_access')
136 submenus
.append(submenu
)
143 admin
= decorators
.view(view
.admin
)
144 create
= decorators
.view(view
.create
)
145 delete
= decorators
.view(view
.delete
)
146 edit
= decorators
.view(view
.edit
)
147 home
= decorators
.view(view
.home
)
148 list = decorators
.view(view
.list)
149 list_requests
= decorators
.view(view
.listRequests
)
150 list_roles
= decorators
.view(view
.listRoles
)
151 public
= decorators
.view(view
.public
)
152 export
= decorators
.view(view
.export
)
153 pick
= decorators
.view(view
.pick
)