new file: projetCuf/__init__.py
[univ_ap.git] / cartographie / views.py
1 #-*- coding: utf-8 -*-
2 # Create your views here.
3 from datetime import datetime
4 from django.shortcuts import render, get_object_or_404
5 from django.http import Http404, HttpResponse
6 from django.shortcuts import redirect
7 from django.core import serializers
8 from cartographie.forms import SearchFormationForm, EditFormationForm
9 from basemodel.models import Contenu, Formation, Pays, Etablissement
10 from cartographie.models import Cartonews, CartoFormation
11 #def index(request):
12 #return render(request,'cartographie/index.html', locals())
13
14 def asie_pacifique():
15 return Pays.objects.filter(asie_pacifique = 1)
16
17 def cartonews():
18 return Cartonews.objects.filter(statut='Publié')
19 def focusnews():
20 return Cartonews.objects.filter(statut='Publié',focus=1)[0:3]
21 def index(request):
22 pays_asie_pacifique = asie_pacifique()
23 #lastnews = last_news()
24 focus = focusnews()
25 if request.method == 'POST': # S'il s'agit d'une requête POST
26 form = SearchFormationForm(request.POST) # Nous reprenons les données
27 if form.is_valid():
28 pays = form.cleaned_data['pays']
29 etablissement = form.cleaned_data['etablissement']
30 dixipline = form.cleaned_data['dixipline']
31 niveau = form.cleaned_data['niveau_formation']
32 # Nous vérifions que les données envoyées sont valides
33 #list_formation = Formation.objects.filter(pays = pays)
34
35 else: # Si ce n'est pas du POST, c'est probablement une requête GET
36 form = SearchFormationForm() # Nous créons un formulaire video
37 return render(request,'cartographie/index.html', locals())
38
39 def formation_details(request,idformation):
40 pays_asie_pacifique= asie_pacifique()
41 #lastnews = last_news()
42 focus = focusnews()
43 try:
44 formation_pdf = CartoFormation.objects.get(carto_id = idformation)
45
46 except:
47 idformation11 = idformation
48 pass
49
50 return render(request,'cartographie/details_formation.html', locals())
51
52 def news(request,slug):
53 #pays_asie_pacifique= asie_pacifique()
54 lastnews = cartonews()
55
56 focus = focusnews()
57
58 if (not slug):
59 focus1 = Cartonews.objects.filter(statut='Publié',focus=1)[0:1]
60 slug = focus1[0].slug
61
62 titre_news = "Formations infos"
63 try:
64 thenew = Cartonews.objects.get(slug = slug)
65 except Cartonews.DoesNotExist:
66 #return redirect('cartographie.views.index')
67 pass
68 return render(request,'cartographie/view_news.html', locals())
69
70 def edit_formation(request,uuid):
71 if request.method == 'POST':
72
73 f = CartoFormation.objects.filter(uuid=uuid)
74 form = EditFormationForm(request.POST, instance=f)
75 if form.is_valid():
76 formation = form.save()
77 saveok = True
78
79 else:
80 #formation = get_object_or_404(CartoFormation, pk=1)
81 formationlist = CartoFormation.objects.filter(uuid=uuid)
82 formation = formationlist[0]
83 form = EditFormationForm(instance=formation)
84
85
86 return render(request,'cartographie/editformation.html', locals())
87
88 def liste_formation(request):
89 liste_form = CartoFormation.objects.order_by('etablissement')
90
91 return render(request,'cartographie/liste_formation.html', locals())
92
93 def formation_details_mobile(request,idformation):
94 pays_asie_pacifique = asie_pacifique()
95 #lastnews = last_news()
96 try:
97 formation_pdf = CartoFormation.objects.get(carto_id = idformation)
98
99 except:
100 idformation11 = idformation
101 pass
102
103 return render(request,'cartographie/details_formation_mobile.html', locals())
104
105 def get_etab_par_pays(request, code_pays):
106 liste_etab = Etablissement.objects.all()
107 if (code_pays <> ''):
108 #pays = Pays.objects.filter(code='VNM')
109 #liste_etab = Etablissement.objects.raw('Select id,code,nom from basemodel_etablissement where pays_id=' + pays.pk)
110 liste_etab = Etablissement.objects.filter(pays__code=code_pays)
111
112 data = serializers.serialize("json", liste_etab)
113 return HttpResponse(data, content_type='application/json')
114
115