changeset 27:eda4deefecd1

reorganisation of the menu using submenus
author souliane <souliane@mailoo.org>
date Wed, 21 Jan 2015 20:07:20 +0100
parents 3df49721008c
children 30a1edf90fae
files sat_website/templatetags/utils.py sat_website/views.py templates/sat_website/base.html templates/sat_website/menu.html
diffstat 4 files changed, 92 insertions(+), 21 deletions(-) [+]
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/sat_website/templatetags/utils.py	Wed Jan 21 20:07:20 2015 +0100
@@ -0,0 +1,14 @@
+from django import template
+register = template.Library()
+
+@register.filter
+def is_tuple(value):
+    """Tell if this value is a tuple or not.
+
+    @param value (obj): any object
+    @return: True if value is a tuple
+    """
+    # XXX: we would like to have is_type with an argument instead, but it would
+    # rely on a strange comparison - isinstance(value, arg) doesn't work here
+    return type(value) == tuple
+
--- a/sat_website/views.py	Mon Jan 19 21:22:40 2015 +0100
+++ b/sat_website/views.py	Wed Jan 21 20:07:20 2015 +0100
@@ -27,12 +27,29 @@
 from collections import OrderedDict
 import screenshots, social_contract, utils
 
-CATEGORIES = OrderedDict([("features", _(u"Features")),
-              ("frontends", _(u"Frontends")),
-              ("screenshots", _(u"Screenshots & Videos")),
-              ("community", _(u"Community")),
-              ("developers", _(u"Developers corner")),
-              ("social_contract", _(u"Social contract"))])
+CATEGORIES = OrderedDict([('frontends', (_(u"Presentation"),
+                                OrderedDict([("features", _(u"Features")),
+                                             ("frontends", _(u"Frontends")),
+                                             ("screenshots", _(u"Screenshots & Videos")),
+                                             ]))),
+                          ('principles', (_(u"Technical area"),
+                                OrderedDict([("principles", _(u"Principles")),
+                                             ("specifications", _(u"Specifications")),
+                                             ("screenshots_tech", _(u"Screenshots & Videos")),
+                                             ("downloads", _(u"Downloads")),
+                                             ("developers", _(u"Developers corner")),
+                                             ]))),
+                          ('community', (_(u"Community"),
+                                OrderedDict([("community", _(u"Get in touch")),
+                                             ("association", _(u"Association")),
+                                             ("links", _(u"Links")),
+                                             ]))),
+                          ])
+
+CATEGORIES_RIGHT = OrderedDict([("adhesion", _(u"Adhesion")),
+                                ("social_contract", _(u"Social contract")),
+                                ])
+
 
 def overview(request):
     return render_to_response('sat_website/overview.html')
@@ -42,10 +59,12 @@
     context = {
                "available_languages": ['fr', 'en'],
                "categories": CATEGORIES,
+               "categories_right": CATEGORIES_RIGHT,
                "category": category,
                "latest_dl_path": latest_dl_path,
                "latest_version": latest_version,
               }
+
     context.update(csrf(request))
 
     if not category or category == "overview":
@@ -53,11 +72,17 @@
     elif category == "screenshots":
         context["screenshots"] = screenshots.screenshots
         context["screencasts"] = screenshots.screencasts
-        return render_to_response('sat_website/screenshots.html', context)
+    elif category == "screenshots_tech":
+        context["screenshots"] = screenshots.screencasts
+        context["screencasts"] = screenshots.screencasts
     elif category == "social_contract":
         context["SOCIAL_CONTRACT"] = social_contract.get_social_contract()
-        return render_to_response('sat_website/social_contract.html', context)
-    elif category in CATEGORIES.keys():
+
+    def all_keys(cats):
+        subcats = [value[1].keys() for value in cats.values() if isinstance(value, tuple)]
+        return sum(subcats, cats.keys())
+
+    if category in all_keys(CATEGORIES) or category in all_keys(CATEGORIES_RIGHT):
         return render_to_response('sat_website/%s.html' % (category,), context)
     else:
         raise Http404
--- a/templates/sat_website/base.html	Mon Jan 19 21:22:40 2015 +0100
+++ b/templates/sat_website/base.html	Wed Jan 21 20:07:20 2015 +0100
@@ -28,7 +28,7 @@
     <meta charset="utf-8">
     <meta http-equiv="X-UA-Compatible" content="IE=edge">
     <meta name="viewport" content="width=device-width, initial-scale=1">
-    <link href="{% static "bootstrap/css/bootstrap.min.css" %}" rel="stylesheet">
+    <link rel="stylesheet" href="{% static "bootstrap/css/bootstrap.min.css" %}">
     <link rel="stylesheet" href="{% static "css/sat_website.css" %}">
     <link rel="icon" type="image/png" href="{% static "images/sat_logo_32.png" %}">
     <title>{% block title %}{% trans "Salut à Toi: the multi-frontends, multi-purposes communication tool" %}{% endblock %}</title>
@@ -49,17 +49,8 @@
                 </a>
             </div>
             <div id="navbar" class="collapse navbar-collapse">
-                <ul class="nav navbar-nav">
-                    {% for cat_url,cat_name in categories.items %}
-                        <li><a href="{{ cat_url }}.html">{{ cat_name }}</a></li>
-                    {% endfor %}
-                </ul>
-                <ul class="nav navbar-nav pull-right">
-                    <li><a href="https://www.libervia.org"><strong>{% trans "Try online demo" %}</strong></a> </li>
-                    {% if latest_dl_path and latest_version %}
-                        <li><a href="{{ latest_dl_path }}"><strong>{% trans "Download SàT" %} {{ latest_version }}</strong></a> </li>
-                    {% endif %}
-                </ul>
+                {% include "sat_website/menu.html" with style="nav navbar-nav" categories=categories %}
+                {% include "sat_website/menu.html" with style="nav navbar-nav pull-right" categories=categories_right %}
             </div>
         </div>
     </nav>
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/templates/sat_website/menu.html	Wed Jan 21 20:07:20 2015 +0100
@@ -0,0 +1,41 @@
+{% comment %}
+SàT website: Salut à Toi's presentation website
+Copyright (C) 2012  Jérôme Poisson (goffi@goffi.org)
+
+This file is part of SàT website.
+
+SàT website is free software: you can redistribute it and/or modify
+it under the terms of the GNU Affero General Public License as published by
+the Free Software Foundation, either version 3 of the License, or
+(at your option) any later version.
+
+Foobar is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+GNU Affero General Public License for more details.
+
+You should have received a copy of the GNU Affero General Public License
+along with Foobar.  If not, see <http://www.gnu.org/licenses/>.
+{% endcomment %}
+
+{% load utils %}
+
+<ul class="{{ style }}">
+    {% for cat_url, item in categories.items %}
+        {% if item|is_tuple %}
+            <li class="dropdown">
+                <a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-expanded="false">
+                    {{ item.0 }}
+                    <span class="caret"></span>
+                </a>
+                <ul class="dropdown-menu" role="menu">
+                    {% for subcat_url, cat_name in item.1.items %}
+                        <li><a href="{{ subcat_url }}.html">{{ cat_name }}</a></li>
+                    {% endfor %}
+                </ul>
+            </li>
+        {% else %}
+            <li><a href="{{ cat_url }}.html"><strong>{{ item }}</strong></a></li>
+        {% endif %}
+    {% endfor %}
+</ul>