Example #1
0
def add_event(request):
    c = {}
    c.update(csrf(request)) 
    if request.method == 'POST':
        event_data = {'event_type' : request.POST['event_type'],
                      'title' : request.POST['title'],
                      'event_datetime' : request.POST['event_datetime'],
                      'location' :  request.POST['location'],
                      'url' : request.POST['url'],
                      'details' : request.POST['details'],
                      'posted_by' : request.POST['posted_by'],}    
        event = EventForm(event_data,auto_id=True)
        if event.is_valid():          
            event.save()
            return redirect('/event/add/complete/')         
        else:           
            event.error = "Event did not validate."       
            return render_to_response('poly_assoc_website/event_add.html', {'form' : event }, RequestContext(request))
         
 
    if request.method == 'GET':
        event = EventForm(auto_id=True)       
        try:
            return render_to_response('poly_assoc_website/event_add.html', {'form' : event }, RequestContext(request))
        except TemplateDoesNotExist:
            raise Http404() 
Example #2
0
def event_edit(request, event_id):
    c = {}
    c.update(csrf(request))   
    event = Event.objects.get(id=event_id)
    user = event.posted_by
    if request.method == 'GET':       
        form = EventForm(instance=event)
        try:
            return render_to_response('poly_assoc_website/event_edit.html', {'form' : form,}, RequestContext(request))
        except TemplateDoesNotExist:
            raise Http404()
    if request.method == 'POST':
        form = EventForm(request.POST,instance=event)
        if form.is_valid():
            form.save()
            return redirect('/my-items/%d/' % event.posted_by.id)
        else:
            form.error = "Event did not validate. Maybe some field are missing"
            return render_to_response('poly_assoc_website/event_edit.html', {'form' : form }, RequestContext(request))