Exemplo n.º 1
0
def edit(request, commute_id):
    
    
    commute = Commute.objects.get(id = commute_id)
    form = CommuteForm(instance = commute)
    
    if request.method == 'POST':
        
        # if the user has pressed the delete button
        if request.POST.has_key('delete'):
            # redirect to the delete confirmation
            return HttpResponseRedirect(reverse('commute-delete', args = [commute.id]))

        form = CommuteForm(request.POST, instance = commute)
        if form.is_valid():

            form.instance.user = request.user
            form.instance.box = fromstr(request.POST['box'])
            form.save()
            messages.success(request, 'Commute edited.')
            return HttpResponseRedirect(reverse('index'))
        

    
    return render_to_response('commute-new.html', locals(), context_instance = RequestContext(request))
Exemplo n.º 2
0
def new(request):
    
    user = request.user
    data = {}
    
    if request.method == 'POST':
        form = CommuteForm(request.POST)
        if form.is_valid():

            form.instance.user = request.user
            form.instance.box = fromstr(request.POST['box'])
            form.save()
            messages.success(request, 'Commute created.')
            return HttpResponseRedirect(reverse('index'))
        data['form'] = form
    else:
        data['form'] = CommuteForm()
    
    return render_to_response('commute-new.html', data, context_instance = RequestContext(request))