fix internal astakos menu & minor other changes:
authorSofia Papagiannaki <papagian@gmail.com>
Thu, 8 Mar 2012 13:00:29 +0000 (15:00 +0200)
committerSofia Papagiannaki <papagian@gmail.com>
Thu, 8 Mar 2012 13:00:29 +0000 (15:00 +0200)
* invoke `get_menu` to dynamically load navigation items
* fix cloudbar settings
* fix httplib2 requirement

snf-astakos-app/astakos/im/api.py
snf-astakos-app/astakos/im/context_processors.py
snf-astakos-app/astakos/im/synnefo_settings.py
snf-astakos-app/astakos/im/templates/im/account_base.html
snf-astakos-app/astakos/im/templatetags/filters.py [new file with mode: 0644]
snf-astakos-app/astakos/im/views.py
snf-astakos-app/conf/20-snf-astakos-app-cloudbar.conf
snf-astakos-app/setup.py

index 6197699..893b9ac 100644 (file)
@@ -117,8 +117,6 @@ def get_services(request):
     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')
@@ -135,7 +133,7 @@ def get_menu(request):
     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" })
index 029e9c8..38b0382 100644 (file)
 
 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}
@@ -66,3 +69,11 @@ def cloudbar(request):
             '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}
index 38efce5..21abb70 100644 (file)
@@ -54,6 +54,7 @@ context_processors = [
     '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'
 ]
 
index 33b9184..ebfb26d 100644 (file)
@@ -1,5 +1,7 @@
 {% 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 %}
diff --git a/snf-astakos-app/astakos/im/templatetags/filters.py b/snf-astakos-app/astakos/im/templatetags/filters.py
new file mode 100644 (file)
index 0000000..9e5d10d
--- /dev/null
@@ -0,0 +1,40 @@
+# 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
index 20249a9..36e257f 100644 (file)
@@ -117,9 +117,7 @@ def index(request, login_template_name='im/login.html', profile_template_name='i
     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))
index c5f0ebb..0068cd9 100644 (file)
@@ -1,5 +1,5 @@
 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'
index 630d6f9..93ccad8 100644 (file)
@@ -77,7 +77,7 @@ CLASSIFIERS = [
 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'
 ]