Commits

Anonymous committed 95f3f38

Les vues génériques intégrées

  • Participants
  • Parent commits cdfda60

Comments (0)

Files changed (4)

personal_calendar/templates/personal_calendar/evenement_confirm_delete.html

+<p>Êtes-vous certain de vouloir supprimer l'évennement {{object.nom}} ? </p>
+
+<form method="POST" action="">
+{% csrf_token %}
+<input type="submit" value="Oui" /></li>
+</form>
+<a href="{{ object.get_absolute_url }}">Non</a>
+

personal_calendar/templates/personal_calendar/evenement_detail.html

 {% endfor %}
 </div>
 {% include "personal_calendar/blocks/participant_form.html" %}
-{% with delete_url=object.delete_url %}
-{% include "personal_calendar/blocks/delete_form.html" %}
-{% endwith %}
+<a href="{% url delete pk=object.pk %}">Supprimer cet évennement</a>
+
 {% endblock content %}

personal_calendar/urls.py

 from django.conf.urls.defaults import patterns, include, url
 from models import Evenement
 from forms import EventForm
-from views import delete, update, delete_participant, Evenement_Liste, Evenement_Detail
-from django.views.generic.edit import CreateView
+from views import delete_participant, Evenement_Liste, Evenement_Detail
+from django.core.urlresolvers import reverse_lazy
+from django.views.generic.edit import CreateView, UpdateView, DeleteView
 
 
 urlpatterns = patterns('',
-    url(r'^create/$', CreateView.as_view(model=Evenement, form_class=EventForm)),
+    url(r'^create/$', CreateView.as_view(
+            model=Evenement,
+            form_class=EventForm)
+        name='create'),
     url(r'^(?P<pk>\d+)/detail/$', Evenement_Detail.as_view(), name='details'),
-    url(r'^liste/$', Evenement_Liste.as_view(paginate_by=1)),
+    url(r'^liste/$', Evenement_Liste.as_view(paginate_by=10), name='liste'),
     url(r'^liste/(?P<champ>[\w-]+)/(?P<terme>[\w-]+)/$',Evenement_Liste.as_view(
-            paginate_by=10
+            paginate_by=10, name='liste_filtre'
             )
         ),
-    url(r'^(\d+)/delete/$', delete),
+    url(r'^(?P<pk>\d+)/delete/$', DeleteView.as_view(
+            model=Evenement,
+            success_url=reverse_lazy('liste')
+            ),
+        name='delete'
+        ),
     url(r'^(\d+)/participant/(\d+)/delete/$', delete_participant),
-    url(r'^(\d+)/update/$', update),
+    url(r'^(?P<pk>\d+)/update/$', UpdateView.as_view(
+            model=Evenement,
+            form_class=EventForm),
+        name='modifier'),
     )

personal_calendar/views.py

 from django.shortcuts import render, HttpResponseRedirect, render_to_response
 from django.http import HttpResponse
 from django.contrib.auth.models import User
-from django.forms import HiddenInput
 import json
 from django.template.loader import render_to_string
 from django.template import RequestContext
                         'event':form.instance.evenement,
                         'form':form})
 
-def delete_participant(request, id, participant):
-    if request.method == "POST":
-        evenement = Evenement.objects.get(pk = id)
-        participant = User.objects.get(pk = participant)
-        a_supprimer = Evenement_Participant.objects.get(
-                      evenement = evenement,
-                      participant = participant
-                      )
-        a_supprimer.delete()
-        if request.is_ajax():
-            return HttpResponse("OK")
-    return HttpResponseRedirect('/agenda/%s/details/' % id)
-
-def delete(request, id):
-    if request.method == "POST":
-        evenement = Evenement.objects.get(pk = id)
-        evenement.delete()
-    return HttpResponseRedirect('/agenda/liste/')
-
-def update(request, id):
-    event = Evenement.objects.get(pk = id)
-    if request.method == "POST":
-        print request.POST
-        form = EventForm(request.POST, instance=event)
-        if form.is_valid():
-            a = form.save()
-            return HttpResponseRedirect('/agenda/%i/details/' % a.pk)
-    else:
-        form = EventForm(instance = event)
-    return render(request,'personal_calendar/event/create.html',{'form':form})
-
 class Evenement_Liste(ListView):
     def get_queryset(self):
         events = Evenement.objects.filter(
                  )
                 )
         return events
+
+def delete_participant(request, id, participant):
+    if request.method == "POST":
+        evenement = Evenement.objects.get(pk = id)
+        participant = User.objects.get(pk = participant)
+        a_supprimer = Evenement_Participant.objects.get(
+                      evenement = evenement,
+                      participant = participant
+                      )
+        a_supprimer.delete()
+        if request.is_ajax():
+            return HttpResponse("OK")
+    return HttpResponseRedirect('/agenda/%s/details/' % id)