annotate sat_website/utils.py @ 87:0377931f6278

add press release for Libervia 2015
author souliane <souliane@mailoo.org>
date Mon, 15 Jun 2015 21:03:25 +0200
parents 746e53efc188
children b1c16cd53b62
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
41
1a0f24401866 send adhesion form results via email to the admins and the new member
souliane <souliane@mailoo.org>
parents: 40
diff changeset
25 from django.utils import translation
39
d2c45f4ba57e add downloads.html
souliane <souliane@mailoo.org>
parents: 31
diff changeset
26 from collections import OrderedDict
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
d2c45f4ba57e add downloads.html
souliane <souliane@mailoo.org>
parents: 31
diff changeset
29 def get_projects_infos(infos):
d2c45f4ba57e add downloads.html
souliane <souliane@mailoo.org>
parents: 31
diff changeset
30 """Return a dict binding project names to a tuple containing:
d2c45f4ba57e add downloads.html
souliane <souliane@mailoo.org>
parents: 31
diff changeset
31 - the external download path
d2c45f4ba57e add downloads.html
souliane <souliane@mailoo.org>
parents: 31
diff changeset
32 - the version number
d2c45f4ba57e add downloads.html
souliane <souliane@mailoo.org>
parents: 31
diff changeset
33 - a short description about the project archive
d2c45f4ba57e add downloads.html
souliane <souliane@mailoo.org>
parents: 31
diff changeset
34
d2c45f4ba57e add downloads.html
souliane <souliane@mailoo.org>
parents: 31
diff changeset
35 @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
36
39
d2c45f4ba57e add downloads.html
souliane <souliane@mailoo.org>
parents: 31
diff changeset
37 @return: dict {unicode: (unicode, unicode, unicode)
d2c45f4ba57e add downloads.html
souliane <souliane@mailoo.org>
parents: 31
diff changeset
38 """
d2c45f4ba57e add downloads.html
souliane <souliane@mailoo.org>
parents: 31
diff changeset
39 result = OrderedDict()
d2c45f4ba57e add downloads.html
souliane <souliane@mailoo.org>
parents: 31
diff changeset
40 for dir, name in settings.PROJECTS_NAMES:
d2c45f4ba57e add downloads.html
souliane <souliane@mailoo.org>
parents: 31
diff changeset
41 if not name:
d2c45f4ba57e add downloads.html
souliane <souliane@mailoo.org>
parents: 31
diff changeset
42 name = dir
d2c45f4ba57e add downloads.html
souliane <souliane@mailoo.org>
parents: 31
diff changeset
43 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
44 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
45 # 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
46 version = basename(realpath(int_path))[len(name) + 1:-len(settings.ARCHIVE_SUFFIX)]
58
746e53efc188 allow large media files (screencasts) to be stored on an external server
souliane <souliane@mailoo.org>
parents: 41
diff changeset
47 ext_path = join(settings.PROJECTS_EXTERNAL_URL, path)
39
d2c45f4ba57e add downloads.html
souliane <souliane@mailoo.org>
parents: 31
diff changeset
48 result[name] = (ext_path, version, infos[name] if name in infos else '')
d2c45f4ba57e add downloads.html
souliane <souliane@mailoo.org>
parents: 31
diff changeset
49
d2c45f4ba57e add downloads.html
souliane <souliane@mailoo.org>
parents: 31
diff changeset
50 return result
31
31d196cf3b34 add settings ASSO_MEMBERS_*, ASSO_FINANCE_* and LIBERVIA_DEMO_URL
souliane <souliane@mailoo.org>
parents: 1
diff changeset
51
31d196cf3b34 add settings ASSO_MEMBERS_*, ASSO_FINANCE_* and LIBERVIA_DEMO_URL
souliane <souliane@mailoo.org>
parents: 1
diff changeset
52 def get_libervia_demo_url():
40
dfe7139dae0a add links to the statutes and rules of the association in the adhesion form
souliane <souliane@mailoo.org>
parents: 39
diff changeset
53 """Returns the URL to Libervia online demo."""
31
31d196cf3b34 add settings ASSO_MEMBERS_*, ASSO_FINANCE_* and LIBERVIA_DEMO_URL
souliane <souliane@mailoo.org>
parents: 1
diff changeset
54 return settings.LIBERVIA_DEMO_URL
31d196cf3b34 add settings ASSO_MEMBERS_*, ASSO_FINANCE_* and LIBERVIA_DEMO_URL
souliane <souliane@mailoo.org>
parents: 1
diff changeset
55
40
dfe7139dae0a add links to the statutes and rules of the association in the adhesion form
souliane <souliane@mailoo.org>
parents: 39
diff changeset
56 def get_asso_urls():
dfe7139dae0a add links to the statutes and rules of the association in the adhesion form
souliane <souliane@mailoo.org>
parents: 39
diff changeset
57 """Returns URLs related to the association"""
dfe7139dae0a add links to the statutes and rules of the association in the adhesion form
souliane <souliane@mailoo.org>
parents: 39
diff changeset
58 return {'asso_url_statutes': settings.ASSO_URL_STATUTES,
dfe7139dae0a add links to the statutes and rules of the association in the adhesion form
souliane <souliane@mailoo.org>
parents: 39
diff changeset
59 'asso_url_rules': settings.ASSO_URL_RULES
dfe7139dae0a add links to the statutes and rules of the association in the adhesion form
souliane <souliane@mailoo.org>
parents: 39
diff changeset
60 }
dfe7139dae0a add links to the statutes and rules of the association in the adhesion form
souliane <souliane@mailoo.org>
parents: 39
diff changeset
61
31
31d196cf3b34 add settings ASSO_MEMBERS_*, ASSO_FINANCE_* and LIBERVIA_DEMO_URL
souliane <souliane@mailoo.org>
parents: 1
diff changeset
62 def get_asso_finance_status():
40
dfe7139dae0a add links to the statutes and rules of the association in the adhesion form
souliane <souliane@mailoo.org>
parents: 39
diff changeset
63 """Returns information about the financing of the association."""
31
31d196cf3b34 add settings ASSO_MEMBERS_*, ASSO_FINANCE_* and LIBERVIA_DEMO_URL
souliane <souliane@mailoo.org>
parents: 1
diff changeset
64 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
65 actual = int(actual)
31d196cf3b34 add settings ASSO_MEMBERS_*, ASSO_FINANCE_* and LIBERVIA_DEMO_URL
souliane <souliane@mailoo.org>
parents: 1
diff changeset
66 target = int(target)
31d196cf3b34 add settings ASSO_MEMBERS_*, ASSO_FINANCE_* and LIBERVIA_DEMO_URL
souliane <souliane@mailoo.org>
parents: 1
diff changeset
67 perc = actual * 100 / target
31d196cf3b34 add settings ASSO_MEMBERS_*, ASSO_FINANCE_* and LIBERVIA_DEMO_URL
souliane <souliane@mailoo.org>
parents: 1
diff changeset
68 return {prefix + 'actual': actual,
31d196cf3b34 add settings ASSO_MEMBERS_*, ASSO_FINANCE_* and LIBERVIA_DEMO_URL
souliane <souliane@mailoo.org>
parents: 1
diff changeset
69 prefix + 'target': target,
31d196cf3b34 add settings ASSO_MEMBERS_*, ASSO_FINANCE_* and LIBERVIA_DEMO_URL
souliane <souliane@mailoo.org>
parents: 1
diff changeset
70 prefix + 'left': target - actual,
31d196cf3b34 add settings ASSO_MEMBERS_*, ASSO_FINANCE_* and LIBERVIA_DEMO_URL
souliane <souliane@mailoo.org>
parents: 1
diff changeset
71 prefix + 'perc': perc,
31d196cf3b34 add settings ASSO_MEMBERS_*, ASSO_FINANCE_* and LIBERVIA_DEMO_URL
souliane <souliane@mailoo.org>
parents: 1
diff changeset
72 prefix + 'perc_left': 100 - perc,
31d196cf3b34 add settings ASSO_MEMBERS_*, ASSO_FINANCE_* and LIBERVIA_DEMO_URL
souliane <souliane@mailoo.org>
parents: 1
diff changeset
73 }
31d196cf3b34 add settings ASSO_MEMBERS_*, ASSO_FINANCE_* and LIBERVIA_DEMO_URL
souliane <souliane@mailoo.org>
parents: 1
diff changeset
74
31d196cf3b34 add settings ASSO_MEMBERS_*, ASSO_FINANCE_* and LIBERVIA_DEMO_URL
souliane <souliane@mailoo.org>
parents: 1
diff changeset
75 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
76 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
77 return items
31d196cf3b34 add settings ASSO_MEMBERS_*, ASSO_FINANCE_* and LIBERVIA_DEMO_URL
souliane <souliane@mailoo.org>
parents: 1
diff changeset
78
31d196cf3b34 add settings ASSO_MEMBERS_*, ASSO_FINANCE_* and LIBERVIA_DEMO_URL
souliane <souliane@mailoo.org>
parents: 1
diff changeset
79 def get_asso_subscr_amounts():
40
dfe7139dae0a add links to the statutes and rules of the association in the adhesion form
souliane <souliane@mailoo.org>
parents: 39
diff changeset
80 """Returns the subscription amounts as defined in the Rules of the association."""
31
31d196cf3b34 add settings ASSO_MEMBERS_*, ASSO_FINANCE_* and LIBERVIA_DEMO_URL
souliane <souliane@mailoo.org>
parents: 1
diff changeset
81 return settings.ASSO_SUBSCR_AMOUNTS
41
1a0f24401866 send adhesion form results via email to the admins and the new member
souliane <souliane@mailoo.org>
parents: 40
diff changeset
82
1a0f24401866 send adhesion form results via email to the admins and the new member
souliane <souliane@mailoo.org>
parents: 40
diff changeset
83 def get_language_name_local(language):
1a0f24401866 send adhesion form results via email to the admins and the new member
souliane <souliane@mailoo.org>
parents: 40
diff changeset
84 """Returns the localised language name.
1a0f24401866 send adhesion form results via email to the admins and the new member
souliane <souliane@mailoo.org>
parents: 40
diff changeset
85
1a0f24401866 send adhesion form results via email to the admins and the new member
souliane <souliane@mailoo.org>
parents: 40
diff changeset
86 @param language (str): language code (e.g. 'fr' or 'en')
1a0f24401866 send adhesion form results via email to the admins and the new member
souliane <souliane@mailoo.org>
parents: 40
diff changeset
87 """
1a0f24401866 send adhesion form results via email to the admins and the new member
souliane <souliane@mailoo.org>
parents: 40
diff changeset
88 return translation.get_language_info(language)['name_local']