Mercurial > sat_legacy_website
comparison sat_website/views/category.py @ 150:b101828faa0e
split views.py in sub-modules
author | souliane <souliane@mailoo.org> |
---|---|
date | Tue, 17 Oct 2017 22:16:20 +0200 |
parents | sat_website/views.py@b1c16cd53b62 |
children | d9adc73fcd12 |
comparison
equal
deleted
inserted
replaced
149:b1c16cd53b62 | 150:b101828faa0e |
---|---|
1 # -*- coding: utf-8 -*- | |
2 """ | |
3 SàT website: Salut à Toi's presentation website | |
4 Copyright (C) 2012 Jérôme Poisson (goffi@goffi.org) | |
5 | |
6 This file is part of SàT website. | |
7 | |
8 SàT website is free software: you can redistribute it and/or modify | |
9 it under the terms of the GNU Affero General Public License as published by | |
10 the Free Software Foundation, either version 3 of the License, or | |
11 (at your option) any later version. | |
12 | |
13 Foobar is distributed in the hope that it will be useful, | |
14 but WITHOUT ANY WARRANTY; without even the implied warranty of | |
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
16 GNU Affero General Public License for more details. | |
17 | |
18 You should have received a copy of the GNU Affero General Public License | |
19 along with SàT website. If not, see <http://www.gnu.org/licenses/>. | |
20 """ | |
21 | |
22 from collections import OrderedDict | |
23 | |
24 from django.http import Http404 | |
25 from django.views.generic.base import View | |
26 from django.shortcuts import render_to_response | |
27 from django.template.context_processors import csrf | |
28 from django.utils.translation import ugettext_lazy as _ | |
29 | |
30 from sat_website import utils, media, social_contract, forms | |
31 | |
32 | |
33 CATEGORIES = OrderedDict([('frontends', (_(u"Presentation"), | |
34 OrderedDict([("features", _(u"Features")), | |
35 ("frontends", _(u"Frontends")), | |
36 ("media", _(u"Screenshots & Videos")), | |
37 ("news", _(u"News")), | |
38 ]))), | |
39 ('principles', (_(u"Technical area"), | |
40 OrderedDict([("principles", _(u"Principles")), | |
41 ("specifications", _(u"Specifications")), | |
42 ("downloads", _(u"Downloads")), | |
43 ("developers", _(u"Developers corner")), | |
44 ]))), | |
45 ('community', (_(u"Community"), | |
46 OrderedDict([("community", _(u"Get in touch")), | |
47 ("association", _(u"Association")), | |
48 ("links", _(u"Links")), | |
49 ("press", _(u"Press")), | |
50 ("faq", _(u"FAQ")), | |
51 ]))), | |
52 ]) | |
53 | |
54 CATEGORIES_RIGHT = OrderedDict([("membership", _(u"Membership")), | |
55 ("social_contract", _(u"Social contract")), | |
56 ]) | |
57 | |
58 CATEGORIES_ALIASES = {"adhesion": "membership", | |
59 "adhesion_form": "membership_form", | |
60 "screenshots": "media", | |
61 } | |
62 | |
63 CATEGORIES_HIDDEN = ('membership_form', 'thank_you') | |
64 | |
65 PROJECTS_INFOS = {'sat': _(u'contains the backend, Primitivus and Jp'), | |
66 'sat_media': _(u'Images and other media needed to launch SàT'), | |
67 'urwid_satext': _(u'console display library needed by Primitivus'), | |
68 'sat_pubsub': _(u'PubSub server component needed for SàT experimental blogging features'), | |
69 'libervia': _(u'Libervia frontend (web server and client)'), | |
70 } | |
71 | |
72 | |
73 class CategoryView(View): | |
74 | |
75 @staticmethod | |
76 def all_keys(cats): | |
77 subcats = [value[1].keys() for value in cats.values() if isinstance(value, tuple)] | |
78 return sum(subcats, cats.keys()) | |
79 | |
80 def get(self, request, category): | |
81 if category in CATEGORIES_ALIASES: | |
82 category = CATEGORIES_ALIASES[category] | |
83 | |
84 context = { | |
85 "available_languages": ['fr', 'en'], | |
86 "categories": CATEGORIES, | |
87 "categories_right": CATEGORIES_RIGHT, | |
88 "category": category, | |
89 "libervia_demo_url": utils.get_libervia_demo_url(), | |
90 "subscription_amounts": utils.get_asso_subscr_amounts(), | |
91 } | |
92 | |
93 context.update(csrf(request)) | |
94 context.update(utils.get_asso_finance_status()) | |
95 | |
96 if not category or category == "overview": | |
97 context.update(utils.get_asso_finance_status()) | |
98 return render_to_response('sat_website/overview.html', context) | |
99 elif category == "media": | |
100 context["media"] = media.media | |
101 context["media_tech"] = media.media_tech | |
102 elif category == "social_contract": | |
103 context["SOCIAL_CONTRACT"] = social_contract.get_social_contract() | |
104 elif category == "downloads": | |
105 context["projects_infos"] = utils.get_projects_infos(PROJECTS_INFOS) | |
106 elif category in ("association", "membership"): | |
107 context.update(utils.get_asso_urls()) | |
108 elif category == "membership_form": | |
109 if request.method == 'POST': | |
110 form = forms.RegistrationForm(request.POST) | |
111 form.process_submitted_data() | |
112 if form.is_valid(): | |
113 category = 'thank_you' | |
114 else: | |
115 form = forms.RegistrationForm(initial={'subscription_amount': 10, | |
116 'mailing': True}) | |
117 context['form'] = form | |
118 context.update(utils.get_asso_urls()) | |
119 | |
120 if ( | |
121 category in self.all_keys(CATEGORIES) or | |
122 category in self.all_keys(CATEGORIES_RIGHT) or | |
123 category in CATEGORIES_HIDDEN | |
124 ): | |
125 return render_to_response('sat_website/%s.html' % (category,), context) | |
126 else: | |
127 raise Http404 |