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>',
25 from django
import forms
26 from django
.utils
.translation
import ugettext_lazy
28 from soc
.logic
import dicts
29 from soc
.logic
.models
import user
as user_logic
30 from soc
.views
import helper
31 from soc
.views
import out_of_band
32 from soc
.views
.helper
import access
33 from soc
.views
.helper
import redirects
34 from soc
.views
.models
import base
35 from soc
.views
.models
import sponsor
as sponsor_view
36 from soc
.views
.models
import user
as user_view
38 import soc
.models
.request
39 import soc
.views
.helper
.lists
40 import soc
.views
.helper
.responses
41 import soc
.views
.helper
.widgets
44 class RequestForm(helper
.forms
.BaseForm
):
45 """Django form displayed when creating a new invititation/request.
49 """Inner Meta class that defines some behavior for the form.
52 #: db.Model subclass for which the form will gather information
53 model
= soc
.models
.request
.Request
55 #: Exclude pretty much everything, model=None would
56 #: also remove the help text etc.
57 exclude
= ['requester', 'to', 'role',
58 'accepted', 'declined']
60 requester
= forms
.CharField(widget
=helper
.widgets
.ReadOnlyInput())
62 role
= forms
.CharField(widget
=helper
.widgets
.ReadOnlyInput())
64 to
= forms
.CharField(widget
=helper
.widgets
.ReadOnlyInput())
67 class View(base
.View
):
68 """Views for all entities that inherit from Role.
70 All views that only Role entities have are defined in this subclass.
73 DEF_INVITE_INSTRUCTION_MSG_FMT
= ugettext_lazy(
74 'Please use this form to invite someone to become a %(name)s.')
76 def __init__(self
, params
=None):
80 params: This dictionary should be filled with the parameters
85 patterns
= [(r
'^%(url_name)s/invite/%(lnp)s$',
86 'soc.views.models.%(module_name)s.invite',
87 'Invite %(name_short)s')]
89 new_params
['extra_django_patterns'] = patterns
90 new_params
['scope_redirect'] = redirects
.getInviteRedirect
92 params
= dicts
.merge(params
, new_params
)
94 super(View
, self
).__init
__(params
=params
)
96 def invite(self
, request
, page_name
=None, params
=None, **kwargs
):
97 """Displays the request promotion to Role page.
103 group_scope
= kwargs
['link_id']
105 new_params
['list_action'] = (redirects
.getCreateRequestRedirect
,
106 {'group_scope' : group_scope
,
107 'url_name' : self
._params
['url_name'] })
108 new_params
['list_description'] = \
109 self
.DEF_INVITE_INSTRUCTION_MSG_FMT
% self
._params
111 new_params
= dicts
.merge(new_params
, params
)
112 params
= dicts
.merge(new_params
, user_view
.view
._params
)
113 params
['logic'] = user_logic
.logic
116 access
.checkAccess('invite', request
, rights
=params
['rights'])
117 except out_of_band
.Error
, error
:
118 return helper
.responses
.errorResponse(error
, request
)
120 content
= helper
.lists
.getListContent(request
, params
)
123 return self
._list
(request
, params
, contents
, page_name
)