cms: ajout de plugins manquant
[auf_framonde.git] / project / framonde / views.py
1 # -*- encoding: utf-8 -*
2 from django.shortcuts import render_to_response, get_object_or_404, get_list_or_404
3 from django.template import Context, RequestContext
4 from django.shortcuts import redirect
5 from django.http import HttpResponse
6 from django.core.paginator import Paginator
7 from django.core.mail import send_mail
8 from django.core.mail import EmailMultiAlternatives
9
10 from .models import *
11
12 # ACCUEIL
13
14
15 def accueil(request):
16 comm_list = Communication.objects.filter(
17 status=3).order_by('-date_pub')[:2]
18 contri_list = Contribution.objects.filter(
19 status=3).order_by('-date_pub')[:2]
20 offre_list = Offre.objects.filter(status=3).order_by('-date_pub')[:2]
21 return render_to_response('accueil.html', {'comm_list': comm_list, 'contri_list': contri_list,
22 'offre_list': offre_list, 'page_title': 'Accueil'}, context_instance=RequestContext(request))
23
24 # PAGE
25
26
27 def Comm(request):
28 comm_list = Communication.objects.filter(status=3).order_by('-date_pub')
29 return render_to_response('pageCom.html', {
30 'comm_list': comm_list, 'page_title': 'Appel à communication'}, context_instance=RequestContext(request))
31
32
33 def Contri(request):
34 contri_list = Contribution.objects.filter(status=3).order_by('-date_pub')
35 return render_to_response('pageContri.html', {
36 'contri_list': contri_list, 'page_title': 'Appel à contribution'}, context_instance=RequestContext(request))
37
38
39 def Offres(request):
40 offre_list = Offre.objects.filter(status=3).order_by('-date_pub')
41 return render_to_response('pageAppel.html', {
42 'offre_list': offre_list, 'page_title': 'Appel d\'offres'}, context_instance=RequestContext(request))
43
44 # DETAIL
45
46
47 def Comm_detail(request, slug):
48 p = get_object_or_404(Communication, slug=slug)
49 return render_to_response('detail.html', {
50 'item': p, 'page_title': 'Appel à communication'}, context_instance=RequestContext(request))
51
52
53 def Contri_detail(request, slug):
54 p = get_object_or_404(Contribution, slug=slug)
55 return render_to_response('detail.html', {
56 'item': p, 'page_title': 'Appel à contribution'}, context_instance=RequestContext(request))
57
58
59 def Offre_detail(request, slug):
60 p = get_object_or_404(Offre, slug=slug)
61 return render_to_response('detail.html', {
62 'item': p, 'page_title': 'Appel d\'offres'}, context_instance=RequestContext(request))
63
64 # ARCHIVES
65
66
67 def Archives(request):
68 archives = Archive.objects.filter(status=3).order_by('-date_pub')
69 return render_to_response('archives.html', {
70 'archives_list': archives, 'page_title': 'Archives'}, context_instance=RequestContext(request))
71
72
73 def Archive_detail(request, id):
74 p = get_object_or_404(Archive, id=id)
75 return render_to_response('detail_archive.html', {
76 'item': p, 'page_title': 'Archives'}, context_instance=RequestContext(request))
77
78 # ABONNEMENT
79
80
81 def Abonnement(request):
82 if request.method == 'POST':
83 form = AbonneForm(request.POST)
84 if form.is_valid():
85 a = Abonne(adresse=form.cleaned_data['adresse'])
86 print a
87 a.save()
88 text_content = 'Votre abonnement à la liste de diffusion Framonde a été validé.'
89 html_content = '<p>Bonjour,</p><p>Votre inscription à la liste de diffusion Framonde a bien été validée.</p><p>Pour toutes informations complémentaires veuillez nous contacter : <a href="http://www.auf.org/">www.auf.org/auf_dans_le_monde</a></p><p>Merci</p>'
90 msg = EmailMultiAlternatives(
91 'Inscription à la liste de diffusion Framonde',
92 text_content,
93 'ne-pas-repondre@auf.org',
94 [
95 form.cleaned_data['adresse']])
96 msg.attach_alternative(html_content, "text/html")
97 return render_to_response('abonnement.html', {
98 'page_title': 'Confirmation inscription'}, context_instance=RequestContext(request))
99 else:
100 form = AbonneForm()
101
102 return render_to_response('erreur-inscription.html', {
103 'page_title': 'Inscription', 'abonne_form': form}, context_instance=RequestContext(request))
104
105 # desinscription
106
107
108 def Desabonnement(request):
109 if request.method == 'POST':
110 form = DesinscireForm(request.POST)
111 if form.is_valid():
112 a = Abonne.objects.get(
113 adresse=form.cleaned_data['adresse']).delete()
114 send_mail('Désinscription à la liste de diffusion Framonde',
115 'Votre abonnement à la liste de diffusion Framonde a été résilié.',
116 'webmestre@auf.org',
117 [form.cleaned_data['adresse']])
118 return render_to_response('desabonnement_confirme.html', {
119 'page_title': 'Confirmation inscription'}, context_instance=RequestContext(request))
120 else:
121 form = DesinscireForm()
122
123 return render_to_response('erreur-desinscription.html', {
124 'page_title': 'Désinscription', 'desabonne_form': form}, context_instance=RequestContext(request))