Mercurial > sat_legacy_website
annotate sat_website/utils.py @ 104:82d920157dc9
fixes gallery CSS to avoid video items to disturb the grid
author | souliane <souliane@mailoo.org> |
---|---|
date | Sat, 17 Oct 2015 12:18:44 +0200 |
parents | 746e53efc188 |
children | b1c16cd53b62 |
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 | 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 | 26 from collections import OrderedDict |
27 | |
28 | |
29 def get_projects_infos(infos): | |
30 """Return a dict binding project names to a tuple containing: | |
31 - the external download path | |
32 - the version number | |
33 - a short description about the project archive | |
34 | |
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 | 37 @return: dict {unicode: (unicode, unicode, unicode) |
38 """ | |
39 result = OrderedDict() | |
40 for dir, name in settings.PROJECTS_NAMES: | |
41 if not name: | |
42 name = dir | |
43 path = join(dir, name) + settings.ARCHIVE_SUFFIX # e.g urwid-satext/urwid_satext.tar.bz2 | |
44 int_path = join(settings.PROJECTS_INTERNAL_PATH, path) # this is a symbolic link | |
45 # base name of the real path MUST look like: <project>-<version><ARCHIVE_SUFFIX> | |
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 | 48 result[name] = (ext_path, version, infos[name] if name in infos else '') |
49 | |
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'] |