annotate 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
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
1
a49aa1b823f6 added SàT archive download link (detect the last version)
Goffi <goffi@goffi.org>
parents:
diff changeset
1 #!/usr/bin/python
a49aa1b823f6 added SàT archive download link (detect the last version)
Goffi <goffi@goffi.org>
parents:
diff changeset
2 # -*- coding: utf-8 -*-
a49aa1b823f6 added SàT archive download link (detect the last version)
Goffi <goffi@goffi.org>
parents:
diff changeset
3 """
a49aa1b823f6 added SàT archive download link (detect the last version)
Goffi <goffi@goffi.org>
parents:
diff changeset
4 SàT website: Salut à Toi's presentation website
a49aa1b823f6 added SàT archive download link (detect the last version)
Goffi <goffi@goffi.org>
parents:
diff changeset
5 Copyright (C) 2012 Jérôme Poisson (goffi@goffi.org)
a49aa1b823f6 added SàT archive download link (detect the last version)
Goffi <goffi@goffi.org>
parents:
diff changeset
6
a49aa1b823f6 added SàT archive download link (detect the last version)
Goffi <goffi@goffi.org>
parents:
diff changeset
7 This file is part of SàT website.
a49aa1b823f6 added SàT archive download link (detect the last version)
Goffi <goffi@goffi.org>
parents:
diff changeset
8
a49aa1b823f6 added SàT archive download link (detect the last version)
Goffi <goffi@goffi.org>
parents:
diff changeset
9 SàT website is free software: you can redistribute it and/or modify
a49aa1b823f6 added SàT archive download link (detect the last version)
Goffi <goffi@goffi.org>
parents:
diff changeset
10 it under the terms of the GNU Affero General Public License as published by
a49aa1b823f6 added SàT archive download link (detect the last version)
Goffi <goffi@goffi.org>
parents:
diff changeset
11 the Free Software Foundation, either version 3 of the License, or
a49aa1b823f6 added SàT archive download link (detect the last version)
Goffi <goffi@goffi.org>
parents:
diff changeset
12 (at your option) any later version.
a49aa1b823f6 added SàT archive download link (detect the last version)
Goffi <goffi@goffi.org>
parents:
diff changeset
13
a49aa1b823f6 added SàT archive download link (detect the last version)
Goffi <goffi@goffi.org>
parents:
diff changeset
14 Foobar is distributed in the hope that it will be useful,
a49aa1b823f6 added SàT archive download link (detect the last version)
Goffi <goffi@goffi.org>
parents:
diff changeset
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
a49aa1b823f6 added SàT archive download link (detect the last version)
Goffi <goffi@goffi.org>
parents:
diff changeset
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
a49aa1b823f6 added SàT archive download link (detect the last version)
Goffi <goffi@goffi.org>
parents:
diff changeset
17 GNU Affero General Public License for more details.
a49aa1b823f6 added SàT archive download link (detect the last version)
Goffi <goffi@goffi.org>
parents:
diff changeset
18
a49aa1b823f6 added SàT archive download link (detect the last version)
Goffi <goffi@goffi.org>
parents:
diff changeset
19 You should have received a copy of the GNU Affero General Public License
a49aa1b823f6 added SàT archive download link (detect the last version)
Goffi <goffi@goffi.org>
parents:
diff changeset
20 along with Foobar. If not, see <http://www.gnu.org/licenses/>.
a49aa1b823f6 added SàT archive download link (detect the last version)
Goffi <goffi@goffi.org>
parents:
diff changeset
21 """
a49aa1b823f6 added SàT archive download link (detect the last version)
Goffi <goffi@goffi.org>
parents:
diff changeset
22
39
d2c45f4ba57e add downloads.html
souliane <souliane@mailoo.org>
parents: 31
diff changeset
23 from os.path import basename, realpath, join
1
a49aa1b823f6 added SàT archive download link (detect the last version)
Goffi <goffi@goffi.org>
parents:
diff changeset
24 from django.conf import settings
39
d2c45f4ba57e add downloads.html
souliane <souliane@mailoo.org>
parents: 31
diff changeset
25 from collections import OrderedDict
d2c45f4ba57e add downloads.html
souliane <souliane@mailoo.org>
parents: 31
diff changeset
26
d2c45f4ba57e add downloads.html
souliane <souliane@mailoo.org>
parents: 31
diff changeset
27
d2c45f4ba57e add downloads.html
souliane <souliane@mailoo.org>
parents: 31
diff changeset
28 def get_projects_infos(infos):
d2c45f4ba57e add downloads.html
souliane <souliane@mailoo.org>
parents: 31
diff changeset
29 """Return a dict binding project names to a tuple containing:
d2c45f4ba57e add downloads.html
souliane <souliane@mailoo.org>
parents: 31
diff changeset
30 - the external download path
d2c45f4ba57e add downloads.html
souliane <souliane@mailoo.org>
parents: 31
diff changeset
31 - the version number
d2c45f4ba57e add downloads.html
souliane <souliane@mailoo.org>
parents: 31
diff changeset
32 - a short description about the project archive
d2c45f4ba57e add downloads.html
souliane <souliane@mailoo.org>
parents: 31
diff changeset
33
d2c45f4ba57e add downloads.html
souliane <souliane@mailoo.org>
parents: 31
diff changeset
34 @param infos: dict binding project names to a short description
1
a49aa1b823f6 added SàT archive download link (detect the last version)
Goffi <goffi@goffi.org>
parents:
diff changeset
35
39
d2c45f4ba57e add downloads.html
souliane <souliane@mailoo.org>
parents: 31
diff changeset
36 @return: dict {unicode: (unicode, unicode, unicode)
d2c45f4ba57e add downloads.html
souliane <souliane@mailoo.org>
parents: 31
diff changeset
37 """
d2c45f4ba57e add downloads.html
souliane <souliane@mailoo.org>
parents: 31
diff changeset
38 result = OrderedDict()
d2c45f4ba57e add downloads.html
souliane <souliane@mailoo.org>
parents: 31
diff changeset
39 for dir, name in settings.PROJECTS_NAMES:
d2c45f4ba57e add downloads.html
souliane <souliane@mailoo.org>
parents: 31
diff changeset
40 if not name:
d2c45f4ba57e add downloads.html
souliane <souliane@mailoo.org>
parents: 31
diff changeset
41 name = dir
d2c45f4ba57e add downloads.html
souliane <souliane@mailoo.org>
parents: 31
diff changeset
42 path = join(dir, name) + settings.ARCHIVE_SUFFIX # e.g urwid-satext/urwid_satext.tar.bz2
d2c45f4ba57e add downloads.html
souliane <souliane@mailoo.org>
parents: 31
diff changeset
43 int_path = join(settings.PROJECTS_INTERNAL_PATH, path) # this is a symbolic link
d2c45f4ba57e add downloads.html
souliane <souliane@mailoo.org>
parents: 31
diff changeset
44 # base name of the real path MUST look like: <project>-<version><ARCHIVE_SUFFIX>
d2c45f4ba57e add downloads.html
souliane <souliane@mailoo.org>
parents: 31
diff changeset
45 version = basename(realpath(int_path))[len(name) + 1:-len(settings.ARCHIVE_SUFFIX)]
d2c45f4ba57e add downloads.html
souliane <souliane@mailoo.org>
parents: 31
diff changeset
46 ext_path = join(settings.PROJECTS_EXTERNAL_PATH, path)
d2c45f4ba57e add downloads.html
souliane <souliane@mailoo.org>
parents: 31
diff changeset
47 result[name] = (ext_path, version, infos[name] if name in infos else '')
d2c45f4ba57e add downloads.html
souliane <souliane@mailoo.org>
parents: 31
diff changeset
48
d2c45f4ba57e add downloads.html
souliane <souliane@mailoo.org>
parents: 31
diff changeset
49 return result
31
31d196cf3b34 add settings ASSO_MEMBERS_*, ASSO_FINANCE_* and LIBERVIA_DEMO_URL
souliane <souliane@mailoo.org>
parents: 1
diff changeset
50
31d196cf3b34 add settings ASSO_MEMBERS_*, ASSO_FINANCE_* and LIBERVIA_DEMO_URL
souliane <souliane@mailoo.org>
parents: 1
diff changeset
51 def get_libervia_demo_url():
31d196cf3b34 add settings ASSO_MEMBERS_*, ASSO_FINANCE_* and LIBERVIA_DEMO_URL
souliane <souliane@mailoo.org>
parents: 1
diff changeset
52 """Return the URL to Libervia online demo"""
31d196cf3b34 add settings ASSO_MEMBERS_*, ASSO_FINANCE_* and LIBERVIA_DEMO_URL
souliane <souliane@mailoo.org>
parents: 1
diff changeset
53 return settings.LIBERVIA_DEMO_URL
31d196cf3b34 add settings ASSO_MEMBERS_*, ASSO_FINANCE_* and LIBERVIA_DEMO_URL
souliane <souliane@mailoo.org>
parents: 1
diff changeset
54
31d196cf3b34 add settings ASSO_MEMBERS_*, ASSO_FINANCE_* and LIBERVIA_DEMO_URL
souliane <souliane@mailoo.org>
parents: 1
diff changeset
55 def get_asso_finance_status():
31d196cf3b34 add settings ASSO_MEMBERS_*, ASSO_FINANCE_* and LIBERVIA_DEMO_URL
souliane <souliane@mailoo.org>
parents: 1
diff changeset
56 """Returns information about the financement of the association"""
31d196cf3b34 add settings ASSO_MEMBERS_*, ASSO_FINANCE_* and LIBERVIA_DEMO_URL
souliane <souliane@mailoo.org>
parents: 1
diff changeset
57 def get_items(actual, target, prefix):
31d196cf3b34 add settings ASSO_MEMBERS_*, ASSO_FINANCE_* and LIBERVIA_DEMO_URL
souliane <souliane@mailoo.org>
parents: 1
diff changeset
58 actual = int(actual)
31d196cf3b34 add settings ASSO_MEMBERS_*, ASSO_FINANCE_* and LIBERVIA_DEMO_URL
souliane <souliane@mailoo.org>
parents: 1
diff changeset
59 target = int(target)
31d196cf3b34 add settings ASSO_MEMBERS_*, ASSO_FINANCE_* and LIBERVIA_DEMO_URL
souliane <souliane@mailoo.org>
parents: 1
diff changeset
60 perc = actual * 100 / target
31d196cf3b34 add settings ASSO_MEMBERS_*, ASSO_FINANCE_* and LIBERVIA_DEMO_URL
souliane <souliane@mailoo.org>
parents: 1
diff changeset
61 return {prefix + 'actual': actual,
31d196cf3b34 add settings ASSO_MEMBERS_*, ASSO_FINANCE_* and LIBERVIA_DEMO_URL
souliane <souliane@mailoo.org>
parents: 1
diff changeset
62 prefix + 'target': target,
31d196cf3b34 add settings ASSO_MEMBERS_*, ASSO_FINANCE_* and LIBERVIA_DEMO_URL
souliane <souliane@mailoo.org>
parents: 1
diff changeset
63 prefix + 'left': target - actual,
31d196cf3b34 add settings ASSO_MEMBERS_*, ASSO_FINANCE_* and LIBERVIA_DEMO_URL
souliane <souliane@mailoo.org>
parents: 1
diff changeset
64 prefix + 'perc': perc,
31d196cf3b34 add settings ASSO_MEMBERS_*, ASSO_FINANCE_* and LIBERVIA_DEMO_URL
souliane <souliane@mailoo.org>
parents: 1
diff changeset
65 prefix + 'perc_left': 100 - perc,
31d196cf3b34 add settings ASSO_MEMBERS_*, ASSO_FINANCE_* and LIBERVIA_DEMO_URL
souliane <souliane@mailoo.org>
parents: 1
diff changeset
66 }
31d196cf3b34 add settings ASSO_MEMBERS_*, ASSO_FINANCE_* and LIBERVIA_DEMO_URL
souliane <souliane@mailoo.org>
parents: 1
diff changeset
67
31d196cf3b34 add settings ASSO_MEMBERS_*, ASSO_FINANCE_* and LIBERVIA_DEMO_URL
souliane <souliane@mailoo.org>
parents: 1
diff changeset
68 items = get_items(settings.ASSO_FINANCE_ACTUAL, settings.ASSO_FINANCE_TARGET, 'asso_finance_')
31d196cf3b34 add settings ASSO_MEMBERS_*, ASSO_FINANCE_* and LIBERVIA_DEMO_URL
souliane <souliane@mailoo.org>
parents: 1
diff changeset
69 items.update(get_items(settings.ASSO_MEMBERS_ACTUAL, settings.ASSO_MEMBERS_TARGET, 'asso_members_'))
31d196cf3b34 add settings ASSO_MEMBERS_*, ASSO_FINANCE_* and LIBERVIA_DEMO_URL
souliane <souliane@mailoo.org>
parents: 1
diff changeset
70 return items
31d196cf3b34 add settings ASSO_MEMBERS_*, ASSO_FINANCE_* and LIBERVIA_DEMO_URL
souliane <souliane@mailoo.org>
parents: 1
diff changeset
71
31d196cf3b34 add settings ASSO_MEMBERS_*, ASSO_FINANCE_* and LIBERVIA_DEMO_URL
souliane <souliane@mailoo.org>
parents: 1
diff changeset
72 def get_asso_subscr_amounts():
31d196cf3b34 add settings ASSO_MEMBERS_*, ASSO_FINANCE_* and LIBERVIA_DEMO_URL
souliane <souliane@mailoo.org>
parents: 1
diff changeset
73 return settings.ASSO_SUBSCR_AMOUNTS