return HttpResponse(content=data, mimetype=mimetype)
def get_menu(request):
- if request.method != 'GET':
- raise BadRequest('Method not allowed.')
location = request.GET.get('location', '')
exclude = []
index_url = reverse('index')
l = [{ 'url': absolute(index_url), 'name': "Sign in"}]
if request.user.is_authenticated():
l = []
- l.append({ 'url': absolute(reverse('astakos.im.views.edit_profile')),
+ l.append({ 'url': absolute(reverse('astakos.im.views.index')),
'name': request.user.email})
l.append({ 'url': absolute(reverse('astakos.im.views.edit_profile')),
'name': "View your profile" })
from astakos.im.settings import IM_MODULES, INVITATIONS_ENABLED, IM_STATIC_URL, \
COOKIE_NAME
+from astakos.im.api import get_menu
+
from django.conf import settings
from django.core.urlresolvers import reverse
+from django.utils import simplejson as json
def im_modules(request):
return {'im_modules': IM_MODULES}
'ACTIVE_SERVICE': CB_ACTIVE_SERVICE,
'GET_SERVICES_URL': absolute(reverse('astakos.im.api.get_services')),
'GET_MENU_URL': absolute(reverse('astakos.im.api.get_menu'))}
+
+def menu(request):
+ absolute = lambda (url): request.build_absolute_uri(url)
+ resp = get_menu(request)
+ menu_items = json.loads(resp.content)[1:]
+ for item in menu_items:
+ item['is_active'] = absolute(request.path) == item['url']
+ return {'menu':menu_items}
'astakos.im.context_processors.next',
'astakos.im.context_processors.code',
'astakos.im.context_processors.invitations',
+ 'astakos.im.context_processors.menu',
'synnefo.lib.context_processors.cloudbar'
]
{% extends "im/base_two_cols.html" %}
+{% load filters %}
+
{% block page.title %}Profile{% endblock %}
{% block page.nav.classes %}{% endblock %}
{% endblock %}
{% block page.nav.items %}
- <li class="{% if tab == "im/profile" %}active{% endif %}">
- <a href="{% url astakos.im.views.edit_profile %}">Profile</a>
- </li>
- <li class="{% if not tab %}active{% endif %}">
- <a href="{% url django.contrib.auth.views.password_change %}">Change password</a>
- </li>
- {% if invitations_enabled %}
- <li class="{% if tab == "im/invitations" %}active{% endif %}">
- <a href="{% url astakos.im.views.invite %}">Invitations</a>
- </li>
- {% endif %}
- <li class="{% if tab == "im/feedback" %}active{% endif %}">
- <a href="{% url astakos.im.views.send_feedback %}">Send feedback</a>
- </li>
+ {% for item in menu%}
+ <li class="{% if item|lookup:"is_active" %}active{% endif %}">
+ <a href="{{ item|lookup:"url" }}">{{ item|lookup:"name" }}</a>
+ </li>
+ {% endfor %}
{% endblock %}
{% block page.body %}
--- /dev/null
+# Copyright 2011-2012 GRNET S.A. All rights reserved.
+#
+# Redistribution and use in source and binary forms, with or
+# without modification, are permitted provided that the following
+# conditions are met:
+#
+# 1. Redistributions of source code must retain the above
+# copyright notice, this list of conditions and the following
+# disclaimer.
+#
+# 2. Redistributions in binary form must reproduce the above
+# copyright notice, this list of conditions and the following
+# disclaimer in the documentation and/or other materials
+# provided with the distribution.
+#
+# THIS SOFTWARE IS PROVIDED BY GRNET S.A. ``AS IS'' AND ANY EXPRESS
+# OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL GRNET S.A OR
+# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
+# USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
+# AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
+# ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+# POSSIBILITY OF SUCH DAMAGE.
+#
+# The views and conclusions contained in the software and
+# documentation are those of the authors and should not be
+# interpreted as representing official policies, either expressed
+# or implied, of GRNET S.A.
+
+from django import template
+
+register = template.Library()
+
+@register.filter
+def lookup(d, key):
+ return d[key]
\ No newline at end of file
formclass = 'LoginForm'
kwargs = {}
if request.user.is_authenticated():
- template_name = profile_template_name
- formclass = 'ProfileForm'
- kwargs.update({'instance':request.user})
+ return HttpResponseRedirect(reverse('astakos.im.views.edit_profile'))
return render_response(template_name,
form = globals()[formclass](**kwargs),
context_instance = get_context(request, extra_context))
CLOUDBAR_ACTIVE = True
-CLOUDBAR_LOCATION = '/static/im/cloudbar'
+CLOUDBAR_LOCATION = '/static/im/cloudbar/'
CLOUDBAR_COOKIE_NAME = '_pithos2_a'
CLOUDBAR_ACTIVE_SERVICE = 'cloud'
CLOUDBAR_SERVICES_URL = '/im/get_services'
INSTALL_REQUIRES = [
'Django>=1.2, <1.3',
'South>=0.7, <=0.7.3',
- 'httplib2==0.6.0',
+ 'httplib2>=0.6.0',
'snf-common>=0.9.0',
'recaptcha-client>=1.0.5'
]