cms: ajout de plugins manquant
[auf_framonde.git] / project / framonde / views.py
CommitLineData
01b54c21 1# -*- encoding: utf-8 -*
01b54c21
MN
2from django.shortcuts import render_to_response, get_object_or_404, get_list_or_404
3from django.template import Context, RequestContext
4from django.shortcuts import redirect
5from django.http import HttpResponse
6from django.core.paginator import Paginator
7from django.core.mail import send_mail
8from django.core.mail import EmailMultiAlternatives
9
6837e829
PH
10from .models import *
11
12# ACCUEIL
13
14
01b54c21 15def accueil(request):
6837e829
PH
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]
01b54c21 20 offre_list = Offre.objects.filter(status=3).order_by('-date_pub')[:2]
6837e829
PH
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
01b54c21 26
01b54c21
MN
27def Comm(request):
28 comm_list = Communication.objects.filter(status=3).order_by('-date_pub')
6837e829
PH
29 return render_to_response('pageCom.html', {
30 'comm_list': comm_list, 'page_title': 'Appel à communication'}, context_instance=RequestContext(request))
31
01b54c21
MN
32
33def Contri(request):
34 contri_list = Contribution.objects.filter(status=3).order_by('-date_pub')
6837e829
PH
35 return render_to_response('pageContri.html', {
36 'contri_list': contri_list, 'page_title': 'Appel à contribution'}, context_instance=RequestContext(request))
37
01b54c21
MN
38
39def Offres(request):
40 offre_list = Offre.objects.filter(status=3).order_by('-date_pub')
6837e829
PH
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
01b54c21 46
01b54c21
MN
47def Comm_detail(request, slug):
48 p = get_object_or_404(Communication, slug=slug)
6837e829
PH
49 return render_to_response('detail.html', {
50 'item': p, 'page_title': 'Appel à communication'}, context_instance=RequestContext(request))
51
01b54c21
MN
52
53def Contri_detail(request, slug):
54 p = get_object_or_404(Contribution, slug=slug)
6837e829
PH
55 return render_to_response('detail.html', {
56 'item': p, 'page_title': 'Appel à contribution'}, context_instance=RequestContext(request))
57
01b54c21
MN
58
59def Offre_detail(request, slug):
60 p = get_object_or_404(Offre, slug=slug)
6837e829
PH
61 return render_to_response('detail.html', {
62 'item': p, 'page_title': 'Appel d\'offres'}, context_instance=RequestContext(request))
63
64# ARCHIVES
65
01b54c21 66
01b54c21 67def Archives(request):
6837e829
PH
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
01b54c21
MN
72
73def Archive_detail(request, id):
74 p = get_object_or_404(Archive, id=id)
6837e829
PH
75 return render_to_response('detail_archive.html', {
76 'item': p, 'page_title': 'Archives'}, context_instance=RequestContext(request))
77
78# ABONNEMENT
79
01b54c21 80
01b54c21 81def Abonnement(request):
6837e829
PH
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
01b54c21
MN
108def Desabonnement(request):
109 if request.method == 'POST':
110 form = DesinscireForm(request.POST)
111 if form.is_valid():
6837e829
PH
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))
01b54c21
MN
120 else:
121 form = DesinscireForm()
6837e829
PH
122
123 return render_to_response('erreur-desinscription.html', {
124 'page_title': 'Désinscription', 'desabonne_form': form}, context_instance=RequestContext(request))