from django.core import serializers
from django.http import HttpResponse
from django.shortcuts import render_to_response
from django.template import RequestContext

from models import Plot, Actor, Event

def add_actor(request):
    actors = []
    if request.method == 'POST':
        name = request.POST.get('name', None)
        if name:
            # TODO: multiple plots per user (select from list and ut in session)
            plot = Plot.objects.get(owners=request.user)
            actor = Actor(name=name, plot=plot)
            actor.save()
            actors.append(actor)
    return render_to_response('list-actors.html', {
            'actors': actors,
        }, context_instance=RequestContext(request))

def delete_actor(request):
    rtn = None
    if request.method == 'POST':
        try:
            actor = Actor.objects.get(id=request.POST.get('id', None))
            actor.delete()
            rtn = 'true'
        except Actor.DoesNotExist:
            pass
    return HttpResponse(rtn) 

def list_actors(request):
    # TODO: multiple plots per user (select from list and ut in session)
    actors = Actor.objects.filter(plot__owners=request.user).order_by('-id')
    return render_to_response('list.html', {
            'actors': actors,
        }, context_instance=RequestContext(request))

def list_events(request, id=None):
    events = Event.objects.filter(actor=id)
    return render_to_response('list-events.html', {
            'events': events,
        }, context_instance=RequestContext(request))
    

@@ -337,89 +337,8 @@
 me:%0A
-            # TODO: multiple plots per user (select from list and ut in session)%0A
     
@@ -663,19 +663,18 @@
 t):%0A    
-rtn
+id
  = None%0A
@@ -735,37 +735,13 @@
     
-actor = Actor.objects.get(id=
+id = 
 requ
@@ -764,17 +764,16 @@
 ', None)
-)
 %0A       
@@ -781,47 +781,41 @@
     
-a
+A
 ctor.
-delete()%0A            rtn = 'true'
+objects.get(id=id).delete()
 %0A   
@@ -891,11 +891,10 @@
 nse(
-rtn
+id
 ) %0A%0A
@@ -923,81 +923,8 @@
 t):%0A
-    # TODO: multiple plots per user (select from list and ut in session)%0A
     
@@ -1121,24 +1121,285 @@
 (request))%0A%0A
+def delete_event(request):%0A    id = None%0A    if request.method == 'POST':%0A        try:%0A            id = request.POST.get('id', None)%0A            Event.objects.get(id=id).delete()%0A        except Event.DoesNotExist:%0A            pass%0A    return HttpResponse(id) %0A%0A
 def list_eve

delete event