root / snf-astakos-app / astakos / im / views.py @ b22de10a
History | View | Annotate | Download (54.3 kB)
1 | aba1e498 | Antony Chazapis | # Copyright 2011-2012 GRNET S.A. All rights reserved.
|
---|---|---|---|
2 | 176023aa | Kostas Papadimitriou | #
|
3 | 64cd4730 | Antony Chazapis | # Redistribution and use in source and binary forms, with or
|
4 | 64cd4730 | Antony Chazapis | # without modification, are permitted provided that the following
|
5 | 64cd4730 | Antony Chazapis | # conditions are met:
|
6 | 176023aa | Kostas Papadimitriou | #
|
7 | 64cd4730 | Antony Chazapis | # 1. Redistributions of source code must retain the above
|
8 | 64cd4730 | Antony Chazapis | # copyright notice, this list of conditions and the following
|
9 | 64cd4730 | Antony Chazapis | # disclaimer.
|
10 | 176023aa | Kostas Papadimitriou | #
|
11 | 64cd4730 | Antony Chazapis | # 2. Redistributions in binary form must reproduce the above
|
12 | 64cd4730 | Antony Chazapis | # copyright notice, this list of conditions and the following
|
13 | 64cd4730 | Antony Chazapis | # disclaimer in the documentation and/or other materials
|
14 | 64cd4730 | Antony Chazapis | # provided with the distribution.
|
15 | 176023aa | Kostas Papadimitriou | #
|
16 | 64cd4730 | Antony Chazapis | # THIS SOFTWARE IS PROVIDED BY GRNET S.A. ``AS IS'' AND ANY EXPRESS
|
17 | 64cd4730 | Antony Chazapis | # OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
18 | 64cd4730 | Antony Chazapis | # WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
19 | 64cd4730 | Antony Chazapis | # PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL GRNET S.A OR
|
20 | 64cd4730 | Antony Chazapis | # CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
21 | 64cd4730 | Antony Chazapis | # SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
22 | 64cd4730 | Antony Chazapis | # LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
|
23 | 64cd4730 | Antony Chazapis | # USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
|
24 | 64cd4730 | Antony Chazapis | # AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
25 | 64cd4730 | Antony Chazapis | # LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
|
26 | 64cd4730 | Antony Chazapis | # ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
27 | 64cd4730 | Antony Chazapis | # POSSIBILITY OF SUCH DAMAGE.
|
28 | 176023aa | Kostas Papadimitriou | #
|
29 | 64cd4730 | Antony Chazapis | # The views and conclusions contained in the software and
|
30 | 64cd4730 | Antony Chazapis | # documentation are those of the authors and should not be
|
31 | 64cd4730 | Antony Chazapis | # interpreted as representing official policies, either expressed
|
32 | 64cd4730 | Antony Chazapis | # or implied, of GRNET S.A.
|
33 | 64cd4730 | Antony Chazapis | |
34 | 64cd4730 | Antony Chazapis | import logging |
35 | 6e029beb | Sofia Papagiannaki | import calendar |
36 | 9a06d96f | Olga Brani | import inflect |
37 | 9a06d96f | Olga Brani | |
38 | 9a06d96f | Olga Brani | engine = inflect.engine() |
39 | 64cd4730 | Antony Chazapis | |
40 | 0905ccd2 | Sofia Papagiannaki | from urllib import quote |
41 | 63ecdd20 | Sofia Papagiannaki | from functools import wraps |
42 | c0b26605 | Sofia Papagiannaki | from datetime import datetime |
43 | 64cd4730 | Antony Chazapis | |
44 | 890b0eaf | Sofia Papagiannaki | from django.contrib import messages |
45 | 01ac12d5 | Sofia Papagiannaki | from django.contrib.auth.decorators import login_required |
46 | 01ac12d5 | Sofia Papagiannaki | from django.core.urlresolvers import reverse |
47 | 01ac12d5 | Sofia Papagiannaki | from django.db import transaction |
48 | 01ac12d5 | Sofia Papagiannaki | from django.db.utils import IntegrityError |
49 | 9a06d96f | Olga Brani | from django.http import (HttpResponse, HttpResponseBadRequest, |
50 | 9a06d96f | Olga Brani | HttpResponseForbidden, HttpResponseRedirect, |
51 | 9a06d96f | Olga Brani | HttpResponseBadRequest, Http404) |
52 | 01ac12d5 | Sofia Papagiannaki | from django.shortcuts import redirect |
53 | 661c4479 | Sofia Papagiannaki | from django.template import RequestContext, loader as template_loader |
54 | 01ac12d5 | Sofia Papagiannaki | from django.utils.http import urlencode |
55 | 01ac12d5 | Sofia Papagiannaki | from django.utils.translation import ugettext as _ |
56 | e1a80257 | Sofia Papagiannaki | from django.views.generic.create_update import ( |
57 | e1a80257 | Sofia Papagiannaki | create_object, delete_object, get_model_and_form_class |
58 | e1a80257 | Sofia Papagiannaki | ) |
59 | f3342849 | Sofia Papagiannaki | from django.views.generic.list_detail import object_list, object_detail |
60 | 661c4479 | Sofia Papagiannaki | from django.core.xheaders import populate_xheaders |
61 | 792c2f3b | Olga Brani | from django.core.exceptions import ValidationError, PermissionDenied |
62 | c0b26605 | Sofia Papagiannaki | from django.template.loader import render_to_string |
63 | 9a06d96f | Olga Brani | from django.views.decorators.http import require_http_methods |
64 | 29b0ec5a | Sofia Papagiannaki | from django.db.models import Q |
65 | c0b26605 | Sofia Papagiannaki | |
66 | 29b0ec5a | Sofia Papagiannaki | from astakos.im.activation_backends import get_backend, SimpleBackend |
67 | e1a80257 | Sofia Papagiannaki | from astakos.im.models import ( |
68 | e1a80257 | Sofia Papagiannaki | AstakosUser, ApprovalTerms, AstakosGroup, |
69 | e1a80257 | Sofia Papagiannaki | EmailChange, GroupKind, Membership, |
70 | e1a80257 | Sofia Papagiannaki | RESOURCE_SEPARATOR, AstakosUserAuthProvider, |
71 | e1a80257 | Sofia Papagiannaki | ProjectApplication |
72 | e1a80257 | Sofia Papagiannaki | ) |
73 | c0b26605 | Sofia Papagiannaki | from astakos.im.util import get_context, prepare_response, get_query, restrict_next |
74 | e1a80257 | Sofia Papagiannaki | from astakos.im.forms import ( |
75 | e1a80257 | Sofia Papagiannaki | LoginForm, InvitationForm, ProfileForm, |
76 | e1a80257 | Sofia Papagiannaki | FeedbackForm, SignApprovalTermsForm, |
77 | e1a80257 | Sofia Papagiannaki | EmailChangeForm, |
78 | e1a80257 | Sofia Papagiannaki | AstakosGroupCreationForm, AstakosGroupSearchForm, |
79 | e1a80257 | Sofia Papagiannaki | AstakosGroupUpdateForm, AddGroupMembersForm, |
80 | e1a80257 | Sofia Papagiannaki | MembersSortForm, AstakosGroupSortForm, |
81 | e1a80257 | Sofia Papagiannaki | TimelineForm, PickResourceForm, |
82 | e1a80257 | Sofia Papagiannaki | AstakosGroupCreationSummaryForm, |
83 | e1a80257 | Sofia Papagiannaki | ProjectApplicationForm |
84 | e1a80257 | Sofia Papagiannaki | ) |
85 | f3342849 | Sofia Papagiannaki | from astakos.im.functions import ( |
86 | f3342849 | Sofia Papagiannaki | send_feedback, SendMailError, |
87 | f3342849 | Sofia Papagiannaki | logout as auth_logout,
|
88 | f3342849 | Sofia Papagiannaki | activate as activate_func,
|
89 | f3342849 | Sofia Papagiannaki | send_activation as send_activation_func,
|
90 | f3342849 | Sofia Papagiannaki | send_group_creation_notification, |
91 | f3342849 | Sofia Papagiannaki | SendNotificationError) |
92 | b6852727 | Olga Brani | from astakos.im.endpoints.qh import timeline_charge |
93 | f3342849 | Sofia Papagiannaki | from astakos.im.settings import ( |
94 | f3342849 | Sofia Papagiannaki | COOKIE_DOMAIN, LOGOUT_NEXT, |
95 | f3342849 | Sofia Papagiannaki | LOGGING_LEVEL, PAGINATE_BY, |
96 | f3342849 | Sofia Papagiannaki | RESOURCES_PRESENTATION_DATA, PAGINATE_BY_ALL |
97 | f3342849 | Sofia Papagiannaki | ) |
98 | f8f86e83 | root | #from astakos.im.tasks import request_billing
|
99 | 820b18e0 | Sofia Papagiannaki | from astakos.im.api.callpoint import AstakosCallpoint |
100 | e1a80257 | Sofia Papagiannaki | # from .generic_views import create_object
|
101 | 64cd4730 | Antony Chazapis | |
102 | ae497612 | Olga Brani | import astakos.im.messages as astakos_messages |
103 | 792c2f3b | Olga Brani | from astakos.im import settings |
104 | 792c2f3b | Olga Brani | from astakos.im import auth_providers |
105 | ae497612 | Olga Brani | |
106 | e015e9e6 | Sofia Papagiannaki | logger = logging.getLogger(__name__) |
107 | e015e9e6 | Sofia Papagiannaki | |
108 | 820b18e0 | Sofia Papagiannaki | callpoint = AstakosCallpoint() |
109 | 9a06d96f | Olga Brani | |
110 | b2ffa772 | Sofia Papagiannaki | def render_response(template, tab=None, status=200, context_instance=None, **kwargs): |
111 | 890b0eaf | Sofia Papagiannaki | """
|
112 | 890b0eaf | Sofia Papagiannaki | Calls ``django.template.loader.render_to_string`` with an additional ``tab``
|
113 | 890b0eaf | Sofia Papagiannaki | keyword argument and returns an ``django.http.HttpResponse`` with the
|
114 | 890b0eaf | Sofia Papagiannaki | specified ``status``.
|
115 | 890b0eaf | Sofia Papagiannaki | """
|
116 | 64cd4730 | Antony Chazapis | if tab is None: |
117 | 881c856c | Sofia Papagiannaki | tab = template.partition('_')[0].partition('.html')[0] |
118 | 64cd4730 | Antony Chazapis | kwargs.setdefault('tab', tab)
|
119 | 661c4479 | Sofia Papagiannaki | html = template_loader.render_to_string( |
120 | 5ce3ce4f | Sofia Papagiannaki | template, kwargs, context_instance=context_instance) |
121 | c301698f | Sofia Papagiannaki | response = HttpResponse(html, status=status) |
122 | c301698f | Sofia Papagiannaki | return response
|
123 | 64cd4730 | Antony Chazapis | |
124 | 792c2f3b | Olga Brani | def requires_auth_provider(provider_id, **perms): |
125 | 792c2f3b | Olga Brani | """
|
126 | 792c2f3b | Olga Brani | """
|
127 | 792c2f3b | Olga Brani | def decorator(func, *args, **kwargs): |
128 | 792c2f3b | Olga Brani | @wraps(func)
|
129 | 792c2f3b | Olga Brani | def wrapper(request, *args, **kwargs): |
130 | 792c2f3b | Olga Brani | provider = auth_providers.get_provider(provider_id) |
131 | 792c2f3b | Olga Brani | |
132 | 792c2f3b | Olga Brani | if not provider or not provider.is_active(): |
133 | 792c2f3b | Olga Brani | raise PermissionDenied
|
134 | 792c2f3b | Olga Brani | |
135 | 792c2f3b | Olga Brani | if provider:
|
136 | 792c2f3b | Olga Brani | for pkey, value in perms.iteritems(): |
137 | 792c2f3b | Olga Brani | attr = 'is_available_for_%s' % pkey.lower()
|
138 | 792c2f3b | Olga Brani | if getattr(provider, attr)() != value: |
139 | 792c2f3b | Olga Brani | raise PermissionDenied
|
140 | 792c2f3b | Olga Brani | return func(request, *args)
|
141 | 792c2f3b | Olga Brani | return wrapper
|
142 | 792c2f3b | Olga Brani | return decorator
|
143 | 792c2f3b | Olga Brani | |
144 | 63ecdd20 | Sofia Papagiannaki | |
145 | 63ecdd20 | Sofia Papagiannaki | def requires_anonymous(func): |
146 | 63ecdd20 | Sofia Papagiannaki | """
|
147 | 270dd48d | Sofia Papagiannaki | Decorator checkes whether the request.user is not Anonymous and in that case
|
148 | 7482228b | Sofia Papagiannaki | redirects to `logout`.
|
149 | 63ecdd20 | Sofia Papagiannaki | """
|
150 | 63ecdd20 | Sofia Papagiannaki | @wraps(func)
|
151 | 63ecdd20 | Sofia Papagiannaki | def wrapper(request, *args): |
152 | 63ecdd20 | Sofia Papagiannaki | if not request.user.is_anonymous(): |
153 | 63ecdd20 | Sofia Papagiannaki | next = urlencode({'next': request.build_absolute_uri()})
|
154 | 270dd48d | Sofia Papagiannaki | logout_uri = reverse(logout) + '?' + next |
155 | 270dd48d | Sofia Papagiannaki | return HttpResponseRedirect(logout_uri)
|
156 | 63ecdd20 | Sofia Papagiannaki | return func(request, *args)
|
157 | 63ecdd20 | Sofia Papagiannaki | return wrapper
|
158 | 63ecdd20 | Sofia Papagiannaki | |
159 | 5ce3ce4f | Sofia Papagiannaki | |
160 | 270dd48d | Sofia Papagiannaki | def signed_terms_required(func): |
161 | 270dd48d | Sofia Papagiannaki | """
|
162 | 270dd48d | Sofia Papagiannaki | Decorator checkes whether the request.user is Anonymous and in that case
|
163 | 270dd48d | Sofia Papagiannaki | redirects to `logout`.
|
164 | 270dd48d | Sofia Papagiannaki | """
|
165 | 270dd48d | Sofia Papagiannaki | @wraps(func)
|
166 | 270dd48d | Sofia Papagiannaki | def wrapper(request, *args, **kwargs): |
167 | fcf90160 | Sofia Papagiannaki | if request.user.is_authenticated() and not request.user.signed_terms: |
168 | 270dd48d | Sofia Papagiannaki | params = urlencode({'next': request.build_absolute_uri(),
|
169 | 5ce3ce4f | Sofia Papagiannaki | 'show_form': ''}) |
170 | 270dd48d | Sofia Papagiannaki | terms_uri = reverse('latest_terms') + '?' + params |
171 | 270dd48d | Sofia Papagiannaki | return HttpResponseRedirect(terms_uri)
|
172 | 270dd48d | Sofia Papagiannaki | return func(request, *args, **kwargs)
|
173 | 270dd48d | Sofia Papagiannaki | return wrapper
|
174 | 270dd48d | Sofia Papagiannaki | |
175 | 5ce3ce4f | Sofia Papagiannaki | |
176 | 9a06d96f | Olga Brani | @require_http_methods(["GET", "POST"]) |
177 | 270dd48d | Sofia Papagiannaki | @signed_terms_required
|
178 | 1f3b4b39 | Sofia Papagiannaki | def index(request, login_template_name='im/login.html', profile_template_name='im/profile.html', extra_context=None): |
179 | 890b0eaf | Sofia Papagiannaki | """
|
180 | dcf55476 | Sofia Papagiannaki | If there is logged on user renders the profile page otherwise renders login page.
|
181 | 176023aa | Kostas Papadimitriou |
|
182 | 890b0eaf | Sofia Papagiannaki | **Arguments**
|
183 | 176023aa | Kostas Papadimitriou |
|
184 | dcf55476 | Sofia Papagiannaki | ``login_template_name``
|
185 | dcf55476 | Sofia Papagiannaki | A custom login template to use. This is optional; if not specified,
|
186 | 1e685275 | Sofia Papagiannaki | this will default to ``im/login.html``.
|
187 | 176023aa | Kostas Papadimitriou |
|
188 | dcf55476 | Sofia Papagiannaki | ``profile_template_name``
|
189 | dcf55476 | Sofia Papagiannaki | A custom profile template to use. This is optional; if not specified,
|
190 | 1e685275 | Sofia Papagiannaki | this will default to ``im/profile.html``.
|
191 | 176023aa | Kostas Papadimitriou |
|
192 | 890b0eaf | Sofia Papagiannaki | ``extra_context``
|
193 | 890b0eaf | Sofia Papagiannaki | An dictionary of variables to add to the template context.
|
194 | 176023aa | Kostas Papadimitriou |
|
195 | 890b0eaf | Sofia Papagiannaki | **Template:**
|
196 | 176023aa | Kostas Papadimitriou |
|
197 | 1e685275 | Sofia Papagiannaki | im/profile.html or im/login.html or ``template_name`` keyword argument.
|
198 | 176023aa | Kostas Papadimitriou |
|
199 | 890b0eaf | Sofia Papagiannaki | """
|
200 | 1f3b4b39 | Sofia Papagiannaki | extra_context = extra_context or {}
|
201 | dcf55476 | Sofia Papagiannaki | template_name = login_template_name |
202 | dcf55476 | Sofia Papagiannaki | if request.user.is_authenticated():
|
203 | f534fb96 | Sofia Papagiannaki | return HttpResponseRedirect(reverse('astakos.im.views.edit_profile')) |
204 | 792c2f3b | Olga Brani | |
205 | ef20ea07 | Sofia Papagiannaki | return render_response(
|
206 | ef20ea07 | Sofia Papagiannaki | template_name, |
207 | ef20ea07 | Sofia Papagiannaki | login_form = LoginForm(request=request), |
208 | ef20ea07 | Sofia Papagiannaki | context_instance = get_context(request, extra_context) |
209 | ef20ea07 | Sofia Papagiannaki | ) |
210 | 5ce3ce4f | Sofia Papagiannaki | |
211 | 64cd4730 | Antony Chazapis | |
212 | 9a06d96f | Olga Brani | @require_http_methods(["GET", "POST"]) |
213 | 890b0eaf | Sofia Papagiannaki | @login_required
|
214 | 270dd48d | Sofia Papagiannaki | @signed_terms_required
|
215 | 890b0eaf | Sofia Papagiannaki | @transaction.commit_manually
|
216 | aab4d540 | Sofia Papagiannaki | def invite(request, template_name='im/invitations.html', extra_context=None): |
217 | 890b0eaf | Sofia Papagiannaki | """
|
218 | 890b0eaf | Sofia Papagiannaki | Allows a user to invite somebody else.
|
219 | 176023aa | Kostas Papadimitriou |
|
220 | 890b0eaf | Sofia Papagiannaki | In case of GET request renders a form for providing the invitee information.
|
221 | 890b0eaf | Sofia Papagiannaki | In case of POST checks whether the user has not run out of invitations and then
|
222 | 890b0eaf | Sofia Papagiannaki | sends an invitation email to singup to the service.
|
223 | 176023aa | Kostas Papadimitriou |
|
224 | 890b0eaf | Sofia Papagiannaki | The view uses commit_manually decorator in order to ensure the number of the
|
225 | 890b0eaf | Sofia Papagiannaki | user invitations is going to be updated only if the email has been successfully sent.
|
226 | 176023aa | Kostas Papadimitriou |
|
227 | 2cbaacd5 | Sofia Papagiannaki | If the user isn't logged in, redirects to settings.LOGIN_URL.
|
228 | 176023aa | Kostas Papadimitriou |
|
229 | 890b0eaf | Sofia Papagiannaki | **Arguments**
|
230 | 176023aa | Kostas Papadimitriou |
|
231 | 890b0eaf | Sofia Papagiannaki | ``template_name``
|
232 | 890b0eaf | Sofia Papagiannaki | A custom template to use. This is optional; if not specified,
|
233 | 1e685275 | Sofia Papagiannaki | this will default to ``im/invitations.html``.
|
234 | 176023aa | Kostas Papadimitriou |
|
235 | 890b0eaf | Sofia Papagiannaki | ``extra_context``
|
236 | 890b0eaf | Sofia Papagiannaki | An dictionary of variables to add to the template context.
|
237 | 176023aa | Kostas Papadimitriou |
|
238 | 890b0eaf | Sofia Papagiannaki | **Template:**
|
239 | 176023aa | Kostas Papadimitriou |
|
240 | 1e685275 | Sofia Papagiannaki | im/invitations.html or ``template_name`` keyword argument.
|
241 | 176023aa | Kostas Papadimitriou |
|
242 | 890b0eaf | Sofia Papagiannaki | **Settings:**
|
243 | 176023aa | Kostas Papadimitriou |
|
244 | 890b0eaf | Sofia Papagiannaki | The view expectes the following settings are defined:
|
245 | 176023aa | Kostas Papadimitriou |
|
246 | 890b0eaf | Sofia Papagiannaki | * LOGIN_URL: login uri
|
247 | 890b0eaf | Sofia Papagiannaki | """
|
248 | 1f3b4b39 | Sofia Papagiannaki | extra_context = extra_context or {}
|
249 | 64cd4730 | Antony Chazapis | status = None
|
250 | 64cd4730 | Antony Chazapis | message = None
|
251 | 8f5a3a06 | Sofia Papagiannaki | form = InvitationForm() |
252 | 5ce3ce4f | Sofia Papagiannaki | |
253 | 18ffbee1 | Sofia Papagiannaki | inviter = request.user |
254 | 64cd4730 | Antony Chazapis | if request.method == 'POST': |
255 | 8f5a3a06 | Sofia Papagiannaki | form = InvitationForm(request.POST) |
256 | 64cd4730 | Antony Chazapis | if inviter.invitations > 0: |
257 | 8f5a3a06 | Sofia Papagiannaki | if form.is_valid():
|
258 | 8f5a3a06 | Sofia Papagiannaki | try:
|
259 | 9a06d96f | Olga Brani | email = form.cleaned_data.get('username')
|
260 | 9a06d96f | Olga Brani | realname = form.cleaned_data.get('realname')
|
261 | 9a06d96f | Olga Brani | inviter.invite(email, realname) |
262 | ae497612 | Olga Brani | message = _(astakos_messages.INVITATION_SENT) % locals()
|
263 | 24406ae3 | Sofia Papagiannaki | messages.success(request, message) |
264 | 8f5a3a06 | Sofia Papagiannaki | except SendMailError, e:
|
265 | 8f5a3a06 | Sofia Papagiannaki | message = e.message |
266 | 24406ae3 | Sofia Papagiannaki | messages.error(request, message) |
267 | 8f5a3a06 | Sofia Papagiannaki | transaction.rollback() |
268 | 18ffbee1 | Sofia Papagiannaki | except BaseException, e: |
269 | ae497612 | Olga Brani | message = _(astakos_messages.GENERIC_ERROR) |
270 | 24406ae3 | Sofia Papagiannaki | messages.error(request, message) |
271 | 18ffbee1 | Sofia Papagiannaki | logger.exception(e) |
272 | 18ffbee1 | Sofia Papagiannaki | transaction.rollback() |
273 | 18ffbee1 | Sofia Papagiannaki | else:
|
274 | 18ffbee1 | Sofia Papagiannaki | transaction.commit() |
275 | 64cd4730 | Antony Chazapis | else:
|
276 | ae497612 | Olga Brani | message = _(astakos_messages.MAX_INVITATION_NUMBER_REACHED) |
277 | 24406ae3 | Sofia Papagiannaki | messages.error(request, message) |
278 | 176023aa | Kostas Papadimitriou | |
279 | a196eb7e | Sofia Papagiannaki | sent = [{'email': inv.username,
|
280 | d6ae71a2 | root | 'realname': inv.realname,
|
281 | d6ae71a2 | root | 'is_consumed': inv.is_consumed}
|
282 | 5ce3ce4f | Sofia Papagiannaki | for inv in request.user.invitations_sent.all()] |
283 | 77e2ad52 | root | kwargs = {'inviter': inviter,
|
284 | 5ce3ce4f | Sofia Papagiannaki | 'sent': sent}
|
285 | 0905ccd2 | Sofia Papagiannaki | context = get_context(request, extra_context, **kwargs) |
286 | 0905ccd2 | Sofia Papagiannaki | return render_response(template_name,
|
287 | 5ce3ce4f | Sofia Papagiannaki | invitation_form=form, |
288 | 5ce3ce4f | Sofia Papagiannaki | context_instance=context) |
289 | 5ce3ce4f | Sofia Papagiannaki | |
290 | 64cd4730 | Antony Chazapis | |
291 | 9a06d96f | Olga Brani | @require_http_methods(["GET", "POST"]) |
292 | 890b0eaf | Sofia Papagiannaki | @login_required
|
293 | 270dd48d | Sofia Papagiannaki | @signed_terms_required
|
294 | aab4d540 | Sofia Papagiannaki | def edit_profile(request, template_name='im/profile.html', extra_context=None): |
295 | 890b0eaf | Sofia Papagiannaki | """
|
296 | 890b0eaf | Sofia Papagiannaki | Allows a user to edit his/her profile.
|
297 | 176023aa | Kostas Papadimitriou |
|
298 | 890b0eaf | Sofia Papagiannaki | In case of GET request renders a form for displaying the user information.
|
299 | ce86cd44 | Sofia Papagiannaki | In case of POST updates the user informantion and redirects to ``next``
|
300 | ce86cd44 | Sofia Papagiannaki | url parameter if exists.
|
301 | 176023aa | Kostas Papadimitriou |
|
302 | 2cbaacd5 | Sofia Papagiannaki | If the user isn't logged in, redirects to settings.LOGIN_URL.
|
303 | 176023aa | Kostas Papadimitriou |
|
304 | 890b0eaf | Sofia Papagiannaki | **Arguments**
|
305 | 176023aa | Kostas Papadimitriou |
|
306 | 890b0eaf | Sofia Papagiannaki | ``template_name``
|
307 | 890b0eaf | Sofia Papagiannaki | A custom template to use. This is optional; if not specified,
|
308 | 1e685275 | Sofia Papagiannaki | this will default to ``im/profile.html``.
|
309 | 176023aa | Kostas Papadimitriou |
|
310 | 890b0eaf | Sofia Papagiannaki | ``extra_context``
|
311 | 890b0eaf | Sofia Papagiannaki | An dictionary of variables to add to the template context.
|
312 | 176023aa | Kostas Papadimitriou |
|
313 | 890b0eaf | Sofia Papagiannaki | **Template:**
|
314 | 176023aa | Kostas Papadimitriou |
|
315 | 1e685275 | Sofia Papagiannaki | im/profile.html or ``template_name`` keyword argument.
|
316 | 176023aa | Kostas Papadimitriou |
|
317 | 92defad4 | Sofia Papagiannaki | **Settings:**
|
318 | 176023aa | Kostas Papadimitriou |
|
319 | 92defad4 | Sofia Papagiannaki | The view expectes the following settings are defined:
|
320 | 176023aa | Kostas Papadimitriou |
|
321 | 92defad4 | Sofia Papagiannaki | * LOGIN_URL: login uri
|
322 | 890b0eaf | Sofia Papagiannaki | """
|
323 | aab4d540 | Sofia Papagiannaki | extra_context = extra_context or {}
|
324 | bf0c6de5 | Sofia Papagiannaki | form = ProfileForm( |
325 | bf0c6de5 | Sofia Papagiannaki | instance=request.user, |
326 | bf0c6de5 | Sofia Papagiannaki | session_key=request.session.session_key |
327 | bf0c6de5 | Sofia Papagiannaki | ) |
328 | 15efc749 | Sofia Papagiannaki | extra_context['next'] = request.GET.get('next') |
329 | 64cd4730 | Antony Chazapis | if request.method == 'POST': |
330 | bf0c6de5 | Sofia Papagiannaki | form = ProfileForm( |
331 | bf0c6de5 | Sofia Papagiannaki | request.POST, |
332 | bf0c6de5 | Sofia Papagiannaki | instance=request.user, |
333 | bf0c6de5 | Sofia Papagiannaki | session_key=request.session.session_key |
334 | bf0c6de5 | Sofia Papagiannaki | ) |
335 | 890b0eaf | Sofia Papagiannaki | if form.is_valid():
|
336 | 64cd4730 | Antony Chazapis | try:
|
337 | c301698f | Sofia Papagiannaki | prev_token = request.user.auth_token |
338 | c301698f | Sofia Papagiannaki | user = form.save() |
339 | bf0c6de5 | Sofia Papagiannaki | form = ProfileForm( |
340 | bf0c6de5 | Sofia Papagiannaki | instance=user, |
341 | bf0c6de5 | Sofia Papagiannaki | session_key=request.session.session_key |
342 | bf0c6de5 | Sofia Papagiannaki | ) |
343 | 217994f8 | Sofia Papagiannaki | next = restrict_next( |
344 | 217994f8 | Sofia Papagiannaki | request.POST.get('next'),
|
345 | 217994f8 | Sofia Papagiannaki | domain=COOKIE_DOMAIN |
346 | 217994f8 | Sofia Papagiannaki | ) |
347 | 1a3675a0 | Sofia Papagiannaki | if next: |
348 | 1a3675a0 | Sofia Papagiannaki | return redirect(next) |
349 | ae497612 | Olga Brani | msg = _(astakos_messages.PROFILE_UPDATED) |
350 | 24406ae3 | Sofia Papagiannaki | messages.success(request, msg) |
351 | 890b0eaf | Sofia Papagiannaki | except ValueError, ve: |
352 | 24406ae3 | Sofia Papagiannaki | messages.success(request, ve) |
353 | 23447441 | Sofia Papagiannaki | elif request.method == "GET": |
354 | 792c2f3b | Olga Brani | request.user.is_verified = True
|
355 | 792c2f3b | Olga Brani | request.user.save() |
356 | 792c2f3b | Olga Brani | |
357 | 792c2f3b | Olga Brani | # existing providers
|
358 | 792c2f3b | Olga Brani | user_providers = request.user.get_active_auth_providers() |
359 | 792c2f3b | Olga Brani | |
360 | 792c2f3b | Olga Brani | # providers that user can add
|
361 | 792c2f3b | Olga Brani | user_available_providers = request.user.get_available_auth_providers() |
362 | 792c2f3b | Olga Brani | |
363 | 0905ccd2 | Sofia Papagiannaki | return render_response(template_name,
|
364 | 8f5a3a06 | Sofia Papagiannaki | profile_form = form, |
365 | 792c2f3b | Olga Brani | user_providers = user_providers, |
366 | 792c2f3b | Olga Brani | user_available_providers = user_available_providers, |
367 | 0905ccd2 | Sofia Papagiannaki | context_instance = get_context(request, |
368 | c301698f | Sofia Papagiannaki | extra_context)) |
369 | 5ce3ce4f | Sofia Papagiannaki | |
370 | 64cd4730 | Antony Chazapis | |
371 | 10ed0073 | Sofia Papagiannaki | @transaction.commit_manually
|
372 | 9a06d96f | Olga Brani | @require_http_methods(["GET", "POST"]) |
373 | aab4d540 | Sofia Papagiannaki | def signup(request, template_name='im/signup.html', on_success='im/signup_complete.html', extra_context=None, backend=None): |
374 | 890b0eaf | Sofia Papagiannaki | """
|
375 | 890b0eaf | Sofia Papagiannaki | Allows a user to create a local account.
|
376 | 176023aa | Kostas Papadimitriou |
|
377 | b669d9c0 | Sofia Papagiannaki | In case of GET request renders a form for entering the user information.
|
378 | 890b0eaf | Sofia Papagiannaki | In case of POST handles the signup.
|
379 | 176023aa | Kostas Papadimitriou |
|
380 | 890b0eaf | Sofia Papagiannaki | The user activation will be delegated to the backend specified by the ``backend`` keyword argument
|
381 | 8f5a3a06 | Sofia Papagiannaki | if present, otherwise to the ``astakos.im.activation_backends.InvitationBackend``
|
382 | 8f5a3a06 | Sofia Papagiannaki | if settings.ASTAKOS_INVITATIONS_ENABLED is True or ``astakos.im.activation_backends.SimpleBackend`` if not
|
383 | 8f5a3a06 | Sofia Papagiannaki | (see activation_backends);
|
384 | 5ce3ce4f | Sofia Papagiannaki |
|
385 | b669d9c0 | Sofia Papagiannaki | Upon successful user creation, if ``next`` url parameter is present the user is redirected there
|
386 | 890b0eaf | Sofia Papagiannaki | otherwise renders the same page with a success message.
|
387 | 5ce3ce4f | Sofia Papagiannaki |
|
388 | 8f5a3a06 | Sofia Papagiannaki | On unsuccessful creation, renders ``template_name`` with an error message.
|
389 | 5ce3ce4f | Sofia Papagiannaki |
|
390 | 890b0eaf | Sofia Papagiannaki | **Arguments**
|
391 | 5ce3ce4f | Sofia Papagiannaki |
|
392 | 8f5a3a06 | Sofia Papagiannaki | ``template_name``
|
393 | 8f5a3a06 | Sofia Papagiannaki | A custom template to render. This is optional;
|
394 | 1e685275 | Sofia Papagiannaki | if not specified, this will default to ``im/signup.html``.
|
395 | 176023aa | Kostas Papadimitriou |
|
396 | f7e8a159 | Sofia Papagiannaki | ``on_success``
|
397 | f7e8a159 | Sofia Papagiannaki | A custom template to render in case of success. This is optional;
|
398 | 1e685275 | Sofia Papagiannaki | if not specified, this will default to ``im/signup_complete.html``.
|
399 | 176023aa | Kostas Papadimitriou |
|
400 | 890b0eaf | Sofia Papagiannaki | ``extra_context``
|
401 | 890b0eaf | Sofia Papagiannaki | An dictionary of variables to add to the template context.
|
402 | 176023aa | Kostas Papadimitriou |
|
403 | 890b0eaf | Sofia Papagiannaki | **Template:**
|
404 | 5ce3ce4f | Sofia Papagiannaki |
|
405 | 8f5a3a06 | Sofia Papagiannaki | im/signup.html or ``template_name`` keyword argument.
|
406 | 5ce3ce4f | Sofia Papagiannaki | im/signup_complete.html or ``on_success`` keyword argument.
|
407 | 890b0eaf | Sofia Papagiannaki | """
|
408 | 1f3b4b39 | Sofia Papagiannaki | extra_context = extra_context or {}
|
409 | 0d02a287 | Sofia Papagiannaki | if request.user.is_authenticated():
|
410 | 6ff7a7ca | Sofia Papagiannaki | return HttpResponseRedirect(reverse('edit_profile')) |
411 | 5ce3ce4f | Sofia Papagiannaki | |
412 | 0a569195 | Sofia Papagiannaki | provider = get_query(request).get('provider', 'local') |
413 | 792c2f3b | Olga Brani | if not auth_providers.get_provider(provider).is_available_for_create(): |
414 | 792c2f3b | Olga Brani | raise PermissionDenied
|
415 | 792c2f3b | Olga Brani | |
416 | 6c8a3f7c | Sofia Papagiannaki | id = get_query(request).get('id')
|
417 | 6c8a3f7c | Sofia Papagiannaki | try:
|
418 | 6c8a3f7c | Sofia Papagiannaki | instance = AstakosUser.objects.get(id=id) if id else None |
419 | 6c8a3f7c | Sofia Papagiannaki | except AstakosUser.DoesNotExist:
|
420 | 6c8a3f7c | Sofia Papagiannaki | instance = None
|
421 | 6c8a3f7c | Sofia Papagiannaki | |
422 | 8ab484ea | Kostas Papadimitriou | third_party_token = request.REQUEST.get('third_party_token', None) |
423 | 8ab484ea | Kostas Papadimitriou | |
424 | 890b0eaf | Sofia Papagiannaki | try:
|
425 | 18ffbee1 | Sofia Papagiannaki | if not backend: |
426 | 18ffbee1 | Sofia Papagiannaki | backend = get_backend(request) |
427 | 6c8a3f7c | Sofia Papagiannaki | form = backend.get_signup_form(provider, instance) |
428 | 0a569195 | Sofia Papagiannaki | except Exception, e: |
429 | 4e30244e | Sofia Papagiannaki | form = SimpleBackend(request).get_signup_form(provider) |
430 | 24406ae3 | Sofia Papagiannaki | messages.error(request, e) |
431 | 8f5a3a06 | Sofia Papagiannaki | if request.method == 'POST': |
432 | 8f5a3a06 | Sofia Papagiannaki | if form.is_valid():
|
433 | 18ffbee1 | Sofia Papagiannaki | user = form.save(commit=False)
|
434 | 8f5a3a06 | Sofia Papagiannaki | try:
|
435 | 8f5a3a06 | Sofia Papagiannaki | result = backend.handle_activation(user) |
436 | 8f5a3a06 | Sofia Papagiannaki | status = messages.SUCCESS |
437 | 18ffbee1 | Sofia Papagiannaki | message = result.message |
438 | 792c2f3b | Olga Brani | |
439 | 792c2f3b | Olga Brani | form.store_user(user, request) |
440 | 792c2f3b | Olga Brani | |
441 | ca828a10 | Sofia Papagiannaki | if 'additional_email' in form.cleaned_data: |
442 | ca828a10 | Sofia Papagiannaki | additional_email = form.cleaned_data['additional_email']
|
443 | ca828a10 | Sofia Papagiannaki | if additional_email != user.email:
|
444 | ca828a10 | Sofia Papagiannaki | user.additionalmail_set.create(email=additional_email) |
445 | 5ce3ce4f | Sofia Papagiannaki | msg = 'Additional email: %s saved for user %s.' % (
|
446 | 6c8a3f7c | Sofia Papagiannaki | additional_email, |
447 | 6c8a3f7c | Sofia Papagiannaki | user.email |
448 | 6c8a3f7c | Sofia Papagiannaki | ) |
449 | b669d9c0 | Sofia Papagiannaki | logger._log(LOGGING_LEVEL, msg, []) |
450 | 8f5a3a06 | Sofia Papagiannaki | if user and user.is_active: |
451 | 8f5a3a06 | Sofia Papagiannaki | next = request.POST.get('next', '') |
452 | 40a0cd8b | Sofia Papagiannaki | response = prepare_response(request, user, next=next)
|
453 | c3f6cdf1 | root | transaction.commit() |
454 | 40a0cd8b | Sofia Papagiannaki | return response
|
455 | 8f5a3a06 | Sofia Papagiannaki | messages.add_message(request, status, message) |
456 | 792c2f3b | Olga Brani | transaction.commit() |
457 | 6c8a3f7c | Sofia Papagiannaki | return render_response(
|
458 | 6c8a3f7c | Sofia Papagiannaki | on_success, |
459 | 6c8a3f7c | Sofia Papagiannaki | context_instance=get_context( |
460 | 6c8a3f7c | Sofia Papagiannaki | request, |
461 | 6c8a3f7c | Sofia Papagiannaki | extra_context |
462 | 6c8a3f7c | Sofia Papagiannaki | ) |
463 | 6c8a3f7c | Sofia Papagiannaki | ) |
464 | 18ffbee1 | Sofia Papagiannaki | except SendMailError, e:
|
465 | c44955a6 | Sofia Papagiannaki | logger.exception(e) |
466 | 18ffbee1 | Sofia Papagiannaki | status = messages.ERROR |
467 | 18ffbee1 | Sofia Papagiannaki | message = e.message |
468 | 24406ae3 | Sofia Papagiannaki | messages.error(request, message) |
469 | 10ed0073 | Sofia Papagiannaki | transaction.rollback() |
470 | 18ffbee1 | Sofia Papagiannaki | except BaseException, e: |
471 | 678b2236 | Sofia Papagiannaki | logger.exception(e) |
472 | ae497612 | Olga Brani | message = _(astakos_messages.GENERIC_ERROR) |
473 | 24406ae3 | Sofia Papagiannaki | messages.error(request, message) |
474 | 0a569195 | Sofia Papagiannaki | logger.exception(e) |
475 | 10ed0073 | Sofia Papagiannaki | transaction.rollback() |
476 | 8f5a3a06 | Sofia Papagiannaki | return render_response(template_name,
|
477 | 5ce3ce4f | Sofia Papagiannaki | signup_form=form, |
478 | 8ab484ea | Kostas Papadimitriou | third_party_token=third_party_token, |
479 | 5ce3ce4f | Sofia Papagiannaki | provider=provider, |
480 | 890b0eaf | Sofia Papagiannaki | context_instance=get_context(request, extra_context)) |
481 | 64cd4730 | Antony Chazapis | |
482 | 5ce3ce4f | Sofia Papagiannaki | |
483 | 9a06d96f | Olga Brani | @require_http_methods(["GET", "POST"]) |
484 | 890b0eaf | Sofia Papagiannaki | @login_required
|
485 | 270dd48d | Sofia Papagiannaki | @signed_terms_required
|
486 | aab4d540 | Sofia Papagiannaki | def feedback(request, template_name='im/feedback.html', email_template_name='im/feedback_mail.txt', extra_context=None): |
487 | 890b0eaf | Sofia Papagiannaki | """
|
488 | 890b0eaf | Sofia Papagiannaki | Allows a user to send feedback.
|
489 | 176023aa | Kostas Papadimitriou |
|
490 | 890b0eaf | Sofia Papagiannaki | In case of GET request renders a form for providing the feedback information.
|
491 | 890b0eaf | Sofia Papagiannaki | In case of POST sends an email to support team.
|
492 | 176023aa | Kostas Papadimitriou |
|
493 | 2cbaacd5 | Sofia Papagiannaki | If the user isn't logged in, redirects to settings.LOGIN_URL.
|
494 | 176023aa | Kostas Papadimitriou |
|
495 | 890b0eaf | Sofia Papagiannaki | **Arguments**
|
496 | 176023aa | Kostas Papadimitriou |
|
497 | 890b0eaf | Sofia Papagiannaki | ``template_name``
|
498 | 890b0eaf | Sofia Papagiannaki | A custom template to use. This is optional; if not specified,
|
499 | 1e685275 | Sofia Papagiannaki | this will default to ``im/feedback.html``.
|
500 | 176023aa | Kostas Papadimitriou |
|
501 | 890b0eaf | Sofia Papagiannaki | ``extra_context``
|
502 | 890b0eaf | Sofia Papagiannaki | An dictionary of variables to add to the template context.
|
503 | 176023aa | Kostas Papadimitriou |
|
504 | 890b0eaf | Sofia Papagiannaki | **Template:**
|
505 | 176023aa | Kostas Papadimitriou |
|
506 | 1e685275 | Sofia Papagiannaki | im/signup.html or ``template_name`` keyword argument.
|
507 | 176023aa | Kostas Papadimitriou |
|
508 | 890b0eaf | Sofia Papagiannaki | **Settings:**
|
509 | 176023aa | Kostas Papadimitriou |
|
510 | 92defad4 | Sofia Papagiannaki | * LOGIN_URL: login uri
|
511 | 890b0eaf | Sofia Papagiannaki | """
|
512 | 1f3b4b39 | Sofia Papagiannaki | extra_context = extra_context or {}
|
513 | 64cd4730 | Antony Chazapis | if request.method == 'GET': |
514 | 890b0eaf | Sofia Papagiannaki | form = FeedbackForm() |
515 | 890b0eaf | Sofia Papagiannaki | if request.method == 'POST': |
516 | 890b0eaf | Sofia Papagiannaki | if not request.user: |
517 | 890b0eaf | Sofia Papagiannaki | return HttpResponse('Unauthorized', status=401) |
518 | 176023aa | Kostas Papadimitriou | |
519 | 890b0eaf | Sofia Papagiannaki | form = FeedbackForm(request.POST) |
520 | 890b0eaf | Sofia Papagiannaki | if form.is_valid():
|
521 | e9083112 | Sofia Papagiannaki | msg = form.cleaned_data['feedback_msg']
|
522 | 8f5a3a06 | Sofia Papagiannaki | data = form.cleaned_data['feedback_data']
|
523 | 538ccdd5 | Sofia Papagiannaki | try:
|
524 | 8f5a3a06 | Sofia Papagiannaki | send_feedback(msg, data, request.user, email_template_name) |
525 | 8f5a3a06 | Sofia Papagiannaki | except SendMailError, e:
|
526 | 24406ae3 | Sofia Papagiannaki | messages.error(request, message) |
527 | 8f5a3a06 | Sofia Papagiannaki | else:
|
528 | ae497612 | Olga Brani | message = _(astakos_messages.FEEDBACK_SENT) |
529 | aab4d540 | Sofia Papagiannaki | messages.success(request, message) |
530 | 890b0eaf | Sofia Papagiannaki | return render_response(template_name,
|
531 | 5ce3ce4f | Sofia Papagiannaki | feedback_form=form, |
532 | 5ce3ce4f | Sofia Papagiannaki | context_instance=get_context(request, extra_context)) |
533 | 5ce3ce4f | Sofia Papagiannaki | |
534 | 15efc749 | Sofia Papagiannaki | |
535 | 217994f8 | Sofia Papagiannaki | @require_http_methods(["GET"]) |
536 | 8e45d6fd | Sofia Papagiannaki | @signed_terms_required
|
537 | aab4d540 | Sofia Papagiannaki | def logout(request, template='registration/logged_out.html', extra_context=None): |
538 | 63ecdd20 | Sofia Papagiannaki | """
|
539 | b2ffa772 | Sofia Papagiannaki | Wraps `django.contrib.auth.logout`.
|
540 | 63ecdd20 | Sofia Papagiannaki | """
|
541 | 1f3b4b39 | Sofia Papagiannaki | extra_context = extra_context or {}
|
542 | 7482228b | Sofia Papagiannaki | response = HttpResponse() |
543 | 8e45d6fd | Sofia Papagiannaki | if request.user.is_authenticated():
|
544 | 8e45d6fd | Sofia Papagiannaki | email = request.user.email |
545 | 8e45d6fd | Sofia Papagiannaki | auth_logout(request) |
546 | 217994f8 | Sofia Papagiannaki | next = restrict_next( |
547 | 217994f8 | Sofia Papagiannaki | request.GET.get('next'),
|
548 | 217994f8 | Sofia Papagiannaki | domain=COOKIE_DOMAIN |
549 | 217994f8 | Sofia Papagiannaki | ) |
550 | 63ecdd20 | Sofia Papagiannaki | if next: |
551 | 63ecdd20 | Sofia Papagiannaki | response['Location'] = next |
552 | 63ecdd20 | Sofia Papagiannaki | response.status_code = 302
|
553 | 0d02a287 | Sofia Papagiannaki | elif LOGOUT_NEXT:
|
554 | 0d02a287 | Sofia Papagiannaki | response['Location'] = LOGOUT_NEXT
|
555 | 0d02a287 | Sofia Papagiannaki | response.status_code = 301
|
556 | b2ffa772 | Sofia Papagiannaki | else:
|
557 | c0b26605 | Sofia Papagiannaki | messages.add_message(request, messages.SUCCESS, _(astakos_messages.LOGOUT_SUCCESS)) |
558 | b2ffa772 | Sofia Papagiannaki | context = get_context(request, extra_context) |
559 | b2ffa772 | Sofia Papagiannaki | response.write(render_to_string(template, context_instance=context)) |
560 | 49df775e | Sofia Papagiannaki | return response
|
561 | 2126d85d | Sofia Papagiannaki | |
562 | 5ce3ce4f | Sofia Papagiannaki | |
563 | 9a06d96f | Olga Brani | @require_http_methods(["GET", "POST"]) |
564 | 683cf244 | Sofia Papagiannaki | @transaction.commit_manually
|
565 | 3bb604eb | Sofia Papagiannaki | def activate(request, greeting_email_template_name='im/welcome_email.txt', |
566 | 3bb604eb | Sofia Papagiannaki | helpdesk_email_template_name='im/helpdesk_notification.txt'):
|
567 | 2126d85d | Sofia Papagiannaki | """
|
568 | 683cf244 | Sofia Papagiannaki | Activates the user identified by the ``auth`` request parameter, sends a welcome email
|
569 | 683cf244 | Sofia Papagiannaki | and renews the user token.
|
570 | 176023aa | Kostas Papadimitriou |
|
571 | 683cf244 | Sofia Papagiannaki | The view uses commit_manually decorator in order to ensure the user state will be updated
|
572 | 683cf244 | Sofia Papagiannaki | only if the email will be send successfully.
|
573 | 2126d85d | Sofia Papagiannaki | """
|
574 | 2126d85d | Sofia Papagiannaki | token = request.GET.get('auth')
|
575 | 2126d85d | Sofia Papagiannaki | next = request.GET.get('next')
|
576 | 2126d85d | Sofia Papagiannaki | try:
|
577 | 2126d85d | Sofia Papagiannaki | user = AstakosUser.objects.get(auth_token=token) |
578 | 2126d85d | Sofia Papagiannaki | except AstakosUser.DoesNotExist:
|
579 | ae497612 | Olga Brani | return HttpResponseBadRequest(_(astakos_messages.ACCOUNT_UNKNOWN))
|
580 | 5ce3ce4f | Sofia Papagiannaki | |
581 | d1757ca7 | Sofia Papagiannaki | if user.is_active:
|
582 | ae497612 | Olga Brani | message = _(astakos_messages.ACCOUNT_ALREADY_ACTIVE) |
583 | 24406ae3 | Sofia Papagiannaki | messages.error(request, message) |
584 | 23b9b72f | Sofia Papagiannaki | return index(request)
|
585 | 5ce3ce4f | Sofia Papagiannaki | |
586 | 0a569195 | Sofia Papagiannaki | try:
|
587 | ef20ea07 | Sofia Papagiannaki | activate_func(user, greeting_email_template_name, helpdesk_email_template_name, verify_email=True)
|
588 | ef20ea07 | Sofia Papagiannaki | response = prepare_response(request, user, next, renew=True) |
589 | ef20ea07 | Sofia Papagiannaki | transaction.commit() |
590 | ef20ea07 | Sofia Papagiannaki | return response
|
591 | ef20ea07 | Sofia Papagiannaki | except SendMailError, e:
|
592 | ef20ea07 | Sofia Papagiannaki | message = e.message |
593 | ef20ea07 | Sofia Papagiannaki | messages.add_message(request, messages.ERROR, message) |
594 | ef20ea07 | Sofia Papagiannaki | transaction.rollback() |
595 | ef20ea07 | Sofia Papagiannaki | return index(request)
|
596 | ef20ea07 | Sofia Papagiannaki | except BaseException, e: |
597 | ef20ea07 | Sofia Papagiannaki | status = messages.ERROR |
598 | c0b26605 | Sofia Papagiannaki | message = _(astakos_messages.GENERIC_ERROR) |
599 | ef20ea07 | Sofia Papagiannaki | messages.add_message(request, messages.ERROR, message) |
600 | ef20ea07 | Sofia Papagiannaki | logger.exception(e) |
601 | ef20ea07 | Sofia Papagiannaki | transaction.rollback() |
602 | ef20ea07 | Sofia Papagiannaki | return index(request)
|
603 | 270dd48d | Sofia Papagiannaki | |
604 | 5ce3ce4f | Sofia Papagiannaki | |
605 | 9a06d96f | Olga Brani | @require_http_methods(["GET", "POST"]) |
606 | aab4d540 | Sofia Papagiannaki | def approval_terms(request, term_id=None, template_name='im/approval_terms.html', extra_context=None): |
607 | 1f3b4b39 | Sofia Papagiannaki | extra_context = extra_context or {}
|
608 | 270dd48d | Sofia Papagiannaki | term = None
|
609 | 270dd48d | Sofia Papagiannaki | terms = None
|
610 | 270dd48d | Sofia Papagiannaki | if not term_id: |
611 | 270dd48d | Sofia Papagiannaki | try:
|
612 | 270dd48d | Sofia Papagiannaki | term = ApprovalTerms.objects.order_by('-id')[0] |
613 | 270dd48d | Sofia Papagiannaki | except IndexError: |
614 | 270dd48d | Sofia Papagiannaki | pass
|
615 | 270dd48d | Sofia Papagiannaki | else:
|
616 | 270dd48d | Sofia Papagiannaki | try:
|
617 | aab4d540 | Sofia Papagiannaki | term = ApprovalTerms.objects.get(id=term_id) |
618 | aab4d540 | Sofia Papagiannaki | except ApprovalTerms.DoesNotExist, e:
|
619 | 270dd48d | Sofia Papagiannaki | pass
|
620 | 176023aa | Kostas Papadimitriou | |
621 | 270dd48d | Sofia Papagiannaki | if not term: |
622 | ae497612 | Olga Brani | messages.error(request, _(astakos_messages.NO_APPROVAL_TERMS)) |
623 | 6ff7a7ca | Sofia Papagiannaki | return HttpResponseRedirect(reverse('index')) |
624 | 270dd48d | Sofia Papagiannaki | f = open(term.location, 'r') |
625 | 270dd48d | Sofia Papagiannaki | terms = f.read() |
626 | 176023aa | Kostas Papadimitriou | |
627 | 270dd48d | Sofia Papagiannaki | if request.method == 'POST': |
628 | 217994f8 | Sofia Papagiannaki | next = restrict_next( |
629 | 217994f8 | Sofia Papagiannaki | request.POST.get('next'),
|
630 | 217994f8 | Sofia Papagiannaki | domain=COOKIE_DOMAIN |
631 | 217994f8 | Sofia Papagiannaki | ) |
632 | 270dd48d | Sofia Papagiannaki | if not next: |
633 | 6ff7a7ca | Sofia Papagiannaki | next = reverse('index')
|
634 | 270dd48d | Sofia Papagiannaki | form = SignApprovalTermsForm(request.POST, instance=request.user) |
635 | 270dd48d | Sofia Papagiannaki | if not form.is_valid(): |
636 | 270dd48d | Sofia Papagiannaki | return render_response(template_name,
|
637 | 5ce3ce4f | Sofia Papagiannaki | terms=terms, |
638 | 5ce3ce4f | Sofia Papagiannaki | approval_terms_form=form, |
639 | 5ce3ce4f | Sofia Papagiannaki | context_instance=get_context(request, extra_context)) |
640 | 270dd48d | Sofia Papagiannaki | user = form.save() |
641 | 270dd48d | Sofia Papagiannaki | return HttpResponseRedirect(next) |
642 | 270dd48d | Sofia Papagiannaki | else:
|
643 | 586967c0 | Sofia Papagiannaki | form = None
|
644 | fcf90160 | Sofia Papagiannaki | if request.user.is_authenticated() and not request.user.signed_terms: |
645 | 586967c0 | Sofia Papagiannaki | form = SignApprovalTermsForm(instance=request.user) |
646 | 270dd48d | Sofia Papagiannaki | return render_response(template_name,
|
647 | 5ce3ce4f | Sofia Papagiannaki | terms=terms, |
648 | 5ce3ce4f | Sofia Papagiannaki | approval_terms_form=form, |
649 | 5ce3ce4f | Sofia Papagiannaki | context_instance=get_context(request, extra_context)) |
650 | 5ce3ce4f | Sofia Papagiannaki | |
651 | 270dd48d | Sofia Papagiannaki | |
652 | 9a06d96f | Olga Brani | @require_http_methods(["GET", "POST"]) |
653 | 8e45d6fd | Sofia Papagiannaki | @login_required
|
654 | dda2e499 | Sofia Papagiannaki | @signed_terms_required
|
655 | 49790d9d | Sofia Papagiannaki | @transaction.commit_manually
|
656 | 49790d9d | Sofia Papagiannaki | def change_email(request, activation_key=None, |
657 | 49790d9d | Sofia Papagiannaki | email_template_name='registration/email_change_email.txt',
|
658 | 49790d9d | Sofia Papagiannaki | form_template_name='registration/email_change_form.html',
|
659 | 49790d9d | Sofia Papagiannaki | confirm_template_name='registration/email_change_done.html',
|
660 | aab4d540 | Sofia Papagiannaki | extra_context=None):
|
661 | 1f3b4b39 | Sofia Papagiannaki | extra_context = extra_context or {}
|
662 | 49790d9d | Sofia Papagiannaki | if activation_key:
|
663 | 49790d9d | Sofia Papagiannaki | try:
|
664 | 49790d9d | Sofia Papagiannaki | user = EmailChange.objects.change_email(activation_key) |
665 | 49790d9d | Sofia Papagiannaki | if request.user.is_authenticated() and request.user == user: |
666 | ae497612 | Olga Brani | msg = _(astakos_messages.EMAIL_CHANGED) |
667 | 24406ae3 | Sofia Papagiannaki | messages.success(request, msg) |
668 | 49790d9d | Sofia Papagiannaki | auth_logout(request) |
669 | 49790d9d | Sofia Papagiannaki | response = prepare_response(request, user) |
670 | 49790d9d | Sofia Papagiannaki | transaction.commit() |
671 | 49790d9d | Sofia Papagiannaki | return response
|
672 | 49790d9d | Sofia Papagiannaki | except ValueError, e: |
673 | 24406ae3 | Sofia Papagiannaki | messages.error(request, e) |
674 | 49790d9d | Sofia Papagiannaki | return render_response(confirm_template_name,
|
675 | 5ce3ce4f | Sofia Papagiannaki | modified_user=user if 'user' in locals( |
676 | 5ce3ce4f | Sofia Papagiannaki | ) else None, |
677 | 5ce3ce4f | Sofia Papagiannaki | context_instance=get_context(request, |
678 | 5ce3ce4f | Sofia Papagiannaki | extra_context)) |
679 | 5ce3ce4f | Sofia Papagiannaki | |
680 | 49790d9d | Sofia Papagiannaki | if not request.user.is_authenticated(): |
681 | 49790d9d | Sofia Papagiannaki | path = quote(request.get_full_path()) |
682 | 6ff7a7ca | Sofia Papagiannaki | url = request.build_absolute_uri(reverse('index'))
|
683 | 49790d9d | Sofia Papagiannaki | return HttpResponseRedirect(url + '?next=' + path) |
684 | 49790d9d | Sofia Papagiannaki | form = EmailChangeForm(request.POST or None) |
685 | 49790d9d | Sofia Papagiannaki | if request.method == 'POST' and form.is_valid(): |
686 | 49790d9d | Sofia Papagiannaki | try:
|
687 | 49790d9d | Sofia Papagiannaki | ec = form.save(email_template_name, request) |
688 | 49790d9d | Sofia Papagiannaki | except SendMailError, e:
|
689 | 49790d9d | Sofia Papagiannaki | msg = e |
690 | 24406ae3 | Sofia Papagiannaki | messages.error(request, msg) |
691 | 49790d9d | Sofia Papagiannaki | transaction.rollback() |
692 | 49790d9d | Sofia Papagiannaki | except IntegrityError, e:
|
693 | ae497612 | Olga Brani | msg = _(astakos_messages.PENDING_EMAIL_CHANGE_REQUEST) |
694 | 24406ae3 | Sofia Papagiannaki | messages.error(request, msg) |
695 | 49790d9d | Sofia Papagiannaki | else:
|
696 | ae497612 | Olga Brani | msg = _(astakos_messages.EMAIL_CHANGE_REGISTERED) |
697 | 24406ae3 | Sofia Papagiannaki | messages.success(request, msg) |
698 | 49790d9d | Sofia Papagiannaki | transaction.commit() |
699 | c0b26605 | Sofia Papagiannaki | return render_response(
|
700 | c0b26605 | Sofia Papagiannaki | form_template_name, |
701 | c0b26605 | Sofia Papagiannaki | form=form, |
702 | c0b26605 | Sofia Papagiannaki | context_instance=get_context(request, extra_context) |
703 | c0b26605 | Sofia Papagiannaki | ) |
704 | 1f3b4b39 | Sofia Papagiannaki | |
705 | 1f3b4b39 | Sofia Papagiannaki | |
706 | 1f3b4b39 | Sofia Papagiannaki | def send_activation(request, user_id, template_name='im/login.html', extra_context=None): |
707 | 792c2f3b | Olga Brani | |
708 | 792c2f3b | Olga Brani | if settings.MODERATION_ENABLED:
|
709 | 792c2f3b | Olga Brani | raise PermissionDenied
|
710 | 792c2f3b | Olga Brani | |
711 | 1f3b4b39 | Sofia Papagiannaki | extra_context = extra_context or {}
|
712 | 1f3b4b39 | Sofia Papagiannaki | try:
|
713 | 1f3b4b39 | Sofia Papagiannaki | u = AstakosUser.objects.get(id=user_id) |
714 | 1f3b4b39 | Sofia Papagiannaki | except AstakosUser.DoesNotExist:
|
715 | c0b26605 | Sofia Papagiannaki | messages.error(request, _(astakos_messages.ACCOUNT_UNKNOWN)) |
716 | 1f3b4b39 | Sofia Papagiannaki | else:
|
717 | 1f3b4b39 | Sofia Papagiannaki | try:
|
718 | 1f3b4b39 | Sofia Papagiannaki | send_activation_func(u) |
719 | c0b26605 | Sofia Papagiannaki | msg = _(astakos_messages.ACTIVATION_SENT) |
720 | 1f3b4b39 | Sofia Papagiannaki | messages.success(request, msg) |
721 | 1f3b4b39 | Sofia Papagiannaki | except SendMailError, e:
|
722 | 1f3b4b39 | Sofia Papagiannaki | messages.error(request, e) |
723 | 1f3b4b39 | Sofia Papagiannaki | return render_response(
|
724 | 1f3b4b39 | Sofia Papagiannaki | template_name, |
725 | c0b26605 | Sofia Papagiannaki | login_form = LoginForm(request=request), |
726 | 1f3b4b39 | Sofia Papagiannaki | context_instance = get_context( |
727 | 1f3b4b39 | Sofia Papagiannaki | request, |
728 | 1f3b4b39 | Sofia Papagiannaki | extra_context |
729 | 1f3b4b39 | Sofia Papagiannaki | ) |
730 | 1f3b4b39 | Sofia Papagiannaki | ) |
731 | 5ce3ce4f | Sofia Papagiannaki | |
732 | 3cbd5e47 | Olga Brani | class ResourcePresentation(): |
733 | 792c2f3b | Olga Brani | |
734 | 3cbd5e47 | Olga Brani | def __init__(self, data): |
735 | 3cbd5e47 | Olga Brani | self.data = data
|
736 | 792c2f3b | Olga Brani | |
737 | 3cbd5e47 | Olga Brani | def update_from_result(self, result): |
738 | 3cbd5e47 | Olga Brani | if result.is_success:
|
739 | 3cbd5e47 | Olga Brani | for r in result.data: |
740 | 3cbd5e47 | Olga Brani | rname = '%s%s%s' % (r.get('service'), RESOURCE_SEPARATOR, r.get('name')) |
741 | 3cbd5e47 | Olga Brani | if not rname in self.data['resources']: |
742 | 3cbd5e47 | Olga Brani | self.data['resources'][rname] = {} |
743 | 792c2f3b | Olga Brani | |
744 | 3cbd5e47 | Olga Brani | self.data['resources'][rname].update(r) |
745 | 3cbd5e47 | Olga Brani | self.data['resources'][rname]['id'] = rname |
746 | 3cbd5e47 | Olga Brani | group = r.get('group')
|
747 | 3cbd5e47 | Olga Brani | if not group in self.data['groups']: |
748 | 3cbd5e47 | Olga Brani | self.data['groups'][group] = {} |
749 | 792c2f3b | Olga Brani | |
750 | 3cbd5e47 | Olga Brani | self.data['groups'][r.get('group')].update({'name': r.get('group')}) |
751 | 792c2f3b | Olga Brani | |
752 | 3cbd5e47 | Olga Brani | def test(self, quota_dict): |
753 | 3cbd5e47 | Olga Brani | for k, v in quota_dict.iteritems(): |
754 | 3cbd5e47 | Olga Brani | rname = k |
755 | 3cbd5e47 | Olga Brani | value = v |
756 | 3cbd5e47 | Olga Brani | if not rname in self.data['resources']: |
757 | c0b26605 | Sofia Papagiannaki | self.data['resources'][rname] = {} |
758 | 792c2f3b | Olga Brani | |
759 | 792c2f3b | Olga Brani | |
760 | 3cbd5e47 | Olga Brani | self.data['resources'][rname]['value'] = value |
761 | 792c2f3b | Olga Brani | |
762 | 792c2f3b | Olga Brani | |
763 | 3cbd5e47 | Olga Brani | def update_from_result_report(self, result): |
764 | 3cbd5e47 | Olga Brani | if result.is_success:
|
765 | 3cbd5e47 | Olga Brani | for r in result.data: |
766 | 3cbd5e47 | Olga Brani | rname = r.get('name')
|
767 | 3cbd5e47 | Olga Brani | if not rname in self.data['resources']: |
768 | 3cbd5e47 | Olga Brani | self.data['resources'][rname] = {} |
769 | 792c2f3b | Olga Brani | |
770 | 3cbd5e47 | Olga Brani | self.data['resources'][rname].update(r) |
771 | 3cbd5e47 | Olga Brani | self.data['resources'][rname]['id'] = rname |
772 | 3cbd5e47 | Olga Brani | group = r.get('group')
|
773 | 3cbd5e47 | Olga Brani | if not group in self.data['groups']: |
774 | 3cbd5e47 | Olga Brani | self.data['groups'][group] = {} |
775 | 792c2f3b | Olga Brani | |
776 | 3cbd5e47 | Olga Brani | self.data['groups'][r.get('group')].update({'name': r.get('group')}) |
777 | 792c2f3b | Olga Brani | |
778 | 3cbd5e47 | Olga Brani | def get_group_resources(self, group): |
779 | 3cbd5e47 | Olga Brani | return dict(filter(lambda t: t[1].get('group') == group, self.data['resources'].iteritems())) |
780 | 792c2f3b | Olga Brani | |
781 | 3cbd5e47 | Olga Brani | def get_groups_resources(self): |
782 | 3cbd5e47 | Olga Brani | for g in self.data['groups']: |
783 | 3cbd5e47 | Olga Brani | yield g, self.get_group_resources(g) |
784 | 792c2f3b | Olga Brani | |
785 | 3cbd5e47 | Olga Brani | def get_quota(self, group_quotas): |
786 | 3cbd5e47 | Olga Brani | for r, v in group_quotas.iteritems(): |
787 | 3cbd5e47 | Olga Brani | rname = str(r)
|
788 | 3cbd5e47 | Olga Brani | quota = self.data['resources'].get(rname) |
789 | 3cbd5e47 | Olga Brani | quota['value'] = v
|
790 | 3cbd5e47 | Olga Brani | yield quota
|
791 | 792c2f3b | Olga Brani | |
792 | 792c2f3b | Olga Brani | |
793 | 3cbd5e47 | Olga Brani | def get_policies(self, policies_data): |
794 | 3cbd5e47 | Olga Brani | for policy in policies_data: |
795 | 3cbd5e47 | Olga Brani | rname = '%s%s%s' % (policy.get('service'), RESOURCE_SEPARATOR, policy.get('resource')) |
796 | 3cbd5e47 | Olga Brani | policy.update(self.data['resources'].get(rname)) |
797 | 3cbd5e47 | Olga Brani | yield policy
|
798 | 792c2f3b | Olga Brani | |
799 | 3cbd5e47 | Olga Brani | def __repr__(self): |
800 | 3cbd5e47 | Olga Brani | return self.data.__repr__() |
801 | 792c2f3b | Olga Brani | |
802 | 3cbd5e47 | Olga Brani | def __iter__(self, *args, **kwargs): |
803 | 3cbd5e47 | Olga Brani | return self.data.__iter__(*args, **kwargs) |
804 | 792c2f3b | Olga Brani | |
805 | 3cbd5e47 | Olga Brani | def __getitem__(self, *args, **kwargs): |
806 | 3cbd5e47 | Olga Brani | return self.data.__getitem__(*args, **kwargs) |
807 | 792c2f3b | Olga Brani | |
808 | 3cbd5e47 | Olga Brani | def get(self, *args, **kwargs): |
809 | 3cbd5e47 | Olga Brani | return self.data.get(*args, **kwargs) |
810 | 792c2f3b | Olga Brani | |
811 | 792c2f3b | Olga Brani | |
812 | 12269b45 | Olga Brani | |
813 | 8c804c12 | Sofia Papagiannaki | @require_http_methods(["GET", "POST"]) |
814 | 8e45d6fd | Sofia Papagiannaki | @signed_terms_required
|
815 | 01ac12d5 | Sofia Papagiannaki | @login_required
|
816 | 0f4fa26d | Sofia Papagiannaki | def group_add(request, kind_name='default'): |
817 | 820b18e0 | Sofia Papagiannaki | result = callpoint.list_resources() |
818 | 3cbd5e47 | Olga Brani | resource_catalog = ResourcePresentation(RESOURCES_PRESENTATION_DATA) |
819 | 3cbd5e47 | Olga Brani | resource_catalog.update_from_result(result) |
820 | 792c2f3b | Olga Brani | |
821 | 3cbd5e47 | Olga Brani | if not result.is_success: |
822 | 820b18e0 | Sofia Papagiannaki | messages.error( |
823 | 820b18e0 | Sofia Papagiannaki | request, |
824 | 820b18e0 | Sofia Papagiannaki | 'Unable to retrieve system resources: %s' % result.reason
|
825 | 820b18e0 | Sofia Papagiannaki | ) |
826 | 792c2f3b | Olga Brani | |
827 | 0f4fa26d | Sofia Papagiannaki | try:
|
828 | 5ce3ce4f | Sofia Papagiannaki | kind = GroupKind.objects.get(name=kind_name) |
829 | 0f4fa26d | Sofia Papagiannaki | except:
|
830 | ae497612 | Olga Brani | return HttpResponseBadRequest(_(astakos_messages.GROUPKIND_UNKNOWN))
|
831 | 792c2f3b | Olga Brani | |
832 | 792c2f3b | Olga Brani | |
833 | 5ce3ce4f | Sofia Papagiannaki | |
834 | 5ce3ce4f | Sofia Papagiannaki | post_save_redirect = '/im/group/%(id)s/'
|
835 | 5ce3ce4f | Sofia Papagiannaki | context_processors = None
|
836 | 0f4fa26d | Sofia Papagiannaki | model, form_class = get_model_and_form_class( |
837 | 0f4fa26d | Sofia Papagiannaki | model=None,
|
838 | 0f4fa26d | Sofia Papagiannaki | form_class=AstakosGroupCreationForm |
839 | 0f4fa26d | Sofia Papagiannaki | ) |
840 | 792c2f3b | Olga Brani | |
841 | 0f4fa26d | Sofia Papagiannaki | if request.method == 'POST': |
842 | 820b18e0 | Sofia Papagiannaki | form = form_class(request.POST, request.FILES) |
843 | 0f4fa26d | Sofia Papagiannaki | if form.is_valid():
|
844 | 513571c3 | Sofia Papagiannaki | policies = form.policies() |
845 | 8c804c12 | Sofia Papagiannaki | return render_response(
|
846 | 8c804c12 | Sofia Papagiannaki | template='im/astakosgroup_form_summary.html',
|
847 | 8c804c12 | Sofia Papagiannaki | context_instance=get_context(request), |
848 | 513571c3 | Sofia Papagiannaki | form=AstakosGroupCreationSummaryForm(form.cleaned_data), |
849 | 513571c3 | Sofia Papagiannaki | policies=resource_catalog.get_policies(policies) |
850 | 8c804c12 | Sofia Papagiannaki | ) |
851 | 0f4fa26d | Sofia Papagiannaki | else:
|
852 | 0f4fa26d | Sofia Papagiannaki | now = datetime.now() |
853 | 0f4fa26d | Sofia Papagiannaki | data = { |
854 | 6abd262c | Olga Brani | 'kind': kind,
|
855 | 0f4fa26d | Sofia Papagiannaki | } |
856 | 3cbd5e47 | Olga Brani | for group, resources in resource_catalog.get_groups_resources(): |
857 | 6abd262c | Olga Brani | data['is_selected_%s' % group] = False |
858 | 6abd262c | Olga Brani | for resource in resources: |
859 | 6abd262c | Olga Brani | data['%s_uplimit' % resource] = '' |
860 | 792c2f3b | Olga Brani | |
861 | 820b18e0 | Sofia Papagiannaki | form = form_class(data) |
862 | 0f4fa26d | Sofia Papagiannaki | |
863 | 0f4fa26d | Sofia Papagiannaki | # Create the template, context, response
|
864 | ae497612 | Olga Brani | template_name = "%s/%s_form.html" % (
|
865 | 0f4fa26d | Sofia Papagiannaki | model._meta.app_label, |
866 | 0f4fa26d | Sofia Papagiannaki | model._meta.object_name.lower() |
867 | 0f4fa26d | Sofia Papagiannaki | ) |
868 | 0f4fa26d | Sofia Papagiannaki | t = template_loader.get_template(template_name) |
869 | 0f4fa26d | Sofia Papagiannaki | c = RequestContext(request, { |
870 | c8977d75 | Olga Brani | 'form': form,
|
871 | c8977d75 | Olga Brani | 'kind': kind,
|
872 | 820b18e0 | Sofia Papagiannaki | 'resource_catalog':resource_catalog,
|
873 | 0f4fa26d | Sofia Papagiannaki | }, context_processors) |
874 | 0f4fa26d | Sofia Papagiannaki | return HttpResponse(t.render(c))
|
875 | 8e45d6fd | Sofia Papagiannaki | |
876 | 8c804c12 | Sofia Papagiannaki | |
877 | e1a80257 | Sofia Papagiannaki | #@require_hsttp_methods(["POST"])
|
878 | ae497612 | Olga Brani | @require_http_methods(["GET", "POST"]) |
879 | 29b87e7c | Sofia Papagiannaki | @signed_terms_required
|
880 | 29b87e7c | Sofia Papagiannaki | @login_required
|
881 | e1a80257 | Sofia Papagiannaki | @transaction.commit_manually
|
882 | 8c804c12 | Sofia Papagiannaki | def group_add_complete(request): |
883 | 29b87e7c | Sofia Papagiannaki | model = AstakosGroup |
884 | 29b87e7c | Sofia Papagiannaki | form = AstakosGroupCreationSummaryForm(request.POST) |
885 | 29b87e7c | Sofia Papagiannaki | if form.is_valid():
|
886 | 29b87e7c | Sofia Papagiannaki | d = form.cleaned_data |
887 | 29b87e7c | Sofia Papagiannaki | d['owners'] = [request.user]
|
888 | 29b87e7c | Sofia Papagiannaki | result = callpoint.create_groups((d,)).next() |
889 | 29b87e7c | Sofia Papagiannaki | if result.is_success:
|
890 | 29b87e7c | Sofia Papagiannaki | new_object = result.data[0]
|
891 | 29b87e7c | Sofia Papagiannaki | # send notification
|
892 | 29b87e7c | Sofia Papagiannaki | try:
|
893 | 29b87e7c | Sofia Papagiannaki | send_group_creation_notification( |
894 | 29b87e7c | Sofia Papagiannaki | template_name='im/group_creation_notification.txt',
|
895 | 29b87e7c | Sofia Papagiannaki | dictionary={ |
896 | 29b87e7c | Sofia Papagiannaki | 'group': new_object,
|
897 | 29b87e7c | Sofia Papagiannaki | 'owner': request.user,
|
898 | 29b87e7c | Sofia Papagiannaki | 'policies': d.get('policies', []) |
899 | 29b87e7c | Sofia Papagiannaki | } |
900 | 29b87e7c | Sofia Papagiannaki | ) |
901 | 29b87e7c | Sofia Papagiannaki | except SendNotificationError, e:
|
902 | 29b87e7c | Sofia Papagiannaki | messages.error(request, e, fail_silently=True)
|
903 | e1a80257 | Sofia Papagiannaki | transaction.rollback() |
904 | e1a80257 | Sofia Papagiannaki | else:
|
905 | e1a80257 | Sofia Papagiannaki | msg = _(astakos_messages.OBJECT_CREATED) %\ |
906 | e1a80257 | Sofia Papagiannaki | {"verbose_name": model._meta.verbose_name}
|
907 | e1a80257 | Sofia Papagiannaki | message = _(astakos_messages.NOTIFICATION_SENT) % 'a project'
|
908 | e1a80257 | Sofia Papagiannaki | messages.success(request, msg, fail_silently=True)
|
909 | e1a80257 | Sofia Papagiannaki | transaction.commit() |
910 | 29b87e7c | Sofia Papagiannaki | else:
|
911 | 3cbd5e47 | Olga Brani | d = {"verbose_name": model._meta.verbose_name,
|
912 | 29b87e7c | Sofia Papagiannaki | "reason":result.reason}
|
913 | 792c2f3b | Olga Brani | msg = _(astakos_messages.OBJECT_CREATED_FAILED) % d |
914 | 29b87e7c | Sofia Papagiannaki | messages.error(request, msg, fail_silently=True)
|
915 | 8c804c12 | Sofia Papagiannaki | return render_response(
|
916 | 29b87e7c | Sofia Papagiannaki | template='im/astakosgroup_form_summary.html',
|
917 | 29b87e7c | Sofia Papagiannaki | context_instance=get_context(request), |
918 | 513571c3 | Sofia Papagiannaki | form=form, |
919 | 513571c3 | Sofia Papagiannaki | policies=form.cleaned_data.get('policies')
|
920 | 513571c3 | Sofia Papagiannaki | ) |
921 | 8c804c12 | Sofia Papagiannaki | |
922 | 8c804c12 | Sofia Papagiannaki | |
923 | ae497612 | Olga Brani | #@require_http_methods(["GET"])
|
924 | ae497612 | Olga Brani | @require_http_methods(["GET", "POST"]) |
925 | 8e45d6fd | Sofia Papagiannaki | @signed_terms_required
|
926 | 8e45d6fd | Sofia Papagiannaki | @login_required
|
927 | ade90760 | Sofia Papagiannaki | def group_list(request): |
928 | 789bcaf9 | Sofia Papagiannaki | none = request.user.astakos_groups.none() |
929 | 3cbd5e47 | Olga Brani | query = """
|
930 | 789bcaf9 | Sofia Papagiannaki | SELECT auth_group.id,
|
931 | 098f333b | Sofia Papagiannaki | auth_group.name AS groupname,
|
932 | 789bcaf9 | Sofia Papagiannaki | im_groupkind.name AS kindname,
|
933 | 789bcaf9 | Sofia Papagiannaki | im_astakosgroup.*,
|
934 | 789bcaf9 | Sofia Papagiannaki | owner.email AS groupowner,
|
935 | 789bcaf9 | Sofia Papagiannaki | (SELECT COUNT(*) FROM im_membership
|
936 | 789bcaf9 | Sofia Papagiannaki | WHERE group_id = im_astakosgroup.group_ptr_id
|
937 | 789bcaf9 | Sofia Papagiannaki | AND date_joined IS NOT NULL) AS approved_members_num,
|
938 | 04febd09 | Olga Brani | (SELECT CASE WHEN(
|
939 | 04febd09 | Olga Brani | SELECT date_joined FROM im_membership
|
940 | 04febd09 | Olga Brani | WHERE group_id = im_astakosgroup.group_ptr_id
|
941 | 289f8c2e | Sofia Papagiannaki | AND person_id = %(id)s) IS NULL
|
942 | 0f225db4 | Sofia Papagiannaki | THEN 0 ELSE 1 END) AS membership_status
|
943 | 789bcaf9 | Sofia Papagiannaki | FROM im_astakosgroup
|
944 | 789bcaf9 | Sofia Papagiannaki | INNER JOIN im_membership ON (
|
945 | 789bcaf9 | Sofia Papagiannaki | im_astakosgroup.group_ptr_id = im_membership.group_id)
|
946 | 789bcaf9 | Sofia Papagiannaki | INNER JOIN auth_group ON(im_astakosgroup.group_ptr_id = auth_group.id)
|
947 | 789bcaf9 | Sofia Papagiannaki | INNER JOIN im_groupkind ON (im_astakosgroup.kind_id = im_groupkind.id)
|
948 | 789bcaf9 | Sofia Papagiannaki | LEFT JOIN im_astakosuser_owner ON (
|
949 | 789bcaf9 | Sofia Papagiannaki | im_astakosuser_owner.astakosgroup_id = im_astakosgroup.group_ptr_id)
|
950 | 789bcaf9 | Sofia Papagiannaki | LEFT JOIN auth_user as owner ON (
|
951 | 789bcaf9 | Sofia Papagiannaki | im_astakosuser_owner.astakosuser_id = owner.id)
|
952 | 289f8c2e | Sofia Papagiannaki | WHERE im_membership.person_id = %(id)s
|
953 | 29b0ec5a | Sofia Papagiannaki | AND im_groupkind.name != 'default'
|
954 | 289f8c2e | Sofia Papagiannaki | """ % request.user.__dict__
|
955 | 792c2f3b | Olga Brani | |
956 | 098f333b | Sofia Papagiannaki | # validate sorting
|
957 | 098f333b | Sofia Papagiannaki | sorting = 'groupname'
|
958 | 098f333b | Sofia Papagiannaki | sort_form = AstakosGroupSortForm(request.GET) |
959 | 098f333b | Sofia Papagiannaki | if sort_form.is_valid():
|
960 | 098f333b | Sofia Papagiannaki | sorting = sort_form.cleaned_data.get('sorting')
|
961 | 098f333b | Sofia Papagiannaki | query = query+" ORDER BY %s ASC" %sorting
|
962 | 098f333b | Sofia Papagiannaki | |
963 | 289f8c2e | Sofia Papagiannaki | q = AstakosGroup.objects.raw(query) |
964 | 098f333b | Sofia Papagiannaki | |
965 | f2a4ce70 | Sofia Papagiannaki | # Create the template, context, response
|
966 | f2a4ce70 | Sofia Papagiannaki | template_name = "%s/%s_list.html" % (
|
967 | f2a4ce70 | Sofia Papagiannaki | q.model._meta.app_label, |
968 | f2a4ce70 | Sofia Papagiannaki | q.model._meta.object_name.lower() |
969 | f2a4ce70 | Sofia Papagiannaki | ) |
970 | f2a4ce70 | Sofia Papagiannaki | extra_context = dict(
|
971 | f2a4ce70 | Sofia Papagiannaki | is_search=False,
|
972 | f2a4ce70 | Sofia Papagiannaki | q=q, |
973 | 098f333b | Sofia Papagiannaki | sorting=sorting, |
974 | f2a4ce70 | Sofia Papagiannaki | page=request.GET.get('page', 1) |
975 | f2a4ce70 | Sofia Papagiannaki | ) |
976 | f2a4ce70 | Sofia Papagiannaki | return render_response(template_name,
|
977 | f2a4ce70 | Sofia Papagiannaki | context_instance=get_context(request, extra_context) |
978 | f2a4ce70 | Sofia Papagiannaki | ) |
979 | 5ce3ce4f | Sofia Papagiannaki | |
980 | 8e45d6fd | Sofia Papagiannaki | |
981 | 8c804c12 | Sofia Papagiannaki | @require_http_methods(["GET", "POST"]) |
982 | 8e45d6fd | Sofia Papagiannaki | @signed_terms_required
|
983 | 8e45d6fd | Sofia Papagiannaki | @login_required
|
984 | 8e45d6fd | Sofia Papagiannaki | def group_detail(request, group_id): |
985 | 032ade79 | Sofia Papagiannaki | q = AstakosGroup.objects.select_related().filter(pk=group_id) |
986 | 661c4479 | Sofia Papagiannaki | q = q.extra(select={ |
987 | 661c4479 | Sofia Papagiannaki | 'is_member': """SELECT CASE WHEN EXISTS( |
988 | 661c4479 | Sofia Papagiannaki | SELECT id FROM im_membership
|
989 | 661c4479 | Sofia Papagiannaki | WHERE group_id = im_astakosgroup.group_ptr_id
|
990 | 661c4479 | Sofia Papagiannaki | AND person_id = %s)
|
991 | 661c4479 | Sofia Papagiannaki | THEN 1 ELSE 0 END""" % request.user.id,
|
992 | 661c4479 | Sofia Papagiannaki | 'is_owner': """SELECT CASE WHEN EXISTS( |
993 | 032ade79 | Sofia Papagiannaki | SELECT id FROM im_astakosuser_owner
|
994 | 032ade79 | Sofia Papagiannaki | WHERE astakosgroup_id = im_astakosgroup.group_ptr_id
|
995 | 032ade79 | Sofia Papagiannaki | AND astakosuser_id = %s)
|
996 | 661c4479 | Sofia Papagiannaki | THEN 1 ELSE 0 END""" % request.user.id,
|
997 | 394c9834 | Olga Brani | 'is_active_member': """SELECT CASE WHEN( |
998 | 394c9834 | Olga Brani | SELECT date_joined FROM im_membership
|
999 | 394c9834 | Olga Brani | WHERE group_id = im_astakosgroup.group_ptr_id
|
1000 | 394c9834 | Olga Brani | AND person_id = %s) IS NULL
|
1001 | 394c9834 | Olga Brani | THEN 0 ELSE 1 END""" % request.user.id,
|
1002 | 661c4479 | Sofia Papagiannaki | 'kindname': """SELECT name FROM im_groupkind |
1003 | 661c4479 | Sofia Papagiannaki | WHERE id = im_astakosgroup.kind_id"""})
|
1004 | 9a06d96f | Olga Brani | |
1005 | 661c4479 | Sofia Papagiannaki | model = q.model |
1006 | 661c4479 | Sofia Papagiannaki | context_processors = None
|
1007 | 661c4479 | Sofia Papagiannaki | mimetype = None
|
1008 | 8e45d6fd | Sofia Papagiannaki | try:
|
1009 | 661c4479 | Sofia Papagiannaki | obj = q.get() |
1010 | 032ade79 | Sofia Papagiannaki | except AstakosGroup.DoesNotExist:
|
1011 | 032ade79 | Sofia Papagiannaki | raise Http404("No %s found matching the query" % ( |
1012 | 032ade79 | Sofia Papagiannaki | model._meta.verbose_name)) |
1013 | 9a06d96f | Olga Brani | |
1014 | 661c4479 | Sofia Papagiannaki | update_form = AstakosGroupUpdateForm(instance=obj) |
1015 | 661c4479 | Sofia Papagiannaki | addmembers_form = AddGroupMembersForm() |
1016 | 661c4479 | Sofia Papagiannaki | if request.method == 'POST': |
1017 | 661c4479 | Sofia Papagiannaki | update_data = {} |
1018 | 661c4479 | Sofia Papagiannaki | addmembers_data = {} |
1019 | 9a06d96f | Olga Brani | for k, v in request.POST.iteritems(): |
1020 | 661c4479 | Sofia Papagiannaki | if k in update_form.fields: |
1021 | 661c4479 | Sofia Papagiannaki | update_data[k] = v |
1022 | 661c4479 | Sofia Papagiannaki | if k in addmembers_form.fields: |
1023 | 661c4479 | Sofia Papagiannaki | addmembers_data[k] = v |
1024 | 661c4479 | Sofia Papagiannaki | update_data = update_data or None |
1025 | 661c4479 | Sofia Papagiannaki | addmembers_data = addmembers_data or None |
1026 | 661c4479 | Sofia Papagiannaki | update_form = AstakosGroupUpdateForm(update_data, instance=obj) |
1027 | 661c4479 | Sofia Papagiannaki | addmembers_form = AddGroupMembersForm(addmembers_data) |
1028 | 661c4479 | Sofia Papagiannaki | if update_form.is_valid():
|
1029 | 661c4479 | Sofia Papagiannaki | update_form.save() |
1030 | 661c4479 | Sofia Papagiannaki | if addmembers_form.is_valid():
|
1031 | ae497612 | Olga Brani | try:
|
1032 | ae497612 | Olga Brani | map(obj.approve_member, addmembers_form.valid_users)
|
1033 | ae497612 | Olga Brani | except AssertionError: |
1034 | ae497612 | Olga Brani | msg = _(astakos_messages.GROUP_MAX_PARTICIPANT_NUMBER_REACHED) |
1035 | ae497612 | Olga Brani | messages.error(request, msg) |
1036 | 661c4479 | Sofia Papagiannaki | addmembers_form = AddGroupMembersForm() |
1037 | 9a06d96f | Olga Brani | |
1038 | 9a06d96f | Olga Brani | template_name = "%s/%s_detail.html" % (
|
1039 | 9a06d96f | Olga Brani | model._meta.app_label, model._meta.object_name.lower()) |
1040 | 661c4479 | Sofia Papagiannaki | t = template_loader.get_template(template_name) |
1041 | 661c4479 | Sofia Papagiannaki | c = RequestContext(request, { |
1042 | 661c4479 | Sofia Papagiannaki | 'object': obj,
|
1043 | 661c4479 | Sofia Papagiannaki | }, context_processors) |
1044 | 9a06d96f | Olga Brani | |
1045 | 801be7a3 | Sofia Papagiannaki | # validate sorting
|
1046 | bfaeedb6 | Sofia Papagiannaki | sorting = 'person__email'
|
1047 | bfaeedb6 | Sofia Papagiannaki | form = MembersSortForm(request.GET) |
1048 | bfaeedb6 | Sofia Papagiannaki | if form.is_valid():
|
1049 | bfaeedb6 | Sofia Papagiannaki | sorting = form.cleaned_data.get('sorting')
|
1050 | bfaeedb6 | Sofia Papagiannaki | |
1051 | bdc1c103 | Olga Brani | result = callpoint.list_resources() |
1052 | 3cbd5e47 | Olga Brani | resource_catalog = ResourcePresentation(RESOURCES_PRESENTATION_DATA) |
1053 | 3cbd5e47 | Olga Brani | resource_catalog.update_from_result(result) |
1054 | 3cbd5e47 | Olga Brani | |
1055 | 792c2f3b | Olga Brani | |
1056 | 3cbd5e47 | Olga Brani | if not result.is_success: |
1057 | 3cbd5e47 | Olga Brani | messages.error( |
1058 | 3cbd5e47 | Olga Brani | request, |
1059 | 3cbd5e47 | Olga Brani | 'Unable to retrieve system resources: %s' % result.reason
|
1060 | 3cbd5e47 | Olga Brani | ) |
1061 | 792c2f3b | Olga Brani | |
1062 | 661c4479 | Sofia Papagiannaki | extra_context = {'update_form': update_form,
|
1063 | 661c4479 | Sofia Papagiannaki | 'addmembers_form': addmembers_form,
|
1064 | 661c4479 | Sofia Papagiannaki | 'page': request.GET.get('page', 1), |
1065 | bdc1c103 | Olga Brani | 'sorting': sorting,
|
1066 | bdc1c103 | Olga Brani | 'resource_catalog':resource_catalog,
|
1067 | 3cbd5e47 | Olga Brani | 'quota':resource_catalog.get_quota(obj.quota)}
|
1068 | 661c4479 | Sofia Papagiannaki | for key, value in extra_context.items(): |
1069 | 661c4479 | Sofia Papagiannaki | if callable(value): |
1070 | 661c4479 | Sofia Papagiannaki | c[key] = value() |
1071 | 04febd09 | Olga Brani | else:
|
1072 | 661c4479 | Sofia Papagiannaki | c[key] = value |
1073 | 661c4479 | Sofia Papagiannaki | response = HttpResponse(t.render(c), mimetype=mimetype) |
1074 | 9a06d96f | Olga Brani | populate_xheaders( |
1075 | 9a06d96f | Olga Brani | request, response, model, getattr(obj, obj._meta.pk.name))
|
1076 | 661c4479 | Sofia Papagiannaki | return response
|
1077 | 8e45d6fd | Sofia Papagiannaki | |
1078 | 5ce3ce4f | Sofia Papagiannaki | |
1079 | 8c804c12 | Sofia Papagiannaki | @require_http_methods(["GET", "POST"]) |
1080 | 01ac12d5 | Sofia Papagiannaki | @signed_terms_required
|
1081 | 01ac12d5 | Sofia Papagiannaki | @login_required
|
1082 | 95a51cdc | Sofia Papagiannaki | def group_search(request, extra_context=None, **kwargs): |
1083 | d220292f | Sofia Papagiannaki | q = request.GET.get('q')
|
1084 | 01ac12d5 | Sofia Papagiannaki | if request.method == 'GET': |
1085 | d220292f | Sofia Papagiannaki | form = AstakosGroupSearchForm({'q': q} if q else None) |
1086 | 01ac12d5 | Sofia Papagiannaki | else:
|
1087 | 01ac12d5 | Sofia Papagiannaki | form = AstakosGroupSearchForm(get_query(request)) |
1088 | 01ac12d5 | Sofia Papagiannaki | if form.is_valid():
|
1089 | 01ac12d5 | Sofia Papagiannaki | q = form.cleaned_data['q'].strip()
|
1090 | 098f333b | Sofia Papagiannaki | |
1091 | 098f333b | Sofia Papagiannaki | sorting = 'groupname'
|
1092 | d220292f | Sofia Papagiannaki | if q:
|
1093 | 789bcaf9 | Sofia Papagiannaki | queryset = AstakosGroup.objects.select_related() |
1094 | 29b0ec5a | Sofia Papagiannaki | queryset = queryset.filter(~Q(kind__name='default'))
|
1095 | 789bcaf9 | Sofia Papagiannaki | queryset = queryset.filter(name__contains=q) |
1096 | 789bcaf9 | Sofia Papagiannaki | queryset = queryset.filter(approval_date__isnull=False)
|
1097 | 789bcaf9 | Sofia Papagiannaki | queryset = queryset.extra(select={ |
1098 | 098f333b | Sofia Papagiannaki | 'groupname': "auth_group.name", |
1099 | 9a06d96f | Olga Brani | 'kindname': "im_groupkind.name", |
1100 | 9a06d96f | Olga Brani | 'approved_members_num': """ |
1101 | 789bcaf9 | Sofia Papagiannaki | SELECT COUNT(*) FROM im_membership
|
1102 | 789bcaf9 | Sofia Papagiannaki | WHERE group_id = im_astakosgroup.group_ptr_id
|
1103 | 789bcaf9 | Sofia Papagiannaki | AND date_joined IS NOT NULL""",
|
1104 | 9a06d96f | Olga Brani | 'membership_approval_date': """ |
1105 | 789bcaf9 | Sofia Papagiannaki | SELECT date_joined FROM im_membership
|
1106 | 789bcaf9 | Sofia Papagiannaki | WHERE group_id = im_astakosgroup.group_ptr_id
|
1107 | 789bcaf9 | Sofia Papagiannaki | AND person_id = %s""" % request.user.id,
|
1108 | 9a06d96f | Olga Brani | 'is_member': """ |
1109 | 789bcaf9 | Sofia Papagiannaki | SELECT CASE WHEN EXISTS(
|
1110 | 789bcaf9 | Sofia Papagiannaki | SELECT date_joined FROM im_membership
|
1111 | 789bcaf9 | Sofia Papagiannaki | WHERE group_id = im_astakosgroup.group_ptr_id
|
1112 | 789bcaf9 | Sofia Papagiannaki | AND person_id = %s)
|
1113 | 701118f4 | Sofia Papagiannaki | THEN 1 ELSE 0 END""" % request.user.id,
|
1114 | 9a06d96f | Olga Brani | 'is_owner': """ |
1115 | 701118f4 | Sofia Papagiannaki | SELECT CASE WHEN EXISTS(
|
1116 | 701118f4 | Sofia Papagiannaki | SELECT id FROM im_astakosuser_owner
|
1117 | 701118f4 | Sofia Papagiannaki | WHERE astakosgroup_id = im_astakosgroup.group_ptr_id
|
1118 | 701118f4 | Sofia Papagiannaki | AND astakosuser_id = %s)
|
1119 | bdc1c103 | Olga Brani | THEN 1 ELSE 0 END""" % request.user.id,
|
1120 | bdc1c103 | Olga Brani | 'is_owner': """SELECT CASE WHEN EXISTS( |
1121 | bdc1c103 | Olga Brani | SELECT id FROM im_astakosuser_owner
|
1122 | bdc1c103 | Olga Brani | WHERE astakosgroup_id = im_astakosgroup.group_ptr_id
|
1123 | bdc1c103 | Olga Brani | AND astakosuser_id = %s)
|
1124 | 792c2f3b | Olga Brani | THEN 1 ELSE 0 END""" % request.user.id,
|
1125 | bdc1c103 | Olga Brani | }) |
1126 | 098f333b | Sofia Papagiannaki | |
1127 | 098f333b | Sofia Papagiannaki | # validate sorting
|
1128 | 098f333b | Sofia Papagiannaki | sort_form = AstakosGroupSortForm(request.GET) |
1129 | 098f333b | Sofia Papagiannaki | if sort_form.is_valid():
|
1130 | 098f333b | Sofia Papagiannaki | sorting = sort_form.cleaned_data.get('sorting')
|
1131 | 098f333b | Sofia Papagiannaki | queryset = queryset.order_by(sorting) |
1132 | 3cbd5e47 | Olga Brani | |
1133 | d220292f | Sofia Papagiannaki | else:
|
1134 | d220292f | Sofia Papagiannaki | queryset = AstakosGroup.objects.none() |
1135 | d220292f | Sofia Papagiannaki | return object_list(
|
1136 | d220292f | Sofia Papagiannaki | request, |
1137 | d220292f | Sofia Papagiannaki | queryset, |
1138 | 59728d4e | Olga Brani | paginate_by=PAGINATE_BY_ALL, |
1139 | d220292f | Sofia Papagiannaki | page=request.GET.get('page') or 1, |
1140 | d220292f | Sofia Papagiannaki | template_name='im/astakosgroup_list.html',
|
1141 | d220292f | Sofia Papagiannaki | extra_context=dict(form=form,
|
1142 | d220292f | Sofia Papagiannaki | is_search=True,
|
1143 | 04febd09 | Olga Brani | q=q, |
1144 | 04febd09 | Olga Brani | sorting=sorting)) |
1145 | 5ce3ce4f | Sofia Papagiannaki | |
1146 | 9a06d96f | Olga Brani | |
1147 | ae497612 | Olga Brani | @require_http_methods(["GET", "POST"]) |
1148 | df67421c | Sofia Papagiannaki | @signed_terms_required
|
1149 | df67421c | Sofia Papagiannaki | @login_required
|
1150 | df67421c | Sofia Papagiannaki | def group_all(request, extra_context=None, **kwargs): |
1151 | 789bcaf9 | Sofia Papagiannaki | q = AstakosGroup.objects.select_related() |
1152 | 29b0ec5a | Sofia Papagiannaki | q = q.filter(~Q(kind__name='default'))
|
1153 | 789bcaf9 | Sofia Papagiannaki | q = q.filter(approval_date__isnull=False)
|
1154 | 789bcaf9 | Sofia Papagiannaki | q = q.extra(select={ |
1155 | 098f333b | Sofia Papagiannaki | 'groupname': "auth_group.name", |
1156 | 789bcaf9 | Sofia Papagiannaki | 'kindname': "im_groupkind.name", |
1157 | 789bcaf9 | Sofia Papagiannaki | 'approved_members_num': """ |
1158 | 789bcaf9 | Sofia Papagiannaki | SELECT COUNT(*) FROM im_membership
|
1159 | 789bcaf9 | Sofia Papagiannaki | WHERE group_id = im_astakosgroup.group_ptr_id
|
1160 | 789bcaf9 | Sofia Papagiannaki | AND date_joined IS NOT NULL""",
|
1161 | 789bcaf9 | Sofia Papagiannaki | 'membership_approval_date': """ |
1162 | 789bcaf9 | Sofia Papagiannaki | SELECT date_joined FROM im_membership
|
1163 | 789bcaf9 | Sofia Papagiannaki | WHERE group_id = im_astakosgroup.group_ptr_id
|
1164 | 789bcaf9 | Sofia Papagiannaki | AND person_id = %s""" % request.user.id,
|
1165 | 789bcaf9 | Sofia Papagiannaki | 'is_member': """ |
1166 | 789bcaf9 | Sofia Papagiannaki | SELECT CASE WHEN EXISTS(
|
1167 | 789bcaf9 | Sofia Papagiannaki | SELECT date_joined FROM im_membership
|
1168 | 789bcaf9 | Sofia Papagiannaki | WHERE group_id = im_astakosgroup.group_ptr_id
|
1169 | 789bcaf9 | Sofia Papagiannaki | AND person_id = %s)
|
1170 | bdc1c103 | Olga Brani | THEN 1 ELSE 0 END""" % request.user.id,
|
1171 | bdc1c103 | Olga Brani | 'is_owner': """SELECT CASE WHEN EXISTS( |
1172 | bdc1c103 | Olga Brani | SELECT id FROM im_astakosuser_owner
|
1173 | bdc1c103 | Olga Brani | WHERE astakosgroup_id = im_astakosgroup.group_ptr_id
|
1174 | bdc1c103 | Olga Brani | AND astakosuser_id = %s)
|
1175 | bdc1c103 | Olga Brani | THEN 1 ELSE 0 END""" % request.user.id, })
|
1176 | 098f333b | Sofia Papagiannaki | |
1177 | 098f333b | Sofia Papagiannaki | # validate sorting
|
1178 | 098f333b | Sofia Papagiannaki | sorting = 'groupname'
|
1179 | 098f333b | Sofia Papagiannaki | sort_form = AstakosGroupSortForm(request.GET) |
1180 | 098f333b | Sofia Papagiannaki | if sort_form.is_valid():
|
1181 | 098f333b | Sofia Papagiannaki | sorting = sort_form.cleaned_data.get('sorting')
|
1182 | 098f333b | Sofia Papagiannaki | q = q.order_by(sorting) |
1183 | 098f333b | Sofia Papagiannaki | |
1184 | df67421c | Sofia Papagiannaki | return object_list(
|
1185 | 9a06d96f | Olga Brani | request, |
1186 | 9a06d96f | Olga Brani | q, |
1187 | 59728d4e | Olga Brani | paginate_by=PAGINATE_BY_ALL, |
1188 | 9a06d96f | Olga Brani | page=request.GET.get('page') or 1, |
1189 | 9a06d96f | Olga Brani | template_name='im/astakosgroup_list.html',
|
1190 | 9a06d96f | Olga Brani | extra_context=dict(form=AstakosGroupSearchForm(),
|
1191 | 9a06d96f | Olga Brani | is_search=True,
|
1192 | 9a06d96f | Olga Brani | sorting=sorting)) |
1193 | df67421c | Sofia Papagiannaki | |
1194 | 01ac12d5 | Sofia Papagiannaki | |
1195 | ae497612 | Olga Brani | #@require_http_methods(["POST"])
|
1196 | ae497612 | Olga Brani | @require_http_methods(["POST", "GET"]) |
1197 | 01ac12d5 | Sofia Papagiannaki | @signed_terms_required
|
1198 | 01ac12d5 | Sofia Papagiannaki | @login_required
|
1199 | 01ac12d5 | Sofia Papagiannaki | def group_join(request, group_id): |
1200 | 95a51cdc | Sofia Papagiannaki | m = Membership(group_id=group_id, |
1201 | 5ce3ce4f | Sofia Papagiannaki | person=request.user, |
1202 | 789bcaf9 | Sofia Papagiannaki | date_requested=datetime.now()) |
1203 | 95a51cdc | Sofia Papagiannaki | try:
|
1204 | 95a51cdc | Sofia Papagiannaki | m.save() |
1205 | 0f4fa26d | Sofia Papagiannaki | post_save_redirect = reverse( |
1206 | 0f4fa26d | Sofia Papagiannaki | 'group_detail',
|
1207 | 789bcaf9 | Sofia Papagiannaki | kwargs=dict(group_id=group_id))
|
1208 | 95a51cdc | Sofia Papagiannaki | return HttpResponseRedirect(post_save_redirect)
|
1209 | 95a51cdc | Sofia Papagiannaki | except IntegrityError, e:
|
1210 | 95a51cdc | Sofia Papagiannaki | logger.exception(e) |
1211 | ae497612 | Olga Brani | msg = _(astakos_messages.GROUP_JOIN_FAILURE) |
1212 | 95a51cdc | Sofia Papagiannaki | messages.error(request, msg) |
1213 | 95a51cdc | Sofia Papagiannaki | return group_search(request)
|
1214 | 01ac12d5 | Sofia Papagiannaki | |
1215 | 5ce3ce4f | Sofia Papagiannaki | |
1216 | 8c804c12 | Sofia Papagiannaki | @require_http_methods(["POST"]) |
1217 | 01ac12d5 | Sofia Papagiannaki | @signed_terms_required
|
1218 | 01ac12d5 | Sofia Papagiannaki | @login_required
|
1219 | 01ac12d5 | Sofia Papagiannaki | def group_leave(request, group_id): |
1220 | 01ac12d5 | Sofia Papagiannaki | try:
|
1221 | 0f4fa26d | Sofia Papagiannaki | m = Membership.objects.select_related().get( |
1222 | 0f4fa26d | Sofia Papagiannaki | group__id=group_id, |
1223 | 032ade79 | Sofia Papagiannaki | person=request.user) |
1224 | 01ac12d5 | Sofia Papagiannaki | except Membership.DoesNotExist:
|
1225 | c0b26605 | Sofia Papagiannaki | return HttpResponseBadRequest(_(astakos_messages.NOT_MEMBER))
|
1226 | 01ac12d5 | Sofia Papagiannaki | if request.user in m.group.owner.all(): |
1227 | ae497612 | Olga Brani | return HttpResponseForbidden(_(astakos_messages.OWNER_CANNOT_LEAVE_GROUP))
|
1228 | 0f4fa26d | Sofia Papagiannaki | return delete_object(
|
1229 | 0f4fa26d | Sofia Papagiannaki | request, |
1230 | 0f4fa26d | Sofia Papagiannaki | model=Membership, |
1231 | 5ce3ce4f | Sofia Papagiannaki | object_id=m.id, |
1232 | 0f4fa26d | Sofia Papagiannaki | template_name='im/astakosgroup_list.html',
|
1233 | 5ce3ce4f | Sofia Papagiannaki | post_delete_redirect=reverse( |
1234 | 0f4fa26d | Sofia Papagiannaki | 'group_detail',
|
1235 | 032ade79 | Sofia Papagiannaki | kwargs=dict(group_id=group_id)))
|
1236 | 01ac12d5 | Sofia Papagiannaki | |
1237 | 5ce3ce4f | Sofia Papagiannaki | |
1238 | 1eaeb5b6 | Sofia Papagiannaki | def handle_membership(func): |
1239 | 1eaeb5b6 | Sofia Papagiannaki | @wraps(func)
|
1240 | 1eaeb5b6 | Sofia Papagiannaki | def wrapper(request, group_id, user_id): |
1241 | 1eaeb5b6 | Sofia Papagiannaki | try:
|
1242 | 1eaeb5b6 | Sofia Papagiannaki | m = Membership.objects.select_related().get( |
1243 | 1eaeb5b6 | Sofia Papagiannaki | group__id=group_id, |
1244 | 032ade79 | Sofia Papagiannaki | person__id=user_id) |
1245 | 1eaeb5b6 | Sofia Papagiannaki | except Membership.DoesNotExist:
|
1246 | ae497612 | Olga Brani | return HttpResponseBadRequest(_(astakos_messages.NOT_MEMBER))
|
1247 | 1eaeb5b6 | Sofia Papagiannaki | else:
|
1248 | 1eaeb5b6 | Sofia Papagiannaki | if request.user not in m.group.owner.all(): |
1249 | ae497612 | Olga Brani | return HttpResponseForbidden(_(astakos_messages.NOT_OWNER))
|
1250 | 1eaeb5b6 | Sofia Papagiannaki | func(request, m) |
1251 | 56b1281c | Sofia Papagiannaki | return group_detail(request, group_id)
|
1252 | 1eaeb5b6 | Sofia Papagiannaki | return wrapper
|
1253 | 01ac12d5 | Sofia Papagiannaki | |
1254 | 5ce3ce4f | Sofia Papagiannaki | |
1255 | ae497612 | Olga Brani | #@require_http_methods(["POST"])
|
1256 | ae497612 | Olga Brani | @require_http_methods(["POST", "GET"]) |
1257 | 01ac12d5 | Sofia Papagiannaki | @signed_terms_required
|
1258 | 01ac12d5 | Sofia Papagiannaki | @login_required
|
1259 | 1eaeb5b6 | Sofia Papagiannaki | @handle_membership
|
1260 | 01ac12d5 | Sofia Papagiannaki | def approve_member(request, membership): |
1261 | 01ac12d5 | Sofia Papagiannaki | try:
|
1262 | 01ac12d5 | Sofia Papagiannaki | membership.approve() |
1263 | 01ac12d5 | Sofia Papagiannaki | realname = membership.person.realname |
1264 | ae497612 | Olga Brani | msg = _(astakos_messages.MEMBER_JOINED_GROUP) % locals()
|
1265 | 01ac12d5 | Sofia Papagiannaki | messages.success(request, msg) |
1266 | ae497612 | Olga Brani | except AssertionError: |
1267 | ae497612 | Olga Brani | msg = _(astakos_messages.GROUP_MAX_PARTICIPANT_NUMBER_REACHED) |
1268 | ae497612 | Olga Brani | messages.error(request, msg) |
1269 | 01ac12d5 | Sofia Papagiannaki | except BaseException, e: |
1270 | 01ac12d5 | Sofia Papagiannaki | logger.exception(e) |
1271 | 56b1281c | Sofia Papagiannaki | realname = membership.person.realname |
1272 | ae497612 | Olga Brani | msg = _(astakos_messages.GENERIC_ERROR) |
1273 | 01ac12d5 | Sofia Papagiannaki | messages.error(request, msg) |
1274 | 5ce3ce4f | Sofia Papagiannaki | |
1275 | 5ce3ce4f | Sofia Papagiannaki | |
1276 | 01ac12d5 | Sofia Papagiannaki | @signed_terms_required
|
1277 | 01ac12d5 | Sofia Papagiannaki | @login_required
|
1278 | 1eaeb5b6 | Sofia Papagiannaki | @handle_membership
|
1279 | 01ac12d5 | Sofia Papagiannaki | def disapprove_member(request, membership): |
1280 | 01ac12d5 | Sofia Papagiannaki | try:
|
1281 | 01ac12d5 | Sofia Papagiannaki | membership.disapprove() |
1282 | 01ac12d5 | Sofia Papagiannaki | realname = membership.person.realname |
1283 | 666e1351 | Sofia Papagiannaki | msg = astakos_messages.MEMBER_REMOVED % locals()
|
1284 | 01ac12d5 | Sofia Papagiannaki | messages.success(request, msg) |
1285 | 01ac12d5 | Sofia Papagiannaki | except BaseException, e: |
1286 | 01ac12d5 | Sofia Papagiannaki | logger.exception(e) |
1287 | ae497612 | Olga Brani | msg = _(astakos_messages.GENERIC_ERROR) |
1288 | 01ac12d5 | Sofia Papagiannaki | messages.error(request, msg) |
1289 | ffb1e7a8 | Sofia Papagiannaki | |
1290 | 5ce3ce4f | Sofia Papagiannaki | |
1291 | ae497612 | Olga Brani | #@require_http_methods(["GET"])
|
1292 | ae497612 | Olga Brani | @require_http_methods(["POST", "GET"]) |
1293 | ffb1e7a8 | Sofia Papagiannaki | @signed_terms_required
|
1294 | ffb1e7a8 | Sofia Papagiannaki | @login_required
|
1295 | 666c7490 | Sofia Papagiannaki | def resource_usage(request): |
1296 | 52343ac8 | Olga Brani | def with_class(entry): |
1297 | 52343ac8 | Olga Brani | entry['load_class'] = 'red' |
1298 | 52343ac8 | Olga Brani | max_value = float(entry['maxValue']) |
1299 | 52343ac8 | Olga Brani | curr_value = float(entry['currValue']) |
1300 | 394c9834 | Olga Brani | entry['ratio_limited']= 0 |
1301 | 639e0352 | Olga Brani | if max_value > 0 : |
1302 | c0b26605 | Sofia Papagiannaki | entry['ratio'] = (curr_value / max_value) * 100 |
1303 | c0b26605 | Sofia Papagiannaki | else:
|
1304 | 792c2f3b | Olga Brani | entry['ratio'] = 0 |
1305 | 52343ac8 | Olga Brani | if entry['ratio'] < 66: |
1306 | 9a06d96f | Olga Brani | entry['load_class'] = 'yellow' |
1307 | 52343ac8 | Olga Brani | if entry['ratio'] < 33: |
1308 | 9a06d96f | Olga Brani | entry['load_class'] = 'green' |
1309 | 394c9834 | Olga Brani | if entry['ratio']<0: |
1310 | 394c9834 | Olga Brani | entry['ratio'] = 0 |
1311 | 394c9834 | Olga Brani | if entry['ratio']>100: |
1312 | 394c9834 | Olga Brani | entry['ratio_limited'] = 100 |
1313 | 394c9834 | Olga Brani | else:
|
1314 | 394c9834 | Olga Brani | entry['ratio_limited'] = entry['ratio'] |
1315 | 394c9834 | Olga Brani | |
1316 | 9a06d96f | Olga Brani | return entry
|
1317 | 9a06d96f | Olga Brani | |
1318 | 52343ac8 | Olga Brani | def pluralize(entry): |
1319 | 9a06d96f | Olga Brani | entry['plural'] = engine.plural(entry.get('name')) |
1320 | 9a06d96f | Olga Brani | return entry
|
1321 | 52343ac8 | Olga Brani | |
1322 | 666c7490 | Sofia Papagiannaki | result = callpoint.get_user_usage(request.user.id) |
1323 | 820b18e0 | Sofia Papagiannaki | if result.is_success:
|
1324 | 820b18e0 | Sofia Papagiannaki | backenddata = map(with_class, result.data)
|
1325 | 820b18e0 | Sofia Papagiannaki | data = map(pluralize, result.data)
|
1326 | 9a06d96f | Olga Brani | else:
|
1327 | 820b18e0 | Sofia Papagiannaki | data = None
|
1328 | 820b18e0 | Sofia Papagiannaki | messages.error(request, result.reason) |
1329 | 3cbd5e47 | Olga Brani | resource_catalog = ResourcePresentation(RESOURCES_PRESENTATION_DATA) |
1330 | 3cbd5e47 | Olga Brani | resource_catalog.update_from_result_report(result) |
1331 | 666c7490 | Sofia Papagiannaki | return render_response('im/resource_usage.html', |
1332 | 9a06d96f | Olga Brani | data=data, |
1333 | 3cbd5e47 | Olga Brani | context_instance=get_context(request), |
1334 | c0b26605 | Sofia Papagiannaki | resource_catalog=resource_catalog, |
1335 | 3cbd5e47 | Olga Brani | result=result) |
1336 | 9a06d96f | Olga Brani | |
1337 | 1b866d9e | Olga Brani | |
1338 | 4b7d68f0 | Olga Brani | def group_create_list(request): |
1339 | 9eafaa32 | Sofia Papagiannaki | form = PickResourceForm() |
1340 | 4b7d68f0 | Olga Brani | return render_response(
|
1341 | 4b7d68f0 | Olga Brani | template='im/astakosgroup_create_list.html',
|
1342 | 032ade79 | Sofia Papagiannaki | context_instance=get_context(request),) |
1343 | 6e029beb | Sofia Papagiannaki | |
1344 | 5ce3ce4f | Sofia Papagiannaki | |
1345 | f8f86e83 | root | ##@require_http_methods(["GET"])
|
1346 | f8f86e83 | root | #@require_http_methods(["POST", "GET"])
|
1347 | f8f86e83 | root | #@signed_terms_required
|
1348 | f8f86e83 | root | #@login_required
|
1349 | f8f86e83 | root | #def billing(request):
|
1350 | f8f86e83 | root | #
|
1351 | f8f86e83 | root | # today = datetime.today()
|
1352 | f8f86e83 | root | # month_last_day = calendar.monthrange(today.year, today.month)[1]
|
1353 | f8f86e83 | root | # start = request.POST.get('datefrom', None)
|
1354 | f8f86e83 | root | # if start:
|
1355 | f8f86e83 | root | # today = datetime.fromtimestamp(int(start))
|
1356 | f8f86e83 | root | # month_last_day = calendar.monthrange(today.year, today.month)[1]
|
1357 | f8f86e83 | root | #
|
1358 | f8f86e83 | root | # start = datetime(today.year, today.month, 1).strftime("%s")
|
1359 | f8f86e83 | root | # end = datetime(today.year, today.month, month_last_day).strftime("%s")
|
1360 | f8f86e83 | root | # r = request_billing.apply(args=('pgerakios@grnet.gr',
|
1361 | f8f86e83 | root | # int(start) * 1000,
|
1362 | f8f86e83 | root | # int(end) * 1000))
|
1363 | f8f86e83 | root | # data = {}
|
1364 | f8f86e83 | root | #
|
1365 | f8f86e83 | root | # try:
|
1366 | f8f86e83 | root | # status, data = r.result
|
1367 | f8f86e83 | root | # data = _clear_billing_data(data)
|
1368 | f8f86e83 | root | # if status != 200:
|
1369 | f8f86e83 | root | # messages.error(request, _(astakos_messages.BILLING_ERROR) % status)
|
1370 | f8f86e83 | root | # except:
|
1371 | f8f86e83 | root | # messages.error(request, r.result)
|
1372 | f8f86e83 | root | #
|
1373 | f8f86e83 | root | # return render_response(
|
1374 | f8f86e83 | root | # template='im/billing.html',
|
1375 | f8f86e83 | root | # context_instance=get_context(request),
|
1376 | f8f86e83 | root | # data=data,
|
1377 | f8f86e83 | root | # zerodate=datetime(month=1, year=1970, day=1),
|
1378 | f8f86e83 | root | # today=today,
|
1379 | f8f86e83 | root | # start=int(start),
|
1380 | f8f86e83 | root | # month_last_day=month_last_day)
|
1381 | 9a06d96f | Olga Brani | |
1382 | 54213d7a | Sofia Papagiannaki | |
1383 | f8f86e83 | root | #def _clear_billing_data(data):
|
1384 | f8f86e83 | root | #
|
1385 | f8f86e83 | root | # # remove addcredits entries
|
1386 | f8f86e83 | root | # def isnotcredit(e):
|
1387 | f8f86e83 | root | # return e['serviceName'] != "addcredits"
|
1388 | f8f86e83 | root | #
|
1389 | f8f86e83 | root | # # separate services
|
1390 | f8f86e83 | root | # def servicefilter(service_name):
|
1391 | f8f86e83 | root | # service = service_name
|
1392 | f8f86e83 | root | #
|
1393 | f8f86e83 | root | # def fltr(e):
|
1394 | f8f86e83 | root | # return e['serviceName'] == service
|
1395 | f8f86e83 | root | # return fltr
|
1396 | f8f86e83 | root | #
|
1397 | f8f86e83 | root | # data['bill_nocredits'] = filter(isnotcredit, data['bill'])
|
1398 | f8f86e83 | root | # data['bill_vmtime'] = filter(servicefilter('vmtime'), data['bill'])
|
1399 | f8f86e83 | root | # data['bill_diskspace'] = filter(servicefilter('diskspace'), data['bill'])
|
1400 | f8f86e83 | root | # data['bill_addcredits'] = filter(servicefilter('addcredits'), data['bill'])
|
1401 | f8f86e83 | root | #
|
1402 | f8f86e83 | root | # return data
|
1403 | 792c2f3b | Olga Brani | |
1404 | 792c2f3b | Olga Brani | |
1405 | e1a80257 | Sofia Papagiannaki | # #@require_http_methods(["GET"])
|
1406 | e1a80257 | Sofia Papagiannaki | # @require_http_methods(["POST", "GET"])
|
1407 | e1a80257 | Sofia Papagiannaki | # @signed_terms_required
|
1408 | e1a80257 | Sofia Papagiannaki | # @login_required
|
1409 | e1a80257 | Sofia Papagiannaki | # def timeline(request):
|
1410 | e1a80257 | Sofia Papagiannaki | # # data = {'entity':request.user.email}
|
1411 | e1a80257 | Sofia Papagiannaki | # timeline_body = ()
|
1412 | e1a80257 | Sofia Papagiannaki | # timeline_header = ()
|
1413 | e1a80257 | Sofia Papagiannaki | # # form = TimelineForm(data)
|
1414 | e1a80257 | Sofia Papagiannaki | # form = TimelineForm()
|
1415 | e1a80257 | Sofia Papagiannaki | # if request.method == 'POST':
|
1416 | e1a80257 | Sofia Papagiannaki | # data = request.POST
|
1417 | e1a80257 | Sofia Papagiannaki | # form = TimelineForm(data)
|
1418 | e1a80257 | Sofia Papagiannaki | # if form.is_valid():
|
1419 | e1a80257 | Sofia Papagiannaki | # data = form.cleaned_data
|
1420 | e1a80257 | Sofia Papagiannaki | # timeline_header = ('entity', 'resource',
|
1421 | e1a80257 | Sofia Papagiannaki | # 'event name', 'event date',
|
1422 | e1a80257 | Sofia Papagiannaki | # 'incremental cost', 'total cost')
|
1423 | e1a80257 | Sofia Papagiannaki | # timeline_body = timeline_charge(
|
1424 | e1a80257 | Sofia Papagiannaki | # data['entity'], data['resource'],
|
1425 | e1a80257 | Sofia Papagiannaki | # data['start_date'], data['end_date'],
|
1426 | e1a80257 | Sofia Papagiannaki | # data['details'], data['operation'])
|
1427 | e1a80257 | Sofia Papagiannaki | #
|
1428 | e1a80257 | Sofia Papagiannaki | # return render_response(template='im/timeline.html',
|
1429 | e1a80257 | Sofia Papagiannaki | # context_instance=get_context(request),
|
1430 | e1a80257 | Sofia Papagiannaki | # form=form,
|
1431 | e1a80257 | Sofia Papagiannaki | # timeline_header=timeline_header,
|
1432 | e1a80257 | Sofia Papagiannaki | # timeline_body=timeline_body)
|
1433 | e1a80257 | Sofia Papagiannaki | # return data
|
1434 | 5ebebb20 | Olga Brani | |
1435 | 792c2f3b | Olga Brani | |
1436 | f432088a | Kostas Papadimitriou | # TODO: action only on POST and user should confirm the removal
|
1437 | d2633501 | Kostas Papadimitriou | @require_http_methods(["GET", "POST"]) |
1438 | d2633501 | Kostas Papadimitriou | @login_required
|
1439 | d2633501 | Kostas Papadimitriou | @signed_terms_required
|
1440 | d2633501 | Kostas Papadimitriou | def remove_auth_provider(request, pk): |
1441 | f432088a | Kostas Papadimitriou | try:
|
1442 | f432088a | Kostas Papadimitriou | provider = request.user.auth_providers.get(pk=pk) |
1443 | f432088a | Kostas Papadimitriou | except AstakosUserAuthProvider.DoesNotExist:
|
1444 | f432088a | Kostas Papadimitriou | raise Http404
|
1445 | f432088a | Kostas Papadimitriou | |
1446 | d2633501 | Kostas Papadimitriou | if provider.can_remove():
|
1447 | d2633501 | Kostas Papadimitriou | provider.delete() |
1448 | d2633501 | Kostas Papadimitriou | return HttpResponseRedirect(reverse('edit_profile')) |
1449 | d2633501 | Kostas Papadimitriou | else:
|
1450 | f432088a | Kostas Papadimitriou | raise PermissionDenied
|
1451 | 5ebebb20 | Olga Brani | |
1452 | 792c2f3b | Olga Brani | |
1453 | 5ebebb20 | Olga Brani | def how_it_works(request): |
1454 | 5ebebb20 | Olga Brani | return render_response(
|
1455 | 5ebebb20 | Olga Brani | template='im/how_it_works.html',
|
1456 | 792c2f3b | Olga Brani | context_instance=get_context(request),) |
1457 | e1a80257 | Sofia Papagiannaki | |
1458 | e1a80257 | Sofia Papagiannaki | @require_http_methods(["GET", "POST"]) |
1459 | e1a80257 | Sofia Papagiannaki | @signed_terms_required
|
1460 | e1a80257 | Sofia Papagiannaki | @login_required
|
1461 | e1a80257 | Sofia Papagiannaki | def project_add(request): |
1462 | e1a80257 | Sofia Papagiannaki | result = callpoint.list_resources() |
1463 | e1a80257 | Sofia Papagiannaki | resource_catalog = ResourcePresentation(RESOURCES_PRESENTATION_DATA) |
1464 | e1a80257 | Sofia Papagiannaki | resource_catalog.update_from_result(result) |
1465 | e1a80257 | Sofia Papagiannaki | |
1466 | e1a80257 | Sofia Papagiannaki | if not result.is_success: |
1467 | e1a80257 | Sofia Papagiannaki | messages.error( |
1468 | e1a80257 | Sofia Papagiannaki | request, |
1469 | e1a80257 | Sofia Papagiannaki | 'Unable to retrieve system resources: %s' % result.reason
|
1470 | e1a80257 | Sofia Papagiannaki | ) |
1471 | e1a80257 | Sofia Papagiannaki | extra_context = {'resource_catalog':resource_catalog}
|
1472 | e1a80257 | Sofia Papagiannaki | return create_object(request, template_name='im/projects/projectapplication_form.html', |
1473 | f3342849 | Sofia Papagiannaki | extra_context=extra_context, post_save_redirect='/im/project/list/',
|
1474 | e1a80257 | Sofia Papagiannaki | form_class=ProjectApplicationForm) |
1475 | e1a80257 | Sofia Papagiannaki | |
1476 | e1a80257 | Sofia Papagiannaki | @require_http_methods(["GET"]) |
1477 | e1a80257 | Sofia Papagiannaki | @signed_terms_required
|
1478 | e1a80257 | Sofia Papagiannaki | @login_required
|
1479 | f3342849 | Sofia Papagiannaki | def project_list(request): |
1480 | 2a965273 | Sofia Papagiannaki | q = ProjectApplication.objects.filter(owner=request.user) |
1481 | 2a965273 | Sofia Papagiannaki | q |= ProjectApplication.objects.filter( |
1482 | 2a965273 | Sofia Papagiannaki | project__in=request.user.projectmembership_set.values_list('project', flat=True) |
1483 | 2a965273 | Sofia Papagiannaki | ) |
1484 | e1a80257 | Sofia Papagiannaki | return object_list(
|
1485 | e1a80257 | Sofia Papagiannaki | request, |
1486 | 2a965273 | Sofia Papagiannaki | q, |
1487 | e1a80257 | Sofia Papagiannaki | paginate_by=PAGINATE_BY_ALL, |
1488 | e1a80257 | Sofia Papagiannaki | page=request.GET.get('page') or 1, |
1489 | 71a38edf | Sofia Papagiannaki | template_name='im/projects/project_list.html',
|
1490 | 71a38edf | Sofia Papagiannaki | extra_context={ |
1491 | 71a38edf | Sofia Papagiannaki | 'is_search':False, |
1492 | 71a38edf | Sofia Papagiannaki | 'sorting':request.GET.get('sorting'), |
1493 | 71a38edf | Sofia Papagiannaki | } |
1494 | 71a38edf | Sofia Papagiannaki | ) |
1495 | e1a80257 | Sofia Papagiannaki | |
1496 | e1a80257 | Sofia Papagiannaki | |
1497 | f3342849 | Sofia Papagiannaki | @require_http_methods(["GET", "POST"]) |
1498 | e1a80257 | Sofia Papagiannaki | @signed_terms_required
|
1499 | e1a80257 | Sofia Papagiannaki | @login_required
|
1500 | f3342849 | Sofia Papagiannaki | def project_application_detail(request, serial): |
1501 | f3342849 | Sofia Papagiannaki | return object_detail(
|
1502 | f3342849 | Sofia Papagiannaki | request, |
1503 | f3342849 | Sofia Papagiannaki | queryset=ProjectApplication.objects.select_related(), |
1504 | f3342849 | Sofia Papagiannaki | slug=serial, |
1505 | f3342849 | Sofia Papagiannaki | slug_field='serial',
|
1506 | f3342849 | Sofia Papagiannaki | template_name='im/projects/projectapplication_detail.html'
|
1507 | f3342849 | Sofia Papagiannaki | ) |
1508 | e1a80257 | Sofia Papagiannaki | |
1509 | e1a80257 | Sofia Papagiannaki | @require_http_methods(["GET", "POST"]) |
1510 | e1a80257 | Sofia Papagiannaki | @signed_terms_required
|
1511 | e1a80257 | Sofia Papagiannaki | @login_required
|
1512 | e1a80257 | Sofia Papagiannaki | def project_detail(request, serial): |
1513 | f3342849 | Sofia Papagiannaki | return object_detail(
|
1514 | f3342849 | Sofia Papagiannaki | request, |
1515 | 71a38edf | Sofia Papagiannaki | queryset=ProjectApplication.objects.select_related(), |
1516 | f3342849 | Sofia Papagiannaki | slug=serial, |
1517 | f3342849 | Sofia Papagiannaki | slug_field='serial',
|
1518 | 71a38edf | Sofia Papagiannaki | template_name='im/projects/project_detail.html',
|
1519 | 71a38edf | Sofia Papagiannaki | extra_context={ |
1520 | 71a38edf | Sofia Papagiannaki | 'sorting':request.GET.get('sorting', request.POST.get('sorting')), |
1521 | 71a38edf | Sofia Papagiannaki | } |
1522 | f3342849 | Sofia Papagiannaki | ) |
1523 | e1a80257 | Sofia Papagiannaki | |
1524 | e1a80257 | Sofia Papagiannaki | @require_http_methods(["GET", "POST"]) |
1525 | e1a80257 | Sofia Papagiannaki | @signed_terms_required
|
1526 | e1a80257 | Sofia Papagiannaki | @login_required
|
1527 | e1a80257 | Sofia Papagiannaki | def project_search(request): |
1528 | e1a80257 | Sofia Papagiannaki | pass
|
1529 | e1a80257 | Sofia Papagiannaki | |
1530 | e1a80257 | Sofia Papagiannaki | @require_http_methods(["GET"]) |
1531 | e1a80257 | Sofia Papagiannaki | @signed_terms_required
|
1532 | e1a80257 | Sofia Papagiannaki | @login_required
|
1533 | e1a80257 | Sofia Papagiannaki | def project_all(request): |
1534 | e1a80257 | Sofia Papagiannaki | pass
|
1535 | e1a80257 | Sofia Papagiannaki | |
1536 | e1a80257 | Sofia Papagiannaki | @require_http_methods(["GET", "POST"]) |
1537 | e1a80257 | Sofia Papagiannaki | @signed_terms_required
|
1538 | e1a80257 | Sofia Papagiannaki | @login_required
|
1539 | e1a80257 | Sofia Papagiannaki | def project_join(request, serial): |
1540 | e1a80257 | Sofia Papagiannaki | pass
|
1541 | e1a80257 | Sofia Papagiannaki | |
1542 | e1a80257 | Sofia Papagiannaki | @require_http_methods(["GET", "POST"]) |
1543 | e1a80257 | Sofia Papagiannaki | @signed_terms_required
|
1544 | e1a80257 | Sofia Papagiannaki | @login_required
|
1545 | e1a80257 | Sofia Papagiannaki | def project_leave(request, serial): |
1546 | e1a80257 | Sofia Papagiannaki | pass
|
1547 | e1a80257 | Sofia Papagiannaki | |
1548 | e1a80257 | Sofia Papagiannaki | @require_http_methods(["POST"]) |
1549 | e1a80257 | Sofia Papagiannaki | @signed_terms_required
|
1550 | e1a80257 | Sofia Papagiannaki | @login_required
|
1551 | e1a80257 | Sofia Papagiannaki | def project_approve_member(request, serial, user_id): |
1552 | e1a80257 | Sofia Papagiannaki | pass
|
1553 | e1a80257 | Sofia Papagiannaki | |
1554 | e1a80257 | Sofia Papagiannaki | @require_http_methods(["POST"]) |
1555 | e1a80257 | Sofia Papagiannaki | @signed_terms_required
|
1556 | e1a80257 | Sofia Papagiannaki | @login_required
|
1557 | e1a80257 | Sofia Papagiannaki | def project_remove_member(request, serial, user_id): |
1558 | e1a80257 | Sofia Papagiannaki | pass
|
1559 | 394c9834 | Olga Brani |