author | Lennard de Rijk <ljvderijk@gmail.com> |
Fri, 23 Jan 2009 12:00:48 +0000 | |
changeset 920 | 39badbfb80be |
parent 858 | e79e7a22326f |
child 925 | a85719e94570 |
permissions | -rw-r--r-- |
802
95c534d02e39
Added Club Admin model, logic, and view
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
1 |
#!/usr/bin/python2.5 |
95c534d02e39
Added Club Admin model, logic, and view
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
2 |
# |
95c534d02e39
Added Club Admin model, logic, and view
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
3 |
# Copyright 2008 the Melange authors. |
95c534d02e39
Added Club Admin model, logic, and view
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
4 |
# |
95c534d02e39
Added Club Admin model, logic, and view
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
5 |
# Licensed under the Apache License, Version 2.0 (the "License"); |
95c534d02e39
Added Club Admin model, logic, and view
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
6 |
# you may not use this file except in compliance with the License. |
95c534d02e39
Added Club Admin model, logic, and view
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
7 |
# You may obtain a copy of the License at |
95c534d02e39
Added Club Admin model, logic, and view
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
8 |
# |
95c534d02e39
Added Club Admin model, logic, and view
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
9 |
# http://www.apache.org/licenses/LICENSE-2.0 |
95c534d02e39
Added Club Admin model, logic, and view
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
10 |
# |
95c534d02e39
Added Club Admin model, logic, and view
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
11 |
# Unless required by applicable law or agreed to in writing, software |
95c534d02e39
Added Club Admin model, logic, and view
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
12 |
# distributed under the License is distributed on an "AS IS" BASIS, |
95c534d02e39
Added Club Admin model, logic, and view
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
13 |
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
95c534d02e39
Added Club Admin model, logic, and view
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
14 |
# See the License for the specific language governing permissions and |
95c534d02e39
Added Club Admin model, logic, and view
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
15 |
# limitations under the License. |
95c534d02e39
Added Club Admin model, logic, and view
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
16 |
|
95c534d02e39
Added Club Admin model, logic, and view
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
17 |
"""Views for Club Admins. |
95c534d02e39
Added Club Admin model, logic, and view
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
18 |
""" |
95c534d02e39
Added Club Admin model, logic, and view
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
19 |
|
95c534d02e39
Added Club Admin model, logic, and view
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
20 |
__authors__ = [ |
95c534d02e39
Added Club Admin model, logic, and view
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
21 |
'"Sverre Rabbelier" <sverre@rabbelier.nl>', |
920
39badbfb80be
Added the new way to process invites for club_admin only.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
858
diff
changeset
|
22 |
'"Lennard de Rijk" <ljvderijk@gmail.com>' |
802
95c534d02e39
Added Club Admin model, logic, and view
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
23 |
] |
95c534d02e39
Added Club Admin model, logic, and view
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
24 |
|
95c534d02e39
Added Club Admin model, logic, and view
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
25 |
|
920
39badbfb80be
Added the new way to process invites for club_admin only.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
858
diff
changeset
|
26 |
from django import http |
802
95c534d02e39
Added Club Admin model, logic, and view
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
27 |
from django import forms |
95c534d02e39
Added Club Admin model, logic, and view
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
28 |
|
95c534d02e39
Added Club Admin model, logic, and view
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
29 |
from soc.logic import cleaning |
95c534d02e39
Added Club Admin model, logic, and view
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
30 |
from soc.logic import dicts |
920
39badbfb80be
Added the new way to process invites for club_admin only.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
858
diff
changeset
|
31 |
from soc.logic.models import club as club_logic |
39badbfb80be
Added the new way to process invites for club_admin only.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
858
diff
changeset
|
32 |
from soc.logic.models import user as user_logic |
39badbfb80be
Added the new way to process invites for club_admin only.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
858
diff
changeset
|
33 |
from soc.logic.models import request as request_logic |
39badbfb80be
Added the new way to process invites for club_admin only.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
858
diff
changeset
|
34 |
from soc.views.helper import access |
39badbfb80be
Added the new way to process invites for club_admin only.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
858
diff
changeset
|
35 |
from soc.views.helper import decorators |
39badbfb80be
Added the new way to process invites for club_admin only.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
858
diff
changeset
|
36 |
from soc.views.helper import dynaform |
802
95c534d02e39
Added Club Admin model, logic, and view
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
37 |
from soc.views.helper import redirects |
920
39badbfb80be
Added the new way to process invites for club_admin only.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
858
diff
changeset
|
38 |
from soc.views.helper import responses |
39badbfb80be
Added the new way to process invites for club_admin only.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
858
diff
changeset
|
39 |
from soc.views.helper import widgets |
802
95c534d02e39
Added Club Admin model, logic, and view
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
40 |
from soc.views.models import base |
95c534d02e39
Added Club Admin model, logic, and view
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
41 |
from soc.views.models import club as club_view |
920
39badbfb80be
Added the new way to process invites for club_admin only.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
858
diff
changeset
|
42 |
from soc.views.models import request as request_view |
802
95c534d02e39
Added Club Admin model, logic, and view
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
43 |
|
95c534d02e39
Added Club Admin model, logic, and view
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
44 |
import soc.logic.models.club_admin |
95c534d02e39
Added Club Admin model, logic, and view
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
45 |
|
95c534d02e39
Added Club Admin model, logic, and view
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
46 |
|
95c534d02e39
Added Club Admin model, logic, and view
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
47 |
class View(base.View): |
920
39badbfb80be
Added the new way to process invites for club_admin only.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
858
diff
changeset
|
48 |
"""View methods for the Club Admin model. |
802
95c534d02e39
Added Club Admin model, logic, and view
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
49 |
""" |
95c534d02e39
Added Club Admin model, logic, and view
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
50 |
|
95c534d02e39
Added Club Admin model, logic, and view
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
51 |
def __init__(self, params=None): |
95c534d02e39
Added Club Admin model, logic, and view
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
52 |
"""Defines the fields and methods required for the base View class |
95c534d02e39
Added Club Admin model, logic, and view
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
53 |
to provide the user with list, public, create, edit and delete views. |
95c534d02e39
Added Club Admin model, logic, and view
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
54 |
|
95c534d02e39
Added Club Admin model, logic, and view
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
55 |
Params: |
95c534d02e39
Added Club Admin model, logic, and view
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
56 |
params: a dict with params for this View |
95c534d02e39
Added Club Admin model, logic, and view
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
57 |
""" |
95c534d02e39
Added Club Admin model, logic, and view
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
58 |
|
920
39badbfb80be
Added the new way to process invites for club_admin only.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
858
diff
changeset
|
59 |
rights = {} |
39badbfb80be
Added the new way to process invites for club_admin only.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
858
diff
changeset
|
60 |
rights['create'] = [access.checkIsHost] |
39badbfb80be
Added the new way to process invites for club_admin only.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
858
diff
changeset
|
61 |
rights['edit'] = [access.checkIsMyActiveRole(soc.logic.models.club_admin)] |
39badbfb80be
Added the new way to process invites for club_admin only.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
858
diff
changeset
|
62 |
rights['delete'] = [access.checkIsHost] |
39badbfb80be
Added the new way to process invites for club_admin only.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
858
diff
changeset
|
63 |
rights['invite'] = [access.checkIsClubAdminForClub] |
39badbfb80be
Added the new way to process invites for club_admin only.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
858
diff
changeset
|
64 |
rights['accept_invite'] = [access.checkCanCreateFromRequest('club_admin')] |
39badbfb80be
Added the new way to process invites for club_admin only.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
858
diff
changeset
|
65 |
|
802
95c534d02e39
Added Club Admin model, logic, and view
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
66 |
new_params = {} |
95c534d02e39
Added Club Admin model, logic, and view
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
67 |
new_params['logic'] = soc.logic.models.club_admin.logic |
920
39badbfb80be
Added the new way to process invites for club_admin only.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
858
diff
changeset
|
68 |
new_params['rights'] = rights |
802
95c534d02e39
Added Club Admin model, logic, and view
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
69 |
|
95c534d02e39
Added Club Admin model, logic, and view
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
70 |
new_params['scope_view'] = club_view |
95c534d02e39
Added Club Admin model, logic, and view
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
71 |
new_params['scope_redirect'] = redirects.getCreateRedirect |
95c534d02e39
Added Club Admin model, logic, and view
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
72 |
|
95c534d02e39
Added Club Admin model, logic, and view
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
73 |
new_params['name'] = "Club Admin" |
95c534d02e39
Added Club Admin model, logic, and view
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
74 |
|
920
39badbfb80be
Added the new way to process invites for club_admin only.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
858
diff
changeset
|
75 |
new_params['extra_dynaexclude'] = ['user', 'club', 'state'] |
39badbfb80be
Added the new way to process invites for club_admin only.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
858
diff
changeset
|
76 |
|
39badbfb80be
Added the new way to process invites for club_admin only.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
858
diff
changeset
|
77 |
new_params['create_extra_dynafields'] = { |
39badbfb80be
Added the new way to process invites for club_admin only.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
858
diff
changeset
|
78 |
'scope_path': forms.CharField(widget=forms.HiddenInput, |
39badbfb80be
Added the new way to process invites for club_admin only.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
858
diff
changeset
|
79 |
required=True), |
39badbfb80be
Added the new way to process invites for club_admin only.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
858
diff
changeset
|
80 |
'clean_link_id' : cleaning.clean_existing_user('link_id'), |
39badbfb80be
Added the new way to process invites for club_admin only.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
858
diff
changeset
|
81 |
'clean_home_page' : cleaning.clean_url('home_page'), |
39badbfb80be
Added the new way to process invites for club_admin only.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
858
diff
changeset
|
82 |
'clean_blog' : cleaning.clean_url('blog'), |
39badbfb80be
Added the new way to process invites for club_admin only.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
858
diff
changeset
|
83 |
'clean_photo_url' : cleaning.clean_url('photo_url')} |
802
95c534d02e39
Added Club Admin model, logic, and view
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
84 |
|
920
39badbfb80be
Added the new way to process invites for club_admin only.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
858
diff
changeset
|
85 |
patterns = [(r'^%(url_name)s/(?P<access_type>invite)/%(lnp)s$', |
39badbfb80be
Added the new way to process invites for club_admin only.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
858
diff
changeset
|
86 |
'soc.views.models.%(module_name)s.invite', |
39badbfb80be
Added the new way to process invites for club_admin only.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
858
diff
changeset
|
87 |
'Create invite for %(name_plural)s'), |
39badbfb80be
Added the new way to process invites for club_admin only.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
858
diff
changeset
|
88 |
(r'^%(url_name)s/(?P<access_type>accept_invite)/%(scope)s/%(lnp)s$', |
39badbfb80be
Added the new way to process invites for club_admin only.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
858
diff
changeset
|
89 |
'soc.views.models.%(module_name)s.acceptInvite', |
39badbfb80be
Added the new way to process invites for club_admin only.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
858
diff
changeset
|
90 |
'Accept invite for %(name_plural)s')] |
39badbfb80be
Added the new way to process invites for club_admin only.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
858
diff
changeset
|
91 |
|
39badbfb80be
Added the new way to process invites for club_admin only.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
858
diff
changeset
|
92 |
new_params['extra_django_patterns'] = patterns |
39badbfb80be
Added the new way to process invites for club_admin only.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
858
diff
changeset
|
93 |
|
802
95c534d02e39
Added Club Admin model, logic, and view
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
94 |
params = dicts.merge(params, new_params) |
95c534d02e39
Added Club Admin model, logic, and view
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
95 |
|
95c534d02e39
Added Club Admin model, logic, and view
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
96 |
super(View, self).__init__(params=params) |
95c534d02e39
Added Club Admin model, logic, and view
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
97 |
|
920
39badbfb80be
Added the new way to process invites for club_admin only.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
858
diff
changeset
|
98 |
# create and store the special form for invited users |
39badbfb80be
Added the new way to process invites for club_admin only.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
858
diff
changeset
|
99 |
updated_fields = { |
39badbfb80be
Added the new way to process invites for club_admin only.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
858
diff
changeset
|
100 |
'link_id': forms.CharField(widget=widgets.ReadOnlyInput(), |
39badbfb80be
Added the new way to process invites for club_admin only.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
858
diff
changeset
|
101 |
required=False)} |
39badbfb80be
Added the new way to process invites for club_admin only.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
858
diff
changeset
|
102 |
|
39badbfb80be
Added the new way to process invites for club_admin only.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
858
diff
changeset
|
103 |
invited_create_form = dynaform.extendDynaForm( |
39badbfb80be
Added the new way to process invites for club_admin only.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
858
diff
changeset
|
104 |
dynaform = self._params['create_form'], |
39badbfb80be
Added the new way to process invites for club_admin only.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
858
diff
changeset
|
105 |
dynafields = updated_fields) |
39badbfb80be
Added the new way to process invites for club_admin only.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
858
diff
changeset
|
106 |
|
39badbfb80be
Added the new way to process invites for club_admin only.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
858
diff
changeset
|
107 |
params['invited_create_form'] = invited_create_form |
39badbfb80be
Added the new way to process invites for club_admin only.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
858
diff
changeset
|
108 |
|
39badbfb80be
Added the new way to process invites for club_admin only.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
858
diff
changeset
|
109 |
|
39badbfb80be
Added the new way to process invites for club_admin only.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
858
diff
changeset
|
110 |
def _editPost(self, request, entity, fields): |
39badbfb80be
Added the new way to process invites for club_admin only.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
858
diff
changeset
|
111 |
"""See base.View._editPost(). |
39badbfb80be
Added the new way to process invites for club_admin only.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
858
diff
changeset
|
112 |
""" |
39badbfb80be
Added the new way to process invites for club_admin only.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
858
diff
changeset
|
113 |
|
39badbfb80be
Added the new way to process invites for club_admin only.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
858
diff
changeset
|
114 |
fields['user'] = fields['link_id'] |
39badbfb80be
Added the new way to process invites for club_admin only.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
858
diff
changeset
|
115 |
fields['link_id'] = fields['user'].link_id |
39badbfb80be
Added the new way to process invites for club_admin only.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
858
diff
changeset
|
116 |
|
39badbfb80be
Added the new way to process invites for club_admin only.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
858
diff
changeset
|
117 |
club = club_logic.logic.getFromKeyName(fields['scope_path']) |
39badbfb80be
Added the new way to process invites for club_admin only.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
858
diff
changeset
|
118 |
fields['club'] = club |
39badbfb80be
Added the new way to process invites for club_admin only.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
858
diff
changeset
|
119 |
|
39badbfb80be
Added the new way to process invites for club_admin only.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
858
diff
changeset
|
120 |
super(View, self)._editPost(request, entity, fields) |
39badbfb80be
Added the new way to process invites for club_admin only.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
858
diff
changeset
|
121 |
|
39badbfb80be
Added the new way to process invites for club_admin only.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
858
diff
changeset
|
122 |
|
39badbfb80be
Added the new way to process invites for club_admin only.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
858
diff
changeset
|
123 |
@decorators.merge_params |
39badbfb80be
Added the new way to process invites for club_admin only.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
858
diff
changeset
|
124 |
@decorators.check_access |
39badbfb80be
Added the new way to process invites for club_admin only.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
858
diff
changeset
|
125 |
def acceptInvite(self, request, access_type, |
39badbfb80be
Added the new way to process invites for club_admin only.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
858
diff
changeset
|
126 |
page_name=None, params=None, **kwargs): |
39badbfb80be
Added the new way to process invites for club_admin only.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
858
diff
changeset
|
127 |
"""Creates the page process an invite into a Club Admin. |
39badbfb80be
Added the new way to process invites for club_admin only.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
858
diff
changeset
|
128 |
|
39badbfb80be
Added the new way to process invites for club_admin only.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
858
diff
changeset
|
129 |
Args: |
39badbfb80be
Added the new way to process invites for club_admin only.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
858
diff
changeset
|
130 |
request: the standard Django HTTP request object |
39badbfb80be
Added the new way to process invites for club_admin only.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
858
diff
changeset
|
131 |
access_type : the name of the access type which should be checked |
39badbfb80be
Added the new way to process invites for club_admin only.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
858
diff
changeset
|
132 |
context: dictionary containing the context for this view |
39badbfb80be
Added the new way to process invites for club_admin only.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
858
diff
changeset
|
133 |
params: a dict with params for this View |
39badbfb80be
Added the new way to process invites for club_admin only.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
858
diff
changeset
|
134 |
kwargs: the Key Fields for the specified entity |
39badbfb80be
Added the new way to process invites for club_admin only.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
858
diff
changeset
|
135 |
""" |
39badbfb80be
Added the new way to process invites for club_admin only.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
858
diff
changeset
|
136 |
|
39badbfb80be
Added the new way to process invites for club_admin only.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
858
diff
changeset
|
137 |
# get the context for this webpage |
39badbfb80be
Added the new way to process invites for club_admin only.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
858
diff
changeset
|
138 |
context = responses.getUniversalContext(request) |
39badbfb80be
Added the new way to process invites for club_admin only.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
858
diff
changeset
|
139 |
context['page_name'] = page_name |
39badbfb80be
Added the new way to process invites for club_admin only.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
858
diff
changeset
|
140 |
|
39badbfb80be
Added the new way to process invites for club_admin only.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
858
diff
changeset
|
141 |
if request.method == 'POST': |
39badbfb80be
Added the new way to process invites for club_admin only.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
858
diff
changeset
|
142 |
return self.acceptInvitePost(request, context, params, **kwargs) |
39badbfb80be
Added the new way to process invites for club_admin only.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
858
diff
changeset
|
143 |
else: |
39badbfb80be
Added the new way to process invites for club_admin only.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
858
diff
changeset
|
144 |
# request.method == 'GET' |
39badbfb80be
Added the new way to process invites for club_admin only.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
858
diff
changeset
|
145 |
return self.acceptInviteGet(request, context, params, **kwargs) |
39badbfb80be
Added the new way to process invites for club_admin only.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
858
diff
changeset
|
146 |
|
39badbfb80be
Added the new way to process invites for club_admin only.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
858
diff
changeset
|
147 |
def acceptInviteGet(self, request, context, params, **kwargs): |
39badbfb80be
Added the new way to process invites for club_admin only.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
858
diff
changeset
|
148 |
"""Handles the GET request concerning the creation of a Club Admin via an |
39badbfb80be
Added the new way to process invites for club_admin only.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
858
diff
changeset
|
149 |
invite. |
39badbfb80be
Added the new way to process invites for club_admin only.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
858
diff
changeset
|
150 |
|
39badbfb80be
Added the new way to process invites for club_admin only.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
858
diff
changeset
|
151 |
Args: |
39badbfb80be
Added the new way to process invites for club_admin only.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
858
diff
changeset
|
152 |
request: the standard Django HTTP request object |
39badbfb80be
Added the new way to process invites for club_admin only.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
858
diff
changeset
|
153 |
context: dictionary containing the context for this view |
39badbfb80be
Added the new way to process invites for club_admin only.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
858
diff
changeset
|
154 |
params: a dict with params for this View |
39badbfb80be
Added the new way to process invites for club_admin only.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
858
diff
changeset
|
155 |
kwargs: the Key Fields for the specified entity |
39badbfb80be
Added the new way to process invites for club_admin only.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
858
diff
changeset
|
156 |
""" |
39badbfb80be
Added the new way to process invites for club_admin only.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
858
diff
changeset
|
157 |
|
39badbfb80be
Added the new way to process invites for club_admin only.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
858
diff
changeset
|
158 |
# create the form using the scope_path and link_id from kwargs as initial value |
39badbfb80be
Added the new way to process invites for club_admin only.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
858
diff
changeset
|
159 |
fields = {'link_id' : kwargs['link_id'], |
39badbfb80be
Added the new way to process invites for club_admin only.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
858
diff
changeset
|
160 |
'scope_path' : kwargs['scope_path']} |
39badbfb80be
Added the new way to process invites for club_admin only.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
858
diff
changeset
|
161 |
form = params['invited_create_form'](initial=fields) |
39badbfb80be
Added the new way to process invites for club_admin only.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
858
diff
changeset
|
162 |
|
39badbfb80be
Added the new way to process invites for club_admin only.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
858
diff
changeset
|
163 |
# construct the appropriate response |
39badbfb80be
Added the new way to process invites for club_admin only.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
858
diff
changeset
|
164 |
return super(View, self)._constructResponse(request, entity=None, |
39badbfb80be
Added the new way to process invites for club_admin only.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
858
diff
changeset
|
165 |
context=context, form=form, params=params) |
39badbfb80be
Added the new way to process invites for club_admin only.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
858
diff
changeset
|
166 |
|
39badbfb80be
Added the new way to process invites for club_admin only.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
858
diff
changeset
|
167 |
def acceptInvitePost(self, request, context, params, **kwargs): |
39badbfb80be
Added the new way to process invites for club_admin only.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
858
diff
changeset
|
168 |
"""Handles the POST request concerning the creation of a Club Admin via an |
39badbfb80be
Added the new way to process invites for club_admin only.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
858
diff
changeset
|
169 |
invite. |
39badbfb80be
Added the new way to process invites for club_admin only.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
858
diff
changeset
|
170 |
|
39badbfb80be
Added the new way to process invites for club_admin only.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
858
diff
changeset
|
171 |
Args: |
39badbfb80be
Added the new way to process invites for club_admin only.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
858
diff
changeset
|
172 |
request: the standard Django HTTP request object |
39badbfb80be
Added the new way to process invites for club_admin only.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
858
diff
changeset
|
173 |
context: dictionary containing the context for this view |
39badbfb80be
Added the new way to process invites for club_admin only.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
858
diff
changeset
|
174 |
params: a dict with params for this View |
39badbfb80be
Added the new way to process invites for club_admin only.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
858
diff
changeset
|
175 |
kwargs: the Key Fields for the specified entity |
39badbfb80be
Added the new way to process invites for club_admin only.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
858
diff
changeset
|
176 |
""" |
39badbfb80be
Added the new way to process invites for club_admin only.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
858
diff
changeset
|
177 |
|
39badbfb80be
Added the new way to process invites for club_admin only.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
858
diff
changeset
|
178 |
# populate the form using the POST data |
39badbfb80be
Added the new way to process invites for club_admin only.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
858
diff
changeset
|
179 |
form = params['invited_create_form'](request.POST) |
39badbfb80be
Added the new way to process invites for club_admin only.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
858
diff
changeset
|
180 |
|
39badbfb80be
Added the new way to process invites for club_admin only.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
858
diff
changeset
|
181 |
if not form.is_valid(): |
39badbfb80be
Added the new way to process invites for club_admin only.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
858
diff
changeset
|
182 |
# return the invalid form response |
39badbfb80be
Added the new way to process invites for club_admin only.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
858
diff
changeset
|
183 |
return self._constructResponse(request, entity=None, context=context, |
39badbfb80be
Added the new way to process invites for club_admin only.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
858
diff
changeset
|
184 |
form=form, params=params) |
39badbfb80be
Added the new way to process invites for club_admin only.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
858
diff
changeset
|
185 |
|
39badbfb80be
Added the new way to process invites for club_admin only.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
858
diff
changeset
|
186 |
# collect the cleaned data from the valid form |
39badbfb80be
Added the new way to process invites for club_admin only.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
858
diff
changeset
|
187 |
key_name, fields = soc.views.helper.forms.collectCleanedFields(form) |
39badbfb80be
Added the new way to process invites for club_admin only.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
858
diff
changeset
|
188 |
|
39badbfb80be
Added the new way to process invites for club_admin only.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
858
diff
changeset
|
189 |
# fill in the appropriate fields that were missing in the form |
39badbfb80be
Added the new way to process invites for club_admin only.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
858
diff
changeset
|
190 |
fields['user'] = fields['link_id'] |
39badbfb80be
Added the new way to process invites for club_admin only.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
858
diff
changeset
|
191 |
fields['link_id'] = fields['user'].link_id |
39badbfb80be
Added the new way to process invites for club_admin only.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
858
diff
changeset
|
192 |
|
39badbfb80be
Added the new way to process invites for club_admin only.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
858
diff
changeset
|
193 |
club = club_logic.logic.getFromKeyName(fields['scope_path']) |
39badbfb80be
Added the new way to process invites for club_admin only.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
858
diff
changeset
|
194 |
fields['club'] = club |
39badbfb80be
Added the new way to process invites for club_admin only.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
858
diff
changeset
|
195 |
fields['scope'] = club |
39badbfb80be
Added the new way to process invites for club_admin only.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
858
diff
changeset
|
196 |
|
39badbfb80be
Added the new way to process invites for club_admin only.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
858
diff
changeset
|
197 |
# make sure that this role becomes active once more in case this user |
39badbfb80be
Added the new way to process invites for club_admin only.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
858
diff
changeset
|
198 |
# has been reinvited |
39badbfb80be
Added the new way to process invites for club_admin only.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
858
diff
changeset
|
199 |
fields ['state'] = 'active' |
39badbfb80be
Added the new way to process invites for club_admin only.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
858
diff
changeset
|
200 |
|
39badbfb80be
Added the new way to process invites for club_admin only.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
858
diff
changeset
|
201 |
# get the key_name for the new entity |
39badbfb80be
Added the new way to process invites for club_admin only.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
858
diff
changeset
|
202 |
key_fields = self._logic.getKeyFieldsFromDict(fields) |
39badbfb80be
Added the new way to process invites for club_admin only.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
858
diff
changeset
|
203 |
key_name = self._logic.getKeyNameForFields(key_fields) |
39badbfb80be
Added the new way to process invites for club_admin only.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
858
diff
changeset
|
204 |
|
39badbfb80be
Added the new way to process invites for club_admin only.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
858
diff
changeset
|
205 |
# create new Club Admin entity |
39badbfb80be
Added the new way to process invites for club_admin only.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
858
diff
changeset
|
206 |
entity = self._logic.updateOrCreateFromKeyName(fields, key_name) |
39badbfb80be
Added the new way to process invites for club_admin only.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
858
diff
changeset
|
207 |
|
39badbfb80be
Added the new way to process invites for club_admin only.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
858
diff
changeset
|
208 |
# redirect to the roles overview page |
39badbfb80be
Added the new way to process invites for club_admin only.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
858
diff
changeset
|
209 |
return http.HttpResponseRedirect('/user/roles') |
39badbfb80be
Added the new way to process invites for club_admin only.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
858
diff
changeset
|
210 |
|
39badbfb80be
Added the new way to process invites for club_admin only.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
858
diff
changeset
|
211 |
|
39badbfb80be
Added the new way to process invites for club_admin only.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
858
diff
changeset
|
212 |
@decorators.merge_params |
39badbfb80be
Added the new way to process invites for club_admin only.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
858
diff
changeset
|
213 |
@decorators.check_access |
39badbfb80be
Added the new way to process invites for club_admin only.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
858
diff
changeset
|
214 |
def invite(self, request, access_type, |
39badbfb80be
Added the new way to process invites for club_admin only.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
858
diff
changeset
|
215 |
page_name=None, params=None, **kwargs): |
39badbfb80be
Added the new way to process invites for club_admin only.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
858
diff
changeset
|
216 |
"""Creates the page upon which a Club Admin can invite another Club Admin. |
39badbfb80be
Added the new way to process invites for club_admin only.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
858
diff
changeset
|
217 |
|
39badbfb80be
Added the new way to process invites for club_admin only.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
858
diff
changeset
|
218 |
Args: |
39badbfb80be
Added the new way to process invites for club_admin only.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
858
diff
changeset
|
219 |
request: the standard Django HTTP request object |
39badbfb80be
Added the new way to process invites for club_admin only.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
858
diff
changeset
|
220 |
access_type : the name of the access type which should be checked |
39badbfb80be
Added the new way to process invites for club_admin only.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
858
diff
changeset
|
221 |
context: dictionary containing the context for this view |
39badbfb80be
Added the new way to process invites for club_admin only.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
858
diff
changeset
|
222 |
params: a dict with params for this View |
39badbfb80be
Added the new way to process invites for club_admin only.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
858
diff
changeset
|
223 |
kwargs: the Key Fields for the specified entity |
39badbfb80be
Added the new way to process invites for club_admin only.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
858
diff
changeset
|
224 |
""" |
39badbfb80be
Added the new way to process invites for club_admin only.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
858
diff
changeset
|
225 |
|
39badbfb80be
Added the new way to process invites for club_admin only.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
858
diff
changeset
|
226 |
# get the context for this webpage |
39badbfb80be
Added the new way to process invites for club_admin only.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
858
diff
changeset
|
227 |
context = responses.getUniversalContext(request) |
39badbfb80be
Added the new way to process invites for club_admin only.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
858
diff
changeset
|
228 |
context['page_name'] = page_name |
39badbfb80be
Added the new way to process invites for club_admin only.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
858
diff
changeset
|
229 |
|
39badbfb80be
Added the new way to process invites for club_admin only.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
858
diff
changeset
|
230 |
if request.method == 'POST': |
39badbfb80be
Added the new way to process invites for club_admin only.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
858
diff
changeset
|
231 |
return self.invitePost(request, context, params, **kwargs) |
39badbfb80be
Added the new way to process invites for club_admin only.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
858
diff
changeset
|
232 |
else: |
39badbfb80be
Added the new way to process invites for club_admin only.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
858
diff
changeset
|
233 |
# request.method == 'GET' |
39badbfb80be
Added the new way to process invites for club_admin only.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
858
diff
changeset
|
234 |
return self.inviteGet(request, context, params, **kwargs) |
39badbfb80be
Added the new way to process invites for club_admin only.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
858
diff
changeset
|
235 |
|
39badbfb80be
Added the new way to process invites for club_admin only.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
858
diff
changeset
|
236 |
def inviteGet(self, request, context, params, **kwargs): |
39badbfb80be
Added the new way to process invites for club_admin only.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
858
diff
changeset
|
237 |
"""Handles the GET request concerning the view that creates an invite |
39badbfb80be
Added the new way to process invites for club_admin only.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
858
diff
changeset
|
238 |
for becoming a Club Admin. |
39badbfb80be
Added the new way to process invites for club_admin only.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
858
diff
changeset
|
239 |
|
39badbfb80be
Added the new way to process invites for club_admin only.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
858
diff
changeset
|
240 |
Args: |
39badbfb80be
Added the new way to process invites for club_admin only.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
858
diff
changeset
|
241 |
request: the standard Django HTTP request object |
39badbfb80be
Added the new way to process invites for club_admin only.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
858
diff
changeset
|
242 |
page_name: the page name displayed in templates as page and header title |
39badbfb80be
Added the new way to process invites for club_admin only.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
858
diff
changeset
|
243 |
params: a dict with params for this View |
39badbfb80be
Added the new way to process invites for club_admin only.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
858
diff
changeset
|
244 |
kwargs: the Key Fields for the specified entity |
39badbfb80be
Added the new way to process invites for club_admin only.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
858
diff
changeset
|
245 |
""" |
39badbfb80be
Added the new way to process invites for club_admin only.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
858
diff
changeset
|
246 |
|
39badbfb80be
Added the new way to process invites for club_admin only.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
858
diff
changeset
|
247 |
# set the role to the right name |
39badbfb80be
Added the new way to process invites for club_admin only.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
858
diff
changeset
|
248 |
fields = {'role' : '%(module_name)s' %(params)} |
39badbfb80be
Added the new way to process invites for club_admin only.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
858
diff
changeset
|
249 |
|
39badbfb80be
Added the new way to process invites for club_admin only.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
858
diff
changeset
|
250 |
# get the request view parameters and initialize the create form |
39badbfb80be
Added the new way to process invites for club_admin only.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
858
diff
changeset
|
251 |
request_params = request_view.view.getParams() |
39badbfb80be
Added the new way to process invites for club_admin only.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
858
diff
changeset
|
252 |
form = request_params['create_form'](initial=fields) |
39badbfb80be
Added the new way to process invites for club_admin only.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
858
diff
changeset
|
253 |
|
39badbfb80be
Added the new way to process invites for club_admin only.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
858
diff
changeset
|
254 |
# construct the appropriate response |
39badbfb80be
Added the new way to process invites for club_admin only.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
858
diff
changeset
|
255 |
return super(View, self)._constructResponse(request, entity=None, |
39badbfb80be
Added the new way to process invites for club_admin only.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
858
diff
changeset
|
256 |
context=context, form=form, params=params) |
39badbfb80be
Added the new way to process invites for club_admin only.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
858
diff
changeset
|
257 |
|
39badbfb80be
Added the new way to process invites for club_admin only.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
858
diff
changeset
|
258 |
def invitePost(self, request, context, params, **kwargs): |
39badbfb80be
Added the new way to process invites for club_admin only.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
858
diff
changeset
|
259 |
"""Handles the POST request concerning the view that creates an invite |
39badbfb80be
Added the new way to process invites for club_admin only.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
858
diff
changeset
|
260 |
for becoming a Club Admin. |
39badbfb80be
Added the new way to process invites for club_admin only.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
858
diff
changeset
|
261 |
|
39badbfb80be
Added the new way to process invites for club_admin only.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
858
diff
changeset
|
262 |
Args: |
39badbfb80be
Added the new way to process invites for club_admin only.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
858
diff
changeset
|
263 |
request: the standard Django HTTP request object |
39badbfb80be
Added the new way to process invites for club_admin only.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
858
diff
changeset
|
264 |
page_name: the page name displayed in templates as page and header title |
39badbfb80be
Added the new way to process invites for club_admin only.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
858
diff
changeset
|
265 |
params: a dict with params for this View |
39badbfb80be
Added the new way to process invites for club_admin only.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
858
diff
changeset
|
266 |
kwargs: the Key Fields for the specified entity |
39badbfb80be
Added the new way to process invites for club_admin only.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
858
diff
changeset
|
267 |
""" |
39badbfb80be
Added the new way to process invites for club_admin only.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
858
diff
changeset
|
268 |
|
39badbfb80be
Added the new way to process invites for club_admin only.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
858
diff
changeset
|
269 |
# get the request view parameters and populate the form using POST data |
39badbfb80be
Added the new way to process invites for club_admin only.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
858
diff
changeset
|
270 |
request_params = request_view.view.getParams() |
39badbfb80be
Added the new way to process invites for club_admin only.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
858
diff
changeset
|
271 |
form = request_params['create_form'](request.POST) |
39badbfb80be
Added the new way to process invites for club_admin only.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
858
diff
changeset
|
272 |
|
39badbfb80be
Added the new way to process invites for club_admin only.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
858
diff
changeset
|
273 |
if not form.is_valid(): |
39badbfb80be
Added the new way to process invites for club_admin only.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
858
diff
changeset
|
274 |
# return the invalid form response |
39badbfb80be
Added the new way to process invites for club_admin only.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
858
diff
changeset
|
275 |
return self._constructResponse(request, entity=None, context=context, |
39badbfb80be
Added the new way to process invites for club_admin only.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
858
diff
changeset
|
276 |
form=form, params=params) |
39badbfb80be
Added the new way to process invites for club_admin only.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
858
diff
changeset
|
277 |
|
39badbfb80be
Added the new way to process invites for club_admin only.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
858
diff
changeset
|
278 |
# collect the cleaned data from the valid form |
39badbfb80be
Added the new way to process invites for club_admin only.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
858
diff
changeset
|
279 |
key_name, form_fields = soc.views.helper.forms.collectCleanedFields(form) |
39badbfb80be
Added the new way to process invites for club_admin only.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
858
diff
changeset
|
280 |
|
39badbfb80be
Added the new way to process invites for club_admin only.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
858
diff
changeset
|
281 |
# get the club entity for which this request is for from link_id in kwargs |
39badbfb80be
Added the new way to process invites for club_admin only.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
858
diff
changeset
|
282 |
club = club_logic.logic.getForFields({'link_id' : kwargs['link_id']}, unique=True) |
39badbfb80be
Added the new way to process invites for club_admin only.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
858
diff
changeset
|
283 |
|
39badbfb80be
Added the new way to process invites for club_admin only.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
858
diff
changeset
|
284 |
# create the fields for the new request entity |
39badbfb80be
Added the new way to process invites for club_admin only.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
858
diff
changeset
|
285 |
request_fields = {'link_id' : form_fields['link_id'].link_id, |
39badbfb80be
Added the new way to process invites for club_admin only.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
858
diff
changeset
|
286 |
'scope' : club, |
39badbfb80be
Added the new way to process invites for club_admin only.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
858
diff
changeset
|
287 |
'scope_path' : club.link_id, |
39badbfb80be
Added the new way to process invites for club_admin only.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
858
diff
changeset
|
288 |
'role' : params['module_name'], |
39badbfb80be
Added the new way to process invites for club_admin only.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
858
diff
changeset
|
289 |
'role_verbose' : params['name'], |
39badbfb80be
Added the new way to process invites for club_admin only.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
858
diff
changeset
|
290 |
'group_accepted' : True, |
39badbfb80be
Added the new way to process invites for club_admin only.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
858
diff
changeset
|
291 |
'completed' : False} |
39badbfb80be
Added the new way to process invites for club_admin only.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
858
diff
changeset
|
292 |
|
39badbfb80be
Added the new way to process invites for club_admin only.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
858
diff
changeset
|
293 |
# extract the key_name for the new request entity |
39badbfb80be
Added the new way to process invites for club_admin only.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
858
diff
changeset
|
294 |
key_fields = request_logic.logic.getKeyFieldsFromDict(request_fields) |
39badbfb80be
Added the new way to process invites for club_admin only.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
858
diff
changeset
|
295 |
key_name = request_logic.logic.getKeyNameForFields(key_fields) |
39badbfb80be
Added the new way to process invites for club_admin only.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
858
diff
changeset
|
296 |
|
39badbfb80be
Added the new way to process invites for club_admin only.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
858
diff
changeset
|
297 |
# create the request entity |
39badbfb80be
Added the new way to process invites for club_admin only.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
858
diff
changeset
|
298 |
entity = request_logic.logic.updateOrCreateFromKeyName(request_fields, key_name) |
39badbfb80be
Added the new way to process invites for club_admin only.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
858
diff
changeset
|
299 |
|
39badbfb80be
Added the new way to process invites for club_admin only.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
858
diff
changeset
|
300 |
# TODO(ljvderijk) redirect to a more useful place like the club homepage |
39badbfb80be
Added the new way to process invites for club_admin only.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
858
diff
changeset
|
301 |
return http.HttpResponseRedirect('/') |
802
95c534d02e39
Added Club Admin model, logic, and view
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
302 |
|
95c534d02e39
Added Club Admin model, logic, and view
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
303 |
|
95c534d02e39
Added Club Admin model, logic, and view
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
304 |
view = View() |
95c534d02e39
Added Club Admin model, logic, and view
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
305 |
|
920
39badbfb80be
Added the new way to process invites for club_admin only.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
858
diff
changeset
|
306 |
acceptInvite = view.acceptInvite |
802
95c534d02e39
Added Club Admin model, logic, and view
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
307 |
create = view.create |
95c534d02e39
Added Club Admin model, logic, and view
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
308 |
delete = view.delete |
95c534d02e39
Added Club Admin model, logic, and view
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
309 |
edit = view.edit |
920
39badbfb80be
Added the new way to process invites for club_admin only.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
858
diff
changeset
|
310 |
invite = view.invite |
802
95c534d02e39
Added Club Admin model, logic, and view
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
311 |
list = view.list |
95c534d02e39
Added Club Admin model, logic, and view
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
312 |
public = view.public |
858
e79e7a22326f
Add an export() view, and implement it as text/text for Document.
Todd Larsen <tlarsen@google.com>
parents:
802
diff
changeset
|
313 |
export = view.export |
e79e7a22326f
Add an export() view, and implement it as text/text for Document.
Todd Larsen <tlarsen@google.com>
parents:
802
diff
changeset
|
314 |