commit 14c5be5a5280412a0810fe3376ccc7e0c5a0127a
Author: Sofia Papagiannaki <papagian@gmail.com>
Date:   Fri Aug 3 11:25:29 2012 +0300

    move get_menu and get_service out of api/admin

diff --git a/snf-astakos-app/astakos/im/api/admin.py b/snf-astakos-app/astakos/im/api/admin.py
index 9cf00f4..07bac52 100644
--- a/snf-astakos-app/astakos/im/api/admin.py
+++ b/snf-astakos-app/astakos/im/api/admin.py
@@ -32,41 +32,24 @@
 # or implied, of GRNET S.A.
 
 import logging
-import urllib
 
 from functools import wraps
-from traceback import format_exc
 from time import time, mktime
-from urllib import quote
 from urlparse import urlparse
 from collections import defaultdict
 
-from django.conf import settings
 from django.http import HttpResponse
 from django.utils import simplejson as json
-from django.core.urlresolvers import reverse
 
 from astakos.im.api.faults import *
+from astakos.im.api import render_fault
 from astakos.im.models import AstakosUser, Service
-from astakos.im.settings import INVITATIONS_ENABLED, COOKIE_NAME, EMAILCHANGE_ENABLED
 from astakos.im.util import epoch
 from astakos.im.api import _get_user_by_email, _get_user_by_username
 
 logger = logging.getLogger(__name__)
 format = ('%a, %d %b %Y %H:%M:%S GMT')
 
-def render_fault(request, fault):
-    if isinstance(fault, InternalServerError) and settings.DEBUG:
-        fault.details = format_exc(fault)
-
-    request.serialization = 'text'
-    data = fault.message + '\n'
-    if fault.details:
-        data += '\n' + fault.details
-    response = HttpResponse(data, status=fault.code)
-    response['Content-Length'] = len(response.content)
-    return response
-
 def api_method(http_method=None, token_required=False, perms=None):
     """Decorator function for views that implement an API method."""
     if not perms:
@@ -171,67 +154,6 @@ def authenticate(request, user=None):
     response['Content-Length'] = len(response.content)
     return response
 
-@api_method(http_method='GET')
-def get_services(request):
-    callback = request.GET.get('callback', None)
-    services = Service.objects.all()
-    data = tuple({'id':s.pk, 'name':s.name, 'url':s.url, 'icon':s.icon} for s in services)
-    data = json.dumps(data)
-    mimetype = 'application/json'
-
-    if callback:
-        mimetype = 'application/javascript'
-        data = '%s(%s)' % (callback, data)
-
-    return HttpResponse(content=data, mimetype=mimetype)
-
-@api_method()
-def get_menu(request, with_extra_links=False, with_signout=True):
-    index_url = reverse('index')
-    absolute = lambda (url): request.build_absolute_uri(url)
-    l = [{ 'url': absolute(index_url), 'name': "Sign in"}]
-    cookie = urllib.unquote(request.COOKIES.get(COOKIE_NAME, ''))
-    email = cookie.partition('|')[0]
-    try:
-        if not email:
-            raise ValueError
-        user = AstakosUser.objects.get(email=email, is_active=True)
-    except AstakosUser.DoesNotExist:
-        pass
-    except ValueError:
-        pass
-    else:
-        l = []
-        l.append({ 'url': absolute(reverse('astakos.im.views.index')),
-                  'name': user.email})
-        l.append({ 'url': absolute(reverse('astakos.im.views.edit_profile')),
-                  'name': "My account" })
-        if with_extra_links:
-            if user.has_usable_password() and user.provider == 'local':
-                l.append({ 'url': absolute(reverse('password_change')),
-                          'name': "Change password" })
-            if EMAILCHANGE_ENABLED:
-                l.append({'url':absolute(reverse('email_change')),
-                          'name': "Change email"})
-            if INVITATIONS_ENABLED:
-                l.append({ 'url': absolute(reverse('astakos.im.views.invite')),
-                          'name': "Invitations" })
-            l.append({ 'url': absolute(reverse('astakos.im.views.feedback')),
-                      'name': "Feedback" })
-        if with_signout:
-            l.append({ 'url': absolute(reverse('astakos.im.views.logout')),
-                      'name': "Sign out"})
-
-    callback = request.GET.get('callback', None)
-    data = json.dumps(tuple(l))
-    mimetype = 'application/json'
-
-    if callback:
-        mimetype = 'application/javascript'
-        data = '%s(%s)' % (callback, data)
-
-    return HttpResponse(content=data, mimetype=mimetype)
-
 @api_method(http_method='GET', token_required=True, perms=['im.can_access_userinfo'])
 def get_user_by_email(request, user=None):
     # Normal Response Codes: 200
