Revision 1ae97c83 snf-astakos-app/astakos/im/api.py
b/snf-astakos-app/astakos/im/api.py | ||
---|---|---|
33 | 33 |
|
34 | 34 |
from traceback import format_exc |
35 | 35 |
from time import time, mktime |
36 |
from urllib import quote |
|
37 |
from urlparse import urlparse |
|
38 |
|
|
36 | 39 |
from django.conf import settings |
37 | 40 |
from django.http import HttpResponse |
38 | 41 |
from django.utils import simplejson as json |
42 |
from django.core.urlresolvers import reverse |
|
39 | 43 |
|
40 | 44 |
from astakos.im.faults import BadRequest, Unauthorized, InternalServerError |
41 | 45 |
from astakos.im.models import AstakosUser |
46 |
from astakos.im.settings import CLOUD_SERVICES, INVITATIONS_ENABLED |
|
42 | 47 |
|
43 | 48 |
def render_fault(request, fault): |
44 | 49 |
if isinstance(fault, InternalServerError) and settings.DEBUG: |
... | ... | |
91 | 96 |
except BaseException, e: |
92 | 97 |
fault = InternalServerError('Unexpected error') |
93 | 98 |
return render_fault(request, fault) |
99 |
|
|
100 |
def get_services(request): |
|
101 |
if request.method != 'GET': |
|
102 |
raise BadRequest('Method not allowed.') |
|
103 |
data = json.dumps(CLOUD_SERVICES) |
|
104 |
return HttpResponse(content=data, mimetype="application/json") |
|
105 |
|
|
106 |
def get_menu(request): |
|
107 |
if request.method != 'GET': |
|
108 |
raise BadRequest('Method not allowed.') |
|
109 |
location = request.GET.get('location', '') |
|
110 |
index_url = reverse('astakos.im.views.index') |
|
111 |
if urlparse(location).query.rfind('next=') == -1: |
|
112 |
index_url = '%s?next=%s' % (index_url, quote(location)) |
|
113 |
l = [{ 'url': index_url, 'name': "login..."}] |
|
114 |
if request.user.is_authenticated(): |
|
115 |
l = [] |
|
116 |
l.append({ 'url': reverse('astakos.im.views.edit_profile'), 'name': request.user.email}) |
|
117 |
l.append({ 'url': reverse('astakos.im.views.edit_profile'), 'name': "view your profile..." }) |
|
118 |
if request.user.password: |
|
119 |
l.append({ 'url': reverse('password_change'), 'name': "change your password..." }) |
|
120 |
if INVITATIONS_ENABLED: |
|
121 |
l.append({ 'url': reverse('astakos.im.views.invite'), 'name': "invite some friends..." }) |
|
122 |
l.append({ 'url': reverse('astakos.im.views.send_feedback'), 'name': "feedback..." }) |
|
123 |
l.append({ 'url': reverse('astakos.im.views.logout'), 'name': "logout..."}) |
|
124 |
data = json.dumps(tuple(l)) |
|
125 |
return HttpResponse(content=data, mimetype="application/json") |
Also available in: Unified diff