author | Lennard de Rijk <ljvderijk@gmail.com> |
Wed, 21 Jan 2009 19:32:00 +0000 | |
changeset 882 | 267e31f1a0b6 |
parent 876 | 0c1329d4b514 |
child 908 | 8f7e89cacd2e |
permissions | -rw-r--r-- |
495
87afae6e4c51
Added basic 'invite' functionality
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
1 |
#!/usr/bin/python2.5 |
87afae6e4c51
Added basic 'invite' functionality
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
2 |
# |
87afae6e4c51
Added basic 'invite' functionality
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
3 |
# Copyright 2008 the Melange authors. |
87afae6e4c51
Added basic 'invite' functionality
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
4 |
# |
87afae6e4c51
Added basic 'invite' functionality
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
5 |
# Licensed under the Apache License, Version 2.0 (the "License"); |
87afae6e4c51
Added basic 'invite' functionality
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
6 |
# you may not use this file except in compliance with the License. |
87afae6e4c51
Added basic 'invite' functionality
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
7 |
# You may obtain a copy of the License at |
87afae6e4c51
Added basic 'invite' functionality
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
8 |
# |
87afae6e4c51
Added basic 'invite' functionality
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
9 |
# http://www.apache.org/licenses/LICENSE-2.0 |
87afae6e4c51
Added basic 'invite' functionality
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
10 |
# |
87afae6e4c51
Added basic 'invite' functionality
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
11 |
# Unless required by applicable law or agreed to in writing, software |
87afae6e4c51
Added basic 'invite' functionality
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
12 |
# distributed under the License is distributed on an "AS IS" BASIS, |
87afae6e4c51
Added basic 'invite' functionality
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
13 |
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
87afae6e4c51
Added basic 'invite' functionality
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
14 |
# See the License for the specific language governing permissions and |
87afae6e4c51
Added basic 'invite' functionality
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
15 |
# limitations under the License. |
87afae6e4c51
Added basic 'invite' functionality
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
16 |
|
837
bc1c951bf3a0
Add missing blank line in soc.views.helper.params module. Fix docstring typo in soc.views.models.role module. Add missing dots at the end of sentences in soc.logic.cleaning and soc.view.models.user_self modules.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
755
diff
changeset
|
17 |
"""Views for Role profiles. |
495
87afae6e4c51
Added basic 'invite' functionality
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
18 |
""" |
87afae6e4c51
Added basic 'invite' functionality
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
19 |
|
87afae6e4c51
Added basic 'invite' functionality
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
20 |
__authors__ = [ |
87afae6e4c51
Added basic 'invite' functionality
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
21 |
'"Sverre Rabbelier" <sverre@rabbelier.nl>', |
87afae6e4c51
Added basic 'invite' functionality
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
22 |
] |
87afae6e4c51
Added basic 'invite' functionality
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
23 |
|
87afae6e4c51
Added basic 'invite' functionality
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
24 |
|
87afae6e4c51
Added basic 'invite' functionality
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
25 |
from django import forms |
87afae6e4c51
Added basic 'invite' functionality
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
26 |
from django.utils.translation import ugettext_lazy |
87afae6e4c51
Added basic 'invite' functionality
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
27 |
|
87afae6e4c51
Added basic 'invite' functionality
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
28 |
from soc.logic import dicts |
87afae6e4c51
Added basic 'invite' functionality
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
29 |
from soc.logic.models import user as user_logic |
87afae6e4c51
Added basic 'invite' functionality
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
30 |
from soc.views import helper |
543
280a1ac6bcc1
Merge soc/logic/out_of_band.py into soc/views/out_of_band.py. Merge
Todd Larsen <tlarsen@google.com>
parents:
542
diff
changeset
|
31 |
from soc.views import out_of_band |
616
580b1c21b808
Fixed requests not working anymore
Sverre Rabbelier <srabbelier@gmail.com>
parents:
572
diff
changeset
|
32 |
from soc.views.helper import access |
876
0c1329d4b514
Make use of the new decorators in all applicable views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
858
diff
changeset
|
33 |
from soc.views.helper import decorators |
620
e74e0b74625f
Put the redirects in the views/helper/redirects.py module.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
616
diff
changeset
|
34 |
from soc.views.helper import redirects |
495
87afae6e4c51
Added basic 'invite' functionality
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
35 |
from soc.views.models import base |
87afae6e4c51
Added basic 'invite' functionality
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
36 |
from soc.views.models import user as user_view |
87afae6e4c51
Added basic 'invite' functionality
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
37 |
|
87afae6e4c51
Added basic 'invite' functionality
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
38 |
import soc.models.request |
646
860e17e5118f
Remove cyclic imports by moving response method of out_of_band.Error class to soc.views.helper.responses module as errorResponse function. Apply changes to affected files.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
624
diff
changeset
|
39 |
import soc.views.helper.lists |
860e17e5118f
Remove cyclic imports by moving response method of out_of_band.Error class to soc.views.helper.responses module as errorResponse function. Apply changes to affected files.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
624
diff
changeset
|
40 |
import soc.views.helper.responses |
495
87afae6e4c51
Added basic 'invite' functionality
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
41 |
import soc.views.helper.widgets |
87afae6e4c51
Added basic 'invite' functionality
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
42 |
|
87afae6e4c51
Added basic 'invite' functionality
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
43 |
|
87afae6e4c51
Added basic 'invite' functionality
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
44 |
class RequestForm(helper.forms.BaseForm): |
499
d22e4fe8e64b
Fix missing dots in doc strings and some other doc string corrections.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
495
diff
changeset
|
45 |
"""Django form displayed when creating a new invititation/request. |
495
87afae6e4c51
Added basic 'invite' functionality
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
46 |
""" |
87afae6e4c51
Added basic 'invite' functionality
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
47 |
|
87afae6e4c51
Added basic 'invite' functionality
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
48 |
class Meta: |
87afae6e4c51
Added basic 'invite' functionality
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
49 |
"""Inner Meta class that defines some behavior for the form. |
87afae6e4c51
Added basic 'invite' functionality
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
50 |
""" |
87afae6e4c51
Added basic 'invite' functionality
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
51 |
|
87afae6e4c51
Added basic 'invite' functionality
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
52 |
#: db.Model subclass for which the form will gather information |
87afae6e4c51
Added basic 'invite' functionality
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
53 |
model = soc.models.request.Request |
87afae6e4c51
Added basic 'invite' functionality
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
54 |
|
528
5e6ae12cc495
Some indention and too long lines fixes in soc.views.models.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
521
diff
changeset
|
55 |
#: Exclude pretty much everything, model=None would |
5e6ae12cc495
Some indention and too long lines fixes in soc.views.models.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
521
diff
changeset
|
56 |
#: also remove the help text etc. |
569
96d9655a7538
Remove inheritance_line from Form meta class excludes in all currently used forms.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
560
diff
changeset
|
57 |
exclude = ['requester', 'to', 'role', |
528
5e6ae12cc495
Some indention and too long lines fixes in soc.views.models.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
521
diff
changeset
|
58 |
'accepted', 'declined'] |
495
87afae6e4c51
Added basic 'invite' functionality
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
59 |
|
87afae6e4c51
Added basic 'invite' functionality
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
60 |
requester = forms.CharField(widget=helper.widgets.ReadOnlyInput()) |
87afae6e4c51
Added basic 'invite' functionality
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
61 |
|
87afae6e4c51
Added basic 'invite' functionality
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
62 |
role = forms.CharField(widget=helper.widgets.ReadOnlyInput()) |
87afae6e4c51
Added basic 'invite' functionality
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
63 |
|
87afae6e4c51
Added basic 'invite' functionality
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
64 |
to = forms.CharField(widget=helper.widgets.ReadOnlyInput()) |
87afae6e4c51
Added basic 'invite' functionality
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
65 |
|
87afae6e4c51
Added basic 'invite' functionality
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
66 |
|
657
c781de4f6d39
Rename role.RoleView to role.View
Sverre Rabbelier <srabbelier@gmail.com>
parents:
656
diff
changeset
|
67 |
class View(base.View): |
499
d22e4fe8e64b
Fix missing dots in doc strings and some other doc string corrections.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
495
diff
changeset
|
68 |
"""Views for all entities that inherit from Role. |
495
87afae6e4c51
Added basic 'invite' functionality
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
69 |
|
87afae6e4c51
Added basic 'invite' functionality
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
70 |
All views that only Role entities have are defined in this subclass. |
87afae6e4c51
Added basic 'invite' functionality
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
71 |
""" |
518
d9d31d316a74
Changes the list template to use an instruction_text property that sets the text above the list. This makes the create_invite template unneeded. The instruction_text comes in handy when defining special lists.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
512
diff
changeset
|
72 |
|
538
4d209757c835
Make it more obvious that a format string constant is a format string by
Todd Larsen <tlarsen@google.com>
parents:
528
diff
changeset
|
73 |
DEF_INVITE_INSTRUCTION_MSG_FMT = ugettext_lazy( |
520
b0c623819b68
Split a too long line
Sverre Rabbelier <srabbelier@gmail.com>
parents:
518
diff
changeset
|
74 |
'Please use this form to invite someone to become a %(name)s.') |
495
87afae6e4c51
Added basic 'invite' functionality
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
75 |
|
616
580b1c21b808
Fixed requests not working anymore
Sverre Rabbelier <srabbelier@gmail.com>
parents:
572
diff
changeset
|
76 |
def __init__(self, params=None): |
495
87afae6e4c51
Added basic 'invite' functionality
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
77 |
""" |
87afae6e4c51
Added basic 'invite' functionality
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
78 |
|
87afae6e4c51
Added basic 'invite' functionality
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
79 |
Args: |
656
a76f1b443ea4
Cleanups in the views module
Sverre Rabbelier <srabbelier@gmail.com>
parents:
654
diff
changeset
|
80 |
params: This dictionary should be filled with the parameters |
495
87afae6e4c51
Added basic 'invite' functionality
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
81 |
""" |
87afae6e4c51
Added basic 'invite' functionality
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
82 |
|
660
5a381b290691
Introduced django_extra_patterns
Sverre Rabbelier <srabbelier@gmail.com>
parents:
657
diff
changeset
|
83 |
new_params = {} |
5a381b290691
Introduced django_extra_patterns
Sverre Rabbelier <srabbelier@gmail.com>
parents:
657
diff
changeset
|
84 |
|
710
edb5dbb1dea7
Add explicit access_types from the url
Sverre Rabbelier <srabbelier@gmail.com>
parents:
708
diff
changeset
|
85 |
patterns = [(r'^%(url_name)s/(?P<access_type>invite)/%(lnp)s$', |
660
5a381b290691
Introduced django_extra_patterns
Sverre Rabbelier <srabbelier@gmail.com>
parents:
657
diff
changeset
|
86 |
'soc.views.models.%(module_name)s.invite', |
5a381b290691
Introduced django_extra_patterns
Sverre Rabbelier <srabbelier@gmail.com>
parents:
657
diff
changeset
|
87 |
'Invite %(name_short)s')] |
5a381b290691
Introduced django_extra_patterns
Sverre Rabbelier <srabbelier@gmail.com>
parents:
657
diff
changeset
|
88 |
|
5a381b290691
Introduced django_extra_patterns
Sverre Rabbelier <srabbelier@gmail.com>
parents:
657
diff
changeset
|
89 |
new_params['extra_django_patterns'] = patterns |
663
c2dcae606699
Make base.View.create lookup the scope if appropriate
Sverre Rabbelier <srabbelier@gmail.com>
parents:
660
diff
changeset
|
90 |
new_params['scope_redirect'] = redirects.getInviteRedirect |
660
5a381b290691
Introduced django_extra_patterns
Sverre Rabbelier <srabbelier@gmail.com>
parents:
657
diff
changeset
|
91 |
|
5a381b290691
Introduced django_extra_patterns
Sverre Rabbelier <srabbelier@gmail.com>
parents:
657
diff
changeset
|
92 |
params = dicts.merge(params, new_params) |
5a381b290691
Introduced django_extra_patterns
Sverre Rabbelier <srabbelier@gmail.com>
parents:
657
diff
changeset
|
93 |
|
656
a76f1b443ea4
Cleanups in the views module
Sverre Rabbelier <srabbelier@gmail.com>
parents:
654
diff
changeset
|
94 |
super(View, self).__init__(params=params) |
495
87afae6e4c51
Added basic 'invite' functionality
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
95 |
|
710
edb5dbb1dea7
Add explicit access_types from the url
Sverre Rabbelier <srabbelier@gmail.com>
parents:
708
diff
changeset
|
96 |
def invite(self, request, access_type, |
876
0c1329d4b514
Make use of the new decorators in all applicable views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
858
diff
changeset
|
97 |
page_name=None, params=None, *args, **kwargs): |
495
87afae6e4c51
Added basic 'invite' functionality
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
98 |
"""Displays the request promotion to Role page. |
87afae6e4c51
Added basic 'invite' functionality
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
99 |
""" |
87afae6e4c51
Added basic 'invite' functionality
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
100 |
|
87afae6e4c51
Added basic 'invite' functionality
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
101 |
new_params = {} |
708
89f1a8c2ea59
Some cleanups in role.py and site.py and create()
Sverre Rabbelier <srabbelier@gmail.com>
parents:
668
diff
changeset
|
102 |
|
620
e74e0b74625f
Put the redirects in the views/helper/redirects.py module.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
616
diff
changeset
|
103 |
group_scope = kwargs['link_id'] |
495
87afae6e4c51
Added basic 'invite' functionality
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
104 |
|
708
89f1a8c2ea59
Some cleanups in role.py and site.py and create()
Sverre Rabbelier <srabbelier@gmail.com>
parents:
668
diff
changeset
|
105 |
new_params['list_action'] = (redirects.getCreateRequestRedirect, |
620
e74e0b74625f
Put the redirects in the views/helper/redirects.py module.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
616
diff
changeset
|
106 |
{'group_scope' : group_scope, |
708
89f1a8c2ea59
Some cleanups in role.py and site.py and create()
Sverre Rabbelier <srabbelier@gmail.com>
parents:
668
diff
changeset
|
107 |
'url_name' : self._params['url_name']}) |
647
355ac73823a1
Swap order of merged params to fix sponsor select view
Sverre Rabbelier <srabbelier@gmail.com>
parents:
646
diff
changeset
|
108 |
new_params['list_description'] = \ |
538
4d209757c835
Make it more obvious that a format string constant is a format string by
Todd Larsen <tlarsen@google.com>
parents:
528
diff
changeset
|
109 |
self.DEF_INVITE_INSTRUCTION_MSG_FMT % self._params |
708
89f1a8c2ea59
Some cleanups in role.py and site.py and create()
Sverre Rabbelier <srabbelier@gmail.com>
parents:
668
diff
changeset
|
110 |
new_params['logic'] = user_logic.logic |
495
87afae6e4c51
Added basic 'invite' functionality
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
111 |
|
708
89f1a8c2ea59
Some cleanups in role.py and site.py and create()
Sverre Rabbelier <srabbelier@gmail.com>
parents:
668
diff
changeset
|
112 |
new_params = dicts.merge(params, new_params) |
560
a32be584ee04
Requests are almost working now
Sverre Rabbelier <srabbelier@gmail.com>
parents:
543
diff
changeset
|
113 |
params = dicts.merge(new_params, user_view.view._params) |
876
0c1329d4b514
Make use of the new decorators in all applicable views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
858
diff
changeset
|
114 |
rights = params['rights'] |
495
87afae6e4c51
Added basic 'invite' functionality
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
115 |
|
87afae6e4c51
Added basic 'invite' functionality
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
116 |
try: |
876
0c1329d4b514
Make use of the new decorators in all applicable views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
858
diff
changeset
|
117 |
access.checkAccess(access_type, request, rights, args, kwargs) |
543
280a1ac6bcc1
Merge soc/logic/out_of_band.py into soc/views/out_of_band.py. Merge
Todd Larsen <tlarsen@google.com>
parents:
542
diff
changeset
|
118 |
except out_of_band.Error, error: |
646
860e17e5118f
Remove cyclic imports by moving response method of out_of_band.Error class to soc.views.helper.responses module as errorResponse function. Apply changes to affected files.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
624
diff
changeset
|
119 |
return helper.responses.errorResponse(error, request) |
495
87afae6e4c51
Added basic 'invite' functionality
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
120 |
|
651
ef6e22d463cb
Remove the logic parameter from getListContent
Sverre Rabbelier <srabbelier@gmail.com>
parents:
647
diff
changeset
|
121 |
content = helper.lists.getListContent(request, params) |
560
a32be584ee04
Requests are almost working now
Sverre Rabbelier <srabbelier@gmail.com>
parents:
543
diff
changeset
|
122 |
contents = [content] |
495
87afae6e4c51
Added basic 'invite' functionality
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
123 |
|
560
a32be584ee04
Requests are almost working now
Sverre Rabbelier <srabbelier@gmail.com>
parents:
543
diff
changeset
|
124 |
return self._list(request, params, contents, page_name) |
858
e79e7a22326f
Add an export() view, and implement it as text/text for Document.
Todd Larsen <tlarsen@google.com>
parents:
837
diff
changeset
|
125 |