view sat_website/views.py @ 29:b45621706d83

use Bootstrap carousels to display images and videos galeries: - one carousel for a 3x3 thumbnails grid - a second one in a modal window to view bigger pictures when a thumbnail is clicked
author souliane <souliane@mailoo.org>
date Wed, 21 Jan 2015 20:13:19 +0100
parents eda4deefecd1
children 73c6333fd124
line wrap: on
line source

#!/usr/bin/python
# -*- coding: utf-8 -*-

"""
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/>.
"""
from django.http import Http404
from django.shortcuts import render_to_response
from django.core.context_processors import csrf
from django.utils.translation import ugettext_lazy as _
from collections import OrderedDict
import screenshots, social_contract, utils

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')

def generic_cat(request, category):
    latest_dl_path, latest_version = utils.get_latest_sat()
    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":
        return render_to_response('sat_website/overview.html', context)
    elif category == "screenshots":
        context["screenshots"] = screenshots.screenshots
    elif category == "screenshots_tech":
        context["screenshots"] = screenshots.screenshots_tech
    elif category == "social_contract":
        context["SOCIAL_CONTRACT"] = social_contract.get_social_contract()

    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