view sat_website/utils.py @ 50:10cdc1fbc4c7

update principles.html
author souliane <souliane@mailoo.org>
date Sun, 03 May 2015 22:58:42 +0200
parents 1a0f24401866
children 746e53efc188
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 os.path import basename, realpath, join
from django.conf import settings
from django.utils import translation
from collections import OrderedDict


def get_projects_infos(infos):
    """Return a dict binding project names to a tuple containing:
        - the external download path
        - the version number
        - a short description about the project archive
        
    @param infos: dict binding project names to a short description

    @return: dict {unicode: (unicode, unicode, unicode)
    """
    result = OrderedDict()
    for dir, name in settings.PROJECTS_NAMES:
        if not name:
            name = dir
        path = join(dir, name) + settings.ARCHIVE_SUFFIX  # e.g urwid-satext/urwid_satext.tar.bz2
        int_path = join(settings.PROJECTS_INTERNAL_PATH, path)  # this is a symbolic link
        # base name of the real path MUST look like: <project>-<version><ARCHIVE_SUFFIX>
        version = basename(realpath(int_path))[len(name) + 1:-len(settings.ARCHIVE_SUFFIX)]
        ext_path = join(settings.PROJECTS_EXTERNAL_PATH, path)
        result[name] = (ext_path, version, infos[name] if name in infos else '')

    return result

def get_libervia_demo_url():
    """Returns the URL to Libervia online demo."""
    return settings.LIBERVIA_DEMO_URL

def get_asso_urls():
    """Returns URLs related to the association"""
    return {'asso_url_statutes': settings.ASSO_URL_STATUTES,
            'asso_url_rules': settings.ASSO_URL_RULES
            }

def get_asso_finance_status():
    """Returns information about the financing of the association."""
    def get_items(actual, target, prefix):
        actual = int(actual)
        target = int(target)
        perc = actual * 100 / target
        return {prefix + 'actual': actual,
                prefix + 'target': target,
                prefix + 'left': target - actual,
                prefix + 'perc': perc,
                prefix + 'perc_left': 100 - perc,
                }

    items = get_items(settings.ASSO_FINANCE_ACTUAL, settings.ASSO_FINANCE_TARGET, 'asso_finance_')
    items.update(get_items(settings.ASSO_MEMBERS_ACTUAL, settings.ASSO_MEMBERS_TARGET, 'asso_members_'))
    return items

def get_asso_subscr_amounts():
    """Returns the subscription amounts as defined in the Rules of the association."""
    return settings.ASSO_SUBSCR_AMOUNTS

def get_language_name_local(language):
    """Returns the localised language name.
    
    @param language (str): language code (e.g. 'fr' or 'en')
    """
    return translation.get_language_info(language)['name_local']