17 """Views for Groups. |
17 """Views for Groups. |
18 """ |
18 """ |
19 |
19 |
20 __authors__ = [ |
20 __authors__ = [ |
21 '"Sverre Rabbelier" <sverre@rabbelier.nl>', |
21 '"Sverre Rabbelier" <sverre@rabbelier.nl>', |
|
22 '"Lennard de Rijk" <ljvderijk@gmail.com>', |
22 ] |
23 ] |
23 |
24 |
24 |
25 |
25 from google.appengine.api import users |
26 from google.appengine.api import users |
26 |
27 |
27 from django import forms |
28 from django import forms |
|
29 from django.utils.translation import ugettext |
28 |
30 |
29 from soc.logic import dicts |
31 from soc.logic import dicts |
30 from soc.logic.models import user as user_logic |
32 from soc.logic.models import user as user_logic |
|
33 from soc.views.helper import decorators |
|
34 from soc.views.helper import lists as list_helper |
|
35 from soc.views.helper import redirects |
31 from soc.views.helper import widgets |
36 from soc.views.helper import widgets |
32 from soc.views.models import base |
37 from soc.views.models import base |
|
38 from soc.views.models.request import view as request_view |
33 |
39 |
34 |
40 |
35 class View(base.View): |
41 class View(base.View): |
36 """View methods for the Group model. |
42 """View methods for the Group model. |
37 """ |
43 """ |
|
44 |
|
45 # TODO(ljvderijk) add sidebar entry for listRequests to each group |
38 |
46 |
39 def __init__(self, params=None): |
47 def __init__(self, params=None): |
40 """Defines the fields and methods required for the base View class |
48 """Defines the fields and methods required for the base View class |
41 to provide the user with list, public, create, edit and delete views. |
49 to provide the user with list, public, create, edit and delete views. |
42 |
50 |
53 'home', 'tos', 'member_template'] |
61 'home', 'tos', 'member_template'] |
54 new_params['edit_extra_dynafields'] = { |
62 new_params['edit_extra_dynafields'] = { |
55 'founded_by': forms.CharField(widget=widgets.ReadOnlyInput(), |
63 'founded_by': forms.CharField(widget=widgets.ReadOnlyInput(), |
56 required=False), |
64 required=False), |
57 } |
65 } |
|
66 |
|
67 #set the extra_django_patterns and include the one from params |
|
68 patterns = params.get('extra_django_patterns') |
|
69 |
|
70 if not patterns: |
|
71 patterns = [] |
|
72 |
|
73 patterns += [ |
|
74 (r'^%(url_name)s/(?P<access_type>list_requests)/%(key_fields)s$', |
|
75 'soc.views.models.%(module_name)s.list_requests', |
|
76 'List of requests for %(name)s')] |
|
77 |
|
78 new_params['extra_django_patterns'] = patterns |
58 |
79 |
59 # TODO(tlarsen): Add support for Django style template lookup |
80 # TODO(tlarsen): Add support for Django style template lookup |
60 new_params['public_template'] = 'soc/group/public.html' |
81 new_params['public_template'] = 'soc/group/public.html' |
61 |
82 |
62 new_params['list_row'] = 'soc/group/list/row.html' |
83 new_params['list_row'] = 'soc/group/list/row.html' |
84 user = user_logic.logic.getForFields({'account': account}, unique=True) |
105 user = user_logic.logic.getForFields({'account': account}, unique=True) |
85 fields['founder'] = user |
106 fields['founder'] = user |
86 |
107 |
87 super(View, self)._editPost(request, entity, fields) |
108 super(View, self)._editPost(request, entity, fields) |
88 |
109 |
|
110 @decorators.merge_params |
|
111 @decorators.check_access |
|
112 def listRequests(self, request, access_type, |
|
113 page_name=None, params=None, **kwargs): |
|
114 """Gives an overview of all the requests for a specific group. |
|
115 |
|
116 Args: |
|
117 request: the standard Django HTTP request object |
|
118 access_type : the name of the access type which should be checked |
|
119 page_name: the page name displayed in templates as page and header title |
|
120 params: a dict with params for this View |
|
121 kwargs: the Key Fields for the specified entity |
|
122 """ |
|
123 |
|
124 # set the pagename to include the link_id |
|
125 page_name = '%s %s' %(page_name, kwargs['link_id']) |
|
126 |
|
127 role_names = params['role_names'] |
|
128 |
|
129 # list all incoming requests |
|
130 filter = { |
|
131 'role': role_names, |
|
132 'state': 'new' |
|
133 } |
|
134 |
|
135 # create the list parameters |
|
136 inc_req_params = request_view.getParams() |
|
137 |
|
138 # define the list redirect action to the request processing page |
|
139 inc_req_params['list_action'] = (redirects.getProcessRequestRedirect, None) |
|
140 inc_req_params['list_description'] = ugettext( |
|
141 "An overview of the %(name)s's incoming requests." % params) |
|
142 |
|
143 inc_req_content = list_helper.getListContent( |
|
144 request, inc_req_params, filter, 0) |
|
145 |
|
146 # list all outstanding invites |
|
147 filter = { |
|
148 'role': role_names, |
|
149 'state': 'group_accepted' |
|
150 } |
|
151 |
|
152 # create the list parameters |
|
153 out_inv_params = request_view.getParams() |
|
154 |
|
155 # define the list redirect action to the request processing page |
|
156 out_inv_params['list_action'] = (redirects.getProcessRequestRedirect, None) |
|
157 out_inv_params['list_description'] = ugettext( |
|
158 "An overview of the %(name)s's outstanding invites." % params) |
|
159 |
|
160 out_inv_content = list_helper.getListContent( |
|
161 request, out_inv_params, filter, 1) |
|
162 |
|
163 # list all ignored requests |
|
164 filter = { |
|
165 'role': role_names, |
|
166 'state': 'ignored' |
|
167 } |
|
168 |
|
169 # create the list parameters |
|
170 ignored_params = request_view.getParams() |
|
171 |
|
172 # define the list redirect action to the request processing page |
|
173 ignored_params['list_action'] = (redirects.getProcessRequestRedirect, None) |
|
174 ignored_params['list_description'] = ugettext( |
|
175 "An overview of the %(name)s's ignored requests." % params) |
|
176 |
|
177 ignored_content = list_helper.getListContent( |
|
178 request, ignored_params, filter, 2) |
|
179 |
|
180 contents = [inc_req_content, out_inv_content, ignored_content] |
|
181 |
|
182 return self._list(request, params, contents, page_name) |