comparison sat_website/views.py @ 34:9d553570cc61

add adhesion_form.html and thank_you.html
author souliane <souliane@mailoo.org>
date Tue, 27 Jan 2015 08:20:30 +0100
parents 73c6333fd124
children d2c45f4ba57e
comparison
equal deleted inserted replaced
33:73c6333fd124 34:9d553570cc61
22 """ 22 """
23 from django.http import Http404 23 from django.http import Http404
24 from django.shortcuts import render_to_response 24 from django.shortcuts import render_to_response
25 from django.core.context_processors import csrf 25 from django.core.context_processors import csrf
26 from django.utils.translation import ugettext_lazy as _ 26 from django.utils.translation import ugettext_lazy as _
27 from django.template import RequestContext
27 from collections import OrderedDict 28 from collections import OrderedDict
28 import screenshots, social_contract, utils 29 import screenshots, social_contract, utils, forms
29 30
30 CATEGORIES = OrderedDict([('frontends', (_(u"Presentation"), 31 CATEGORIES = OrderedDict([('frontends', (_(u"Presentation"),
31 OrderedDict([("features", _(u"Features")), 32 OrderedDict([("features", _(u"Features")),
32 ("frontends", _(u"Frontends")), 33 ("frontends", _(u"Frontends")),
33 ("screenshots", _(u"Screenshots & Videos")), 34 ("screenshots", _(u"Screenshots & Videos")),
48 49
49 CATEGORIES_RIGHT = OrderedDict([("adhesion", _(u"Adhesion")), 50 CATEGORIES_RIGHT = OrderedDict([("adhesion", _(u"Adhesion")),
50 ("social_contract", _(u"Social contract")), 51 ("social_contract", _(u"Social contract")),
51 ]) 52 ])
52 53
54 CATEGORIES_HIDDEN = ('adhesion_form', 'thank_you')
55
53 56
54 def overview(request): 57 def overview(request):
55 return render_to_response('sat_website/overview.html') 58 return render_to_response('sat_website/overview.html')
56 59
57 def generic_cat(request, category): 60 def generic_cat(request, category):
58 context = { 61 context = RequestContext(request, {
59 "available_languages": ['fr', 'en'], 62 "available_languages": ['fr', 'en'],
60 "categories": CATEGORIES, 63 "categories": CATEGORIES,
61 "categories_right": CATEGORIES_RIGHT, 64 "categories_right": CATEGORIES_RIGHT,
62 "category": category, 65 "category": category,
63 }
64 "libervia_demo_url": utils.get_libervia_demo_url(), 66 "libervia_demo_url": utils.get_libervia_demo_url(),
65 "subscription_amounts": utils.get_asso_subscr_amounts(), 67 "subscription_amounts": utils.get_asso_subscr_amounts(),
68 })
66 69
67 context.update(csrf(request)) 70 context.update(csrf(request))
68 71
69 if not category or category == "overview": 72 if not category or category == "overview":
70 context.update(utils.get_asso_finance_status()) 73 context.update(utils.get_asso_finance_status())
77 context["SOCIAL_CONTRACT"] = social_contract.get_social_contract() 80 context["SOCIAL_CONTRACT"] = social_contract.get_social_contract()
78 elif category == "downloads": 81 elif category == "downloads":
79 latest_dl_path, latest_version = utils.get_latest_sat() 82 latest_dl_path, latest_version = utils.get_latest_sat()
80 context["latest_dl_path"] = latest_dl_path 83 context["latest_dl_path"] = latest_dl_path
81 context["latest_version"] = latest_version 84 context["latest_version"] = latest_version
85 elif category == "adhesion":
86 context.update(utils.get_asso_finance_status())
87 elif category == "adhesion_form":
88 if request.method == 'POST':
89 form = forms.RegistrationForm(request.POST)
90 if form.is_valid():
91 category = 'thank_you'
92 else:
93 form = forms.RegistrationForm(initial={'subscription_amount': 10,
94 'payment_method': 'card'})
95 context['form'] = form
82 96
83 def all_keys(cats): 97 def all_keys(cats):
84 subcats = [value[1].keys() for value in cats.values() if isinstance(value, tuple)] 98 subcats = [value[1].keys() for value in cats.values() if isinstance(value, tuple)]
85 return sum(subcats, cats.keys()) 99 return sum(subcats, cats.keys())
86 100
87 if category in all_keys(CATEGORIES) or category in all_keys(CATEGORIES_RIGHT): 101 if category in all_keys(CATEGORIES) or category in all_keys(CATEGORIES_RIGHT) or category in CATEGORIES_HIDDEN:
88 return render_to_response('sat_website/%s.html' % (category,), context) 102 return render_to_response('sat_website/%s.html' % (category,), context)
89 else: 103 else:
90 raise Http404 104 raise Http404