Hello site
[auf_framonde.git] / project / framonde / views.py
CommitLineData
01b54c21
MN
1# -*- encoding: utf-8 -*
2from framonde.models import *
3from django.shortcuts import render_to_response, get_object_or_404, get_list_or_404
4from django.template import Context, RequestContext
5from django.shortcuts import redirect
6from django.http import HttpResponse
7from django.core.paginator import Paginator
8from django.core.mail import send_mail
9from django.core.mail import EmailMultiAlternatives
10
11#ACCUEIL
12def accueil(request):
13 comm_list = Communication.objects.filter(status=3).order_by('-date_pub')[:2]
14 contri_list = Contribution.objects.filter(status=3).order_by('-date_pub')[:2]
15 offre_list = Offre.objects.filter(status=3).order_by('-date_pub')[:2]
16 return render_to_response('accueil.html', {'comm_list': comm_list, 'contri_list': contri_list, 'offre_list': offre_list, 'page_title': 'Accueil'}, context_instance = RequestContext(request))
17
18#PAGE
19def Comm(request):
20 comm_list = Communication.objects.filter(status=3).order_by('-date_pub')
21 return render_to_response('pageCom.html', {'comm_list': comm_list, 'page_title': 'Appel à communication'}, context_instance = RequestContext(request))
22
23def Contri(request):
24 contri_list = Contribution.objects.filter(status=3).order_by('-date_pub')
25 return render_to_response('pageContri.html', {'contri_list': contri_list, 'page_title': 'Appel à contribution'}, context_instance = RequestContext(request))
26
27def Offres(request):
28 offre_list = Offre.objects.filter(status=3).order_by('-date_pub')
29 return render_to_response('pageAppel.html', {'offre_list': offre_list, 'page_title': 'Appel d\'offres'}, context_instance = RequestContext(request))
30
31#DETAIL
32def Comm_detail(request, slug):
33 p = get_object_or_404(Communication, slug=slug)
34 return render_to_response('detail.html', {'item': p, 'page_title': 'Appel à communication'}, context_instance = RequestContext(request))
35
36def Contri_detail(request, slug):
37 p = get_object_or_404(Contribution, slug=slug)
38 return render_to_response('detail.html', {'item': p, 'page_title': 'Appel à contribution'}, context_instance = RequestContext(request))
39
40def Offre_detail(request, slug):
41 p = get_object_or_404(Offre, slug=slug)
42 return render_to_response('detail.html', {'item': p, 'page_title': 'Appel d\'offres'}, context_instance = RequestContext(request))
43
44#ARCHIVES
45def Archives(request):
46 archives = Archive.objects.filter(status=3).order_by('-date_pub')
47 return render_to_response('archives.html', {'archives_list': archives, 'page_title': 'Archives'}, context_instance = RequestContext(request))
48
49def Archive_detail(request, id):
50 p = get_object_or_404(Archive, id=id)
51 return render_to_response('detail_archive.html', {'item': p, 'page_title': 'Archives'}, context_instance = RequestContext(request))
52
53#ABONNEMENT
54def Abonnement(request):
55 if request.method == 'POST':
56 form = AbonneForm(request.POST)
57 if form.is_valid():
58 a = Abonne(adresse = form.cleaned_data['adresse'])
59 print a
60 a.save()
61 text_content = 'Votre abonnement à la liste de diffusion Framonde a été validé.'
62 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>'
63 msg = EmailMultiAlternatives('Inscription à la liste de diffusion Framonde', text_content, 'ne-pas-repondre@auf.org', [form.cleaned_data['adresse']])
64 msg.attach_alternative(html_content, "text/html")
65 return render_to_response('abonnement.html', {'page_title': 'Confirmation inscription'}, context_instance = RequestContext(request))
66 else:
67 form = AbonneForm()
68
69 return render_to_response('erreur-inscription.html', {'page_title': 'Inscription','abonne_form': form}, context_instance = RequestContext(request))
70
71#desinscription
72def Desabonnement(request):
73 if request.method == 'POST':
74 form = DesinscireForm(request.POST)
75 if form.is_valid():
76 a = Abonne.objects.get(adresse=form.cleaned_data['adresse']).delete()
77 send_mail('Désinscription à la liste de diffusion Framonde', 'Votre abonnement à la liste de diffusion Framonde a été résilié.', 'webmestre@auf.org',[form.cleaned_data['adresse']])
78 return render_to_response('desabonnement_confirme.html', {'page_title': 'Confirmation inscription'}, context_instance = RequestContext(request))
79 else:
80 form = DesinscireForm()
81
82 return render_to_response('erreur-desinscription.html', {'page_title': 'Désinscription','desabonne_form': form}, context_instance = RequestContext(request))