annotate sat_website/views.py @ 147:d0cd185f9b61

replace apayer with liberapay
author souliane <souliane@mailoo.org>
date Tue, 17 Oct 2017 06:01:01 +0200
parents 2ec5653b190a
children b1c16cd53b62
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
9305c6458e2f initial commit
Goffi <goffi@goffi.org>
parents:
diff changeset
1 #!/usr/bin/python
9305c6458e2f initial commit
Goffi <goffi@goffi.org>
parents:
diff changeset
2 # -*- coding: utf-8 -*-
9305c6458e2f initial commit
Goffi <goffi@goffi.org>
parents:
diff changeset
3
9305c6458e2f initial commit
Goffi <goffi@goffi.org>
parents:
diff changeset
4 """
9305c6458e2f initial commit
Goffi <goffi@goffi.org>
parents:
diff changeset
5 SàT website: Salut à Toi's presentation website
9305c6458e2f initial commit
Goffi <goffi@goffi.org>
parents:
diff changeset
6 Copyright (C) 2012 Jérôme Poisson (goffi@goffi.org)
9305c6458e2f initial commit
Goffi <goffi@goffi.org>
parents:
diff changeset
7
9305c6458e2f initial commit
Goffi <goffi@goffi.org>
parents:
diff changeset
8 This file is part of SàT website.
9305c6458e2f initial commit
Goffi <goffi@goffi.org>
parents:
diff changeset
9
9305c6458e2f initial commit
Goffi <goffi@goffi.org>
parents:
diff changeset
10 SàT website is free software: you can redistribute it and/or modify
9305c6458e2f initial commit
Goffi <goffi@goffi.org>
parents:
diff changeset
11 it under the terms of the GNU Affero General Public License as published by
9305c6458e2f initial commit
Goffi <goffi@goffi.org>
parents:
diff changeset
12 the Free Software Foundation, either version 3 of the License, or
9305c6458e2f initial commit
Goffi <goffi@goffi.org>
parents:
diff changeset
13 (at your option) any later version.
9305c6458e2f initial commit
Goffi <goffi@goffi.org>
parents:
diff changeset
14
9305c6458e2f initial commit
Goffi <goffi@goffi.org>
parents:
diff changeset
15 Foobar is distributed in the hope that it will be useful,
9305c6458e2f initial commit
Goffi <goffi@goffi.org>
parents:
diff changeset
16 but WITHOUT ANY WARRANTY; without even the implied warranty of
9305c6458e2f initial commit
Goffi <goffi@goffi.org>
parents:
diff changeset
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
9305c6458e2f initial commit
Goffi <goffi@goffi.org>
parents:
diff changeset
18 GNU Affero General Public License for more details.
9305c6458e2f initial commit
Goffi <goffi@goffi.org>
parents:
diff changeset
19
9305c6458e2f initial commit
Goffi <goffi@goffi.org>
parents:
diff changeset
20 You should have received a copy of the GNU Affero General Public License
9305c6458e2f initial commit
Goffi <goffi@goffi.org>
parents:
diff changeset
21 along with Foobar. If not, see <http://www.gnu.org/licenses/>.
9305c6458e2f initial commit
Goffi <goffi@goffi.org>
parents:
diff changeset
22 """
138
2ec5653b190a add url "whereami" to get the client IP address
souliane <souliane@mailoo.org>
parents: 136
diff changeset
23 from django.http import Http404, HttpResponse
0
9305c6458e2f initial commit
Goffi <goffi@goffi.org>
parents:
diff changeset
24 from django.shortcuts import render_to_response
2
0df46e87537d i18n: marked translatable texts + add change language form on pages footer
Goffi <goffi@goffi.org>
parents: 1
diff changeset
25 from django.core.context_processors import csrf
0df46e87537d i18n: marked translatable texts + add change language form on pages footer
Goffi <goffi@goffi.org>
parents: 1
diff changeset
26 from django.utils.translation import ugettext_lazy as _
34
9d553570cc61 add adhesion_form.html and thank_you.html
souliane <souliane@mailoo.org>
parents: 33
diff changeset
27 from django.template import RequestContext
0
9305c6458e2f initial commit
Goffi <goffi@goffi.org>
parents:
diff changeset
28 from collections import OrderedDict
116
e138879873f1 changes to link the crowdfunding campaign (revert to be done manually after 45 days)
souliane <souliane@mailoo.org>
parents: 89
diff changeset
29 import datetime
89
4b4a5d7602f8 rename screenshots to media, since not only screenshots but also videos are listed
souliane <souliane@mailoo.org>
parents: 78
diff changeset
30 import media, social_contract, utils, forms
0
9305c6458e2f initial commit
Goffi <goffi@goffi.org>
parents:
diff changeset
31
27
eda4deefecd1 reorganisation of the menu using submenus
souliane <souliane@mailoo.org>
parents: 4
diff changeset
32 CATEGORIES = OrderedDict([('frontends', (_(u"Presentation"),
eda4deefecd1 reorganisation of the menu using submenus
souliane <souliane@mailoo.org>
parents: 4
diff changeset
33 OrderedDict([("features", _(u"Features")),
eda4deefecd1 reorganisation of the menu using submenus
souliane <souliane@mailoo.org>
parents: 4
diff changeset
34 ("frontends", _(u"Frontends")),
89
4b4a5d7602f8 rename screenshots to media, since not only screenshots but also videos are listed
souliane <souliane@mailoo.org>
parents: 78
diff changeset
35 ("media", _(u"Screenshots & Videos")),
136
c56b6ad62153 add section News with the official news feed
souliane <souliane@mailoo.org>
parents: 133
diff changeset
36 ("news", _(u"News")),
27
eda4deefecd1 reorganisation of the menu using submenus
souliane <souliane@mailoo.org>
parents: 4
diff changeset
37 ]))),
eda4deefecd1 reorganisation of the menu using submenus
souliane <souliane@mailoo.org>
parents: 4
diff changeset
38 ('principles', (_(u"Technical area"),
eda4deefecd1 reorganisation of the menu using submenus
souliane <souliane@mailoo.org>
parents: 4
diff changeset
39 OrderedDict([("principles", _(u"Principles")),
eda4deefecd1 reorganisation of the menu using submenus
souliane <souliane@mailoo.org>
parents: 4
diff changeset
40 ("specifications", _(u"Specifications")),
eda4deefecd1 reorganisation of the menu using submenus
souliane <souliane@mailoo.org>
parents: 4
diff changeset
41 ("downloads", _(u"Downloads")),
eda4deefecd1 reorganisation of the menu using submenus
souliane <souliane@mailoo.org>
parents: 4
diff changeset
42 ("developers", _(u"Developers corner")),
eda4deefecd1 reorganisation of the menu using submenus
souliane <souliane@mailoo.org>
parents: 4
diff changeset
43 ]))),
eda4deefecd1 reorganisation of the menu using submenus
souliane <souliane@mailoo.org>
parents: 4
diff changeset
44 ('community', (_(u"Community"),
eda4deefecd1 reorganisation of the menu using submenus
souliane <souliane@mailoo.org>
parents: 4
diff changeset
45 OrderedDict([("community", _(u"Get in touch")),
55
a1e457ac6871 split adhesion.html between adhesion.html and association.html
souliane <souliane@mailoo.org>
parents: 52
diff changeset
46 ("association", _(u"Association")),
27
eda4deefecd1 reorganisation of the menu using submenus
souliane <souliane@mailoo.org>
parents: 4
diff changeset
47 ("links", _(u"Links")),
56
01e9c646999f add links to other projects and press files
souliane <souliane@mailoo.org>
parents: 55
diff changeset
48 ("press", _(u"Press")),
76
d2ea666fb1dd add a FAQ section, now talking about HTTPS and CAcert
souliane <souliane@mailoo.org>
parents: 74
diff changeset
49 ("faq", _(u"FAQ")),
27
eda4deefecd1 reorganisation of the menu using submenus
souliane <souliane@mailoo.org>
parents: 4
diff changeset
50 ]))),
eda4deefecd1 reorganisation of the menu using submenus
souliane <souliane@mailoo.org>
parents: 4
diff changeset
51 ])
eda4deefecd1 reorganisation of the menu using submenus
souliane <souliane@mailoo.org>
parents: 4
diff changeset
52
77
13ebb548f234 use membership instead of adhesion in English (also rename the files)
souliane <souliane@mailoo.org>
parents: 76
diff changeset
53 CATEGORIES_RIGHT = OrderedDict([("membership", _(u"Membership")),
27
eda4deefecd1 reorganisation of the menu using submenus
souliane <souliane@mailoo.org>
parents: 4
diff changeset
54 ("social_contract", _(u"Social contract")),
eda4deefecd1 reorganisation of the menu using submenus
souliane <souliane@mailoo.org>
parents: 4
diff changeset
55 ])
eda4deefecd1 reorganisation of the menu using submenus
souliane <souliane@mailoo.org>
parents: 4
diff changeset
56
78
6250b65523c6 categories' aliases can be defined to be able to use "French" links like adhesion.html
souliane <souliane@mailoo.org>
parents: 77
diff changeset
57 CATEGORIES_ALIASES = {"adhesion": "membership",
6250b65523c6 categories' aliases can be defined to be able to use "French" links like adhesion.html
souliane <souliane@mailoo.org>
parents: 77
diff changeset
58 "adhesion_form": "membership_form",
89
4b4a5d7602f8 rename screenshots to media, since not only screenshots but also videos are listed
souliane <souliane@mailoo.org>
parents: 78
diff changeset
59 "screenshots": "media",
78
6250b65523c6 categories' aliases can be defined to be able to use "French" links like adhesion.html
souliane <souliane@mailoo.org>
parents: 77
diff changeset
60 }
6250b65523c6 categories' aliases can be defined to be able to use "French" links like adhesion.html
souliane <souliane@mailoo.org>
parents: 77
diff changeset
61
77
13ebb548f234 use membership instead of adhesion in English (also rename the files)
souliane <souliane@mailoo.org>
parents: 76
diff changeset
62 CATEGORIES_HIDDEN = ('membership_form', 'thank_you')
34
9d553570cc61 add adhesion_form.html and thank_you.html
souliane <souliane@mailoo.org>
parents: 33
diff changeset
63
39
d2c45f4ba57e add downloads.html
souliane <souliane@mailoo.org>
parents: 34
diff changeset
64 PROJECTS_INFOS = {'sat': _(u'contains the backend, Primitivus and Jp'),
d2c45f4ba57e add downloads.html
souliane <souliane@mailoo.org>
parents: 34
diff changeset
65 'sat_media': _(u'Images and other media needed to launch SàT'),
d2c45f4ba57e add downloads.html
souliane <souliane@mailoo.org>
parents: 34
diff changeset
66 'urwid_satext': _(u'console display library needed by Primitivus'),
d2c45f4ba57e add downloads.html
souliane <souliane@mailoo.org>
parents: 34
diff changeset
67 'sat_pubsub': _(u'PubSub server component needed for SàT experimental blogging features'),
d2c45f4ba57e add downloads.html
souliane <souliane@mailoo.org>
parents: 34
diff changeset
68 'libervia': _(u'Libervia frontend (web server and client)'),
d2c45f4ba57e add downloads.html
souliane <souliane@mailoo.org>
parents: 34
diff changeset
69 }
0
9305c6458e2f initial commit
Goffi <goffi@goffi.org>
parents:
diff changeset
70
138
2ec5653b190a add url "whereami" to get the client IP address
souliane <souliane@mailoo.org>
parents: 136
diff changeset
71
0
9305c6458e2f initial commit
Goffi <goffi@goffi.org>
parents:
diff changeset
72 def overview(request):
9305c6458e2f initial commit
Goffi <goffi@goffi.org>
parents:
diff changeset
73 return render_to_response('sat_website/overview.html')
9305c6458e2f initial commit
Goffi <goffi@goffi.org>
parents:
diff changeset
74
138
2ec5653b190a add url "whereami" to get the client IP address
souliane <souliane@mailoo.org>
parents: 136
diff changeset
75
0
9305c6458e2f initial commit
Goffi <goffi@goffi.org>
parents:
diff changeset
76 def generic_cat(request, category):
78
6250b65523c6 categories' aliases can be defined to be able to use "French" links like adhesion.html
souliane <souliane@mailoo.org>
parents: 77
diff changeset
77 if category in CATEGORIES_ALIASES:
6250b65523c6 categories' aliases can be defined to be able to use "French" links like adhesion.html
souliane <souliane@mailoo.org>
parents: 77
diff changeset
78 category = CATEGORIES_ALIASES[category]
6250b65523c6 categories' aliases can be defined to be able to use "French" links like adhesion.html
souliane <souliane@mailoo.org>
parents: 77
diff changeset
79
34
9d553570cc61 add adhesion_form.html and thank_you.html
souliane <souliane@mailoo.org>
parents: 33
diff changeset
80 context = RequestContext(request, {
2
0df46e87537d i18n: marked translatable texts + add change language form on pages footer
Goffi <goffi@goffi.org>
parents: 1
diff changeset
81 "available_languages": ['fr', 'en'],
0df46e87537d i18n: marked translatable texts + add change language form on pages footer
Goffi <goffi@goffi.org>
parents: 1
diff changeset
82 "categories": CATEGORIES,
27
eda4deefecd1 reorganisation of the menu using submenus
souliane <souliane@mailoo.org>
parents: 4
diff changeset
83 "categories_right": CATEGORIES_RIGHT,
1
a49aa1b823f6 added SàT archive download link (detect the last version)
Goffi <goffi@goffi.org>
parents: 0
diff changeset
84 "category": category,
33
73c6333fd124 change overview.html, move the previous content to principles.html
souliane <souliane@mailoo.org>
parents: 29
diff changeset
85 "libervia_demo_url": utils.get_libervia_demo_url(),
73c6333fd124 change overview.html, move the previous content to principles.html
souliane <souliane@mailoo.org>
parents: 29
diff changeset
86 "subscription_amounts": utils.get_asso_subscr_amounts(),
34
9d553570cc61 add adhesion_form.html and thank_you.html
souliane <souliane@mailoo.org>
parents: 33
diff changeset
87 })
27
eda4deefecd1 reorganisation of the menu using submenus
souliane <souliane@mailoo.org>
parents: 4
diff changeset
88
2
0df46e87537d i18n: marked translatable texts + add change language form on pages footer
Goffi <goffi@goffi.org>
parents: 1
diff changeset
89 context.update(csrf(request))
71
a14845624e01 display a banner on top of all pages (but adhesion, adhesion_form and thank_you) to encourage people joining the association
souliane <souliane@mailoo.org>
parents: 57
diff changeset
90 context.update(utils.get_asso_finance_status())
2
0df46e87537d i18n: marked translatable texts + add change language form on pages footer
Goffi <goffi@goffi.org>
parents: 1
diff changeset
91
0
9305c6458e2f initial commit
Goffi <goffi@goffi.org>
parents:
diff changeset
92 if not category or category == "overview":
33
73c6333fd124 change overview.html, move the previous content to principles.html
souliane <souliane@mailoo.org>
parents: 29
diff changeset
93 context.update(utils.get_asso_finance_status())
0
9305c6458e2f initial commit
Goffi <goffi@goffi.org>
parents:
diff changeset
94 return render_to_response('sat_website/overview.html', context)
89
4b4a5d7602f8 rename screenshots to media, since not only screenshots but also videos are listed
souliane <souliane@mailoo.org>
parents: 78
diff changeset
95 elif category == "media":
4b4a5d7602f8 rename screenshots to media, since not only screenshots but also videos are listed
souliane <souliane@mailoo.org>
parents: 78
diff changeset
96 context["media"] = media.media
4b4a5d7602f8 rename screenshots to media, since not only screenshots but also videos are listed
souliane <souliane@mailoo.org>
parents: 78
diff changeset
97 context["media_tech"] = media.media_tech
0
9305c6458e2f initial commit
Goffi <goffi@goffi.org>
parents:
diff changeset
98 elif category == "social_contract":
9305c6458e2f initial commit
Goffi <goffi@goffi.org>
parents:
diff changeset
99 context["SOCIAL_CONTRACT"] = social_contract.get_social_contract()
33
73c6333fd124 change overview.html, move the previous content to principles.html
souliane <souliane@mailoo.org>
parents: 29
diff changeset
100 elif category == "downloads":
39
d2c45f4ba57e add downloads.html
souliane <souliane@mailoo.org>
parents: 34
diff changeset
101 context["projects_infos"] = utils.get_projects_infos(PROJECTS_INFOS)
77
13ebb548f234 use membership instead of adhesion in English (also rename the files)
souliane <souliane@mailoo.org>
parents: 76
diff changeset
102 elif category in ("association", "membership"):
40
dfe7139dae0a add links to the statutes and rules of the association in the adhesion form
souliane <souliane@mailoo.org>
parents: 39
diff changeset
103 context.update(utils.get_asso_urls())
77
13ebb548f234 use membership instead of adhesion in English (also rename the files)
souliane <souliane@mailoo.org>
parents: 76
diff changeset
104 elif category == "membership_form":
34
9d553570cc61 add adhesion_form.html and thank_you.html
souliane <souliane@mailoo.org>
parents: 33
diff changeset
105 if request.method == 'POST':
9d553570cc61 add adhesion_form.html and thank_you.html
souliane <souliane@mailoo.org>
parents: 33
diff changeset
106 form = forms.RegistrationForm(request.POST)
40
dfe7139dae0a add links to the statutes and rules of the association in the adhesion form
souliane <souliane@mailoo.org>
parents: 39
diff changeset
107 form.process_submitted_data()
34
9d553570cc61 add adhesion_form.html and thank_you.html
souliane <souliane@mailoo.org>
parents: 33
diff changeset
108 if form.is_valid():
9d553570cc61 add adhesion_form.html and thank_you.html
souliane <souliane@mailoo.org>
parents: 33
diff changeset
109 category = 'thank_you'
9d553570cc61 add adhesion_form.html and thank_you.html
souliane <souliane@mailoo.org>
parents: 33
diff changeset
110 else:
9d553570cc61 add adhesion_form.html and thank_you.html
souliane <souliane@mailoo.org>
parents: 33
diff changeset
111 form = forms.RegistrationForm(initial={'subscription_amount': 10,
74
651c4049f32b rename "Newsletter" to "Mailing list" in the adhesion form
souliane <souliane@mailoo.org>
parents: 71
diff changeset
112 'mailing': True})
34
9d553570cc61 add adhesion_form.html and thank_you.html
souliane <souliane@mailoo.org>
parents: 33
diff changeset
113 context['form'] = form
40
dfe7139dae0a add links to the statutes and rules of the association in the adhesion form
souliane <souliane@mailoo.org>
parents: 39
diff changeset
114 context.update(utils.get_asso_urls())
27
eda4deefecd1 reorganisation of the menu using submenus
souliane <souliane@mailoo.org>
parents: 4
diff changeset
115
eda4deefecd1 reorganisation of the menu using submenus
souliane <souliane@mailoo.org>
parents: 4
diff changeset
116 def all_keys(cats):
eda4deefecd1 reorganisation of the menu using submenus
souliane <souliane@mailoo.org>
parents: 4
diff changeset
117 subcats = [value[1].keys() for value in cats.values() if isinstance(value, tuple)]
eda4deefecd1 reorganisation of the menu using submenus
souliane <souliane@mailoo.org>
parents: 4
diff changeset
118 return sum(subcats, cats.keys())
eda4deefecd1 reorganisation of the menu using submenus
souliane <souliane@mailoo.org>
parents: 4
diff changeset
119
34
9d553570cc61 add adhesion_form.html and thank_you.html
souliane <souliane@mailoo.org>
parents: 33
diff changeset
120 if category in all_keys(CATEGORIES) or category in all_keys(CATEGORIES_RIGHT) or category in CATEGORIES_HIDDEN:
0
9305c6458e2f initial commit
Goffi <goffi@goffi.org>
parents:
diff changeset
121 return render_to_response('sat_website/%s.html' % (category,), context)
9305c6458e2f initial commit
Goffi <goffi@goffi.org>
parents:
diff changeset
122 else:
9305c6458e2f initial commit
Goffi <goffi@goffi.org>
parents:
diff changeset
123 raise Http404
138
2ec5653b190a add url "whereami" to get the client IP address
souliane <souliane@mailoo.org>
parents: 136
diff changeset
124
2ec5653b190a add url "whereami" to get the client IP address
souliane <souliane@mailoo.org>
parents: 136
diff changeset
125
2ec5653b190a add url "whereami" to get the client IP address
souliane <souliane@mailoo.org>
parents: 136
diff changeset
126 def whereami(request):
2ec5653b190a add url "whereami" to get the client IP address
souliane <souliane@mailoo.org>
parents: 136
diff changeset
127 """Return the client IP address"""
2ec5653b190a add url "whereami" to get the client IP address
souliane <souliane@mailoo.org>
parents: 136
diff changeset
128 x_forwarded_for = request.META.get('HTTP_X_FORWARDED_FOR')
2ec5653b190a add url "whereami" to get the client IP address
souliane <souliane@mailoo.org>
parents: 136
diff changeset
129 if x_forwarded_for:
2ec5653b190a add url "whereami" to get the client IP address
souliane <souliane@mailoo.org>
parents: 136
diff changeset
130 ip = x_forwarded_for.split(',')[0]
2ec5653b190a add url "whereami" to get the client IP address
souliane <souliane@mailoo.org>
parents: 136
diff changeset
131 else:
2ec5653b190a add url "whereami" to get the client IP address
souliane <souliane@mailoo.org>
parents: 136
diff changeset
132 ip = request.META.get('REMOTE_ADDR')
2ec5653b190a add url "whereami" to get the client IP address
souliane <souliane@mailoo.org>
parents: 136
diff changeset
133 return HttpResponse(ip)