Mercurial > sat_legacy_website
view sat_website/utils.py @ 39:d2c45f4ba57e
add downloads.html
author | souliane <souliane@mailoo.org> |
---|---|
date | Tue, 27 Jan 2015 18:23:39 +0100 |
parents | 31d196cf3b34 |
children | dfe7139dae0a |
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 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(): """Return the URL to Libervia online demo""" return settings.LIBERVIA_DEMO_URL def get_asso_finance_status(): """Returns information about the financement 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(): return settings.ASSO_SUBSCR_AMOUNTS