Some style and typo fixes in different modules.
[Melange.git] / app / soc / views / models / role.py
blob5642b273c1ba3da573d2cc7e6335e946a1171cd7
1 #!/usr/bin/python2.5
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.
18 """
20 __authors__ = [
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.
46 """
48 class Meta:
49 """Inner Meta class that defines some behavior for the form.
50 """
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.
71 """
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):
77 """
79 Args:
80 params: This dictionary should be filled with the parameters
81 """
83 new_params = {}
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.
98 """
100 if not params:
101 params = {}
102 new_params = {}
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
115 try:
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)
121 contents = [content]
123 return self._list(request, params, contents, page_name)