annotate sat_website/utils.py @ 35:10ce34ab389a

dummy patch (just add some new lines to make space between the blocks)
author souliane <souliane@mailoo.org>
date Tue, 27 Jan 2015 08:16:27 +0100
parents 31d196cf3b34
children d2c45f4ba57e
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
a49aa1b823f6 added SàT archive download link (detect the last version)
Goffi <goffi@goffi.org>
parents:
diff changeset
23 from os.path import basename,realpath,join
a49aa1b823f6 added SàT archive download link (detect the last version)
Goffi <goffi@goffi.org>
parents:
diff changeset
24 from django.conf import settings
a49aa1b823f6 added SàT archive download link (detect the last version)
Goffi <goffi@goffi.org>
parents:
diff changeset
25
a49aa1b823f6 added SàT archive download link (detect the last version)
Goffi <goffi@goffi.org>
parents:
diff changeset
26 def get_latest_sat():
a49aa1b823f6 added SàT archive download link (detect the last version)
Goffi <goffi@goffi.org>
parents:
diff changeset
27 """Return a tuple with download path of latest SàT version, and version number"""
a49aa1b823f6 added SàT archive download link (detect the last version)
Goffi <goffi@goffi.org>
parents:
diff changeset
28 try:
a49aa1b823f6 added SàT archive download link (detect the last version)
Goffi <goffi@goffi.org>
parents:
diff changeset
29 path = settings.SAT_LINK_PATH
a49aa1b823f6 added SàT archive download link (detect the last version)
Goffi <goffi@goffi.org>
parents:
diff changeset
30 real_path = realpath(path)
a49aa1b823f6 added SàT archive download link (detect the last version)
Goffi <goffi@goffi.org>
parents:
diff changeset
31 filename = basename(real_path)
a49aa1b823f6 added SàT archive download link (detect the last version)
Goffi <goffi@goffi.org>
parents:
diff changeset
32 version = filename[4:-8] #filename must be in the form of sat-version.tar.bz2
a49aa1b823f6 added SàT archive download link (detect the last version)
Goffi <goffi@goffi.org>
parents:
diff changeset
33 if hasattr(settings, "SAT_DL_PATH"):
a49aa1b823f6 added SàT archive download link (detect the last version)
Goffi <goffi@goffi.org>
parents:
diff changeset
34 dl_path = settings.SAT_DL_PATH
a49aa1b823f6 added SàT archive download link (detect the last version)
Goffi <goffi@goffi.org>
parents:
diff changeset
35 else:
a49aa1b823f6 added SàT archive download link (detect the last version)
Goffi <goffi@goffi.org>
parents:
diff changeset
36 dl_path = join(settings.SAT_DL_PREFIX, filename)
a49aa1b823f6 added SàT archive download link (detect the last version)
Goffi <goffi@goffi.org>
parents:
diff changeset
37 except AttributeError:
a49aa1b823f6 added SàT archive download link (detect the last version)
Goffi <goffi@goffi.org>
parents:
diff changeset
38 return (None, None)
a49aa1b823f6 added SàT archive download link (detect the last version)
Goffi <goffi@goffi.org>
parents:
diff changeset
39
a49aa1b823f6 added SàT archive download link (detect the last version)
Goffi <goffi@goffi.org>
parents:
diff changeset
40 return (dl_path, version)
31
31d196cf3b34 add settings ASSO_MEMBERS_*, ASSO_FINANCE_* and LIBERVIA_DEMO_URL
souliane <souliane@mailoo.org>
parents: 1
diff changeset
41
31d196cf3b34 add settings ASSO_MEMBERS_*, ASSO_FINANCE_* and LIBERVIA_DEMO_URL
souliane <souliane@mailoo.org>
parents: 1
diff changeset
42 def get_libervia_demo_url():
31d196cf3b34 add settings ASSO_MEMBERS_*, ASSO_FINANCE_* and LIBERVIA_DEMO_URL
souliane <souliane@mailoo.org>
parents: 1
diff changeset
43 """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
44 return settings.LIBERVIA_DEMO_URL
31d196cf3b34 add settings ASSO_MEMBERS_*, ASSO_FINANCE_* and LIBERVIA_DEMO_URL
souliane <souliane@mailoo.org>
parents: 1
diff changeset
45
31d196cf3b34 add settings ASSO_MEMBERS_*, ASSO_FINANCE_* and LIBERVIA_DEMO_URL
souliane <souliane@mailoo.org>
parents: 1
diff changeset
46 def get_asso_finance_status():
31d196cf3b34 add settings ASSO_MEMBERS_*, ASSO_FINANCE_* and LIBERVIA_DEMO_URL
souliane <souliane@mailoo.org>
parents: 1
diff changeset
47 """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
48 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
49 actual = int(actual)
31d196cf3b34 add settings ASSO_MEMBERS_*, ASSO_FINANCE_* and LIBERVIA_DEMO_URL
souliane <souliane@mailoo.org>
parents: 1
diff changeset
50 target = int(target)
31d196cf3b34 add settings ASSO_MEMBERS_*, ASSO_FINANCE_* and LIBERVIA_DEMO_URL
souliane <souliane@mailoo.org>
parents: 1
diff changeset
51 perc = actual * 100 / target
31d196cf3b34 add settings ASSO_MEMBERS_*, ASSO_FINANCE_* and LIBERVIA_DEMO_URL
souliane <souliane@mailoo.org>
parents: 1
diff changeset
52 return {prefix + 'actual': actual,
31d196cf3b34 add settings ASSO_MEMBERS_*, ASSO_FINANCE_* and LIBERVIA_DEMO_URL
souliane <souliane@mailoo.org>
parents: 1
diff changeset
53 prefix + 'target': target,
31d196cf3b34 add settings ASSO_MEMBERS_*, ASSO_FINANCE_* and LIBERVIA_DEMO_URL
souliane <souliane@mailoo.org>
parents: 1
diff changeset
54 prefix + 'left': target - actual,
31d196cf3b34 add settings ASSO_MEMBERS_*, ASSO_FINANCE_* and LIBERVIA_DEMO_URL
souliane <souliane@mailoo.org>
parents: 1
diff changeset
55 prefix + 'perc': perc,
31d196cf3b34 add settings ASSO_MEMBERS_*, ASSO_FINANCE_* and LIBERVIA_DEMO_URL
souliane <souliane@mailoo.org>
parents: 1
diff changeset
56 prefix + 'perc_left': 100 - perc,
31d196cf3b34 add settings ASSO_MEMBERS_*, ASSO_FINANCE_* and LIBERVIA_DEMO_URL
souliane <souliane@mailoo.org>
parents: 1
diff changeset
57 }
31d196cf3b34 add settings ASSO_MEMBERS_*, ASSO_FINANCE_* and LIBERVIA_DEMO_URL
souliane <souliane@mailoo.org>
parents: 1
diff changeset
58
31d196cf3b34 add settings ASSO_MEMBERS_*, ASSO_FINANCE_* and LIBERVIA_DEMO_URL
souliane <souliane@mailoo.org>
parents: 1
diff changeset
59 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
60 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
61 return items
31d196cf3b34 add settings ASSO_MEMBERS_*, ASSO_FINANCE_* and LIBERVIA_DEMO_URL
souliane <souliane@mailoo.org>
parents: 1
diff changeset
62
31d196cf3b34 add settings ASSO_MEMBERS_*, ASSO_FINANCE_* and LIBERVIA_DEMO_URL
souliane <souliane@mailoo.org>
parents: 1
diff changeset
63 def get_asso_subscr_amounts():
31d196cf3b34 add settings ASSO_MEMBERS_*, ASSO_FINANCE_* and LIBERVIA_DEMO_URL
souliane <souliane@mailoo.org>
parents: 1
diff changeset
64 return settings.ASSO_SUBSCR_AMOUNTS