Пример #1
0
def add(request, app_label, model_name, id):
    '''add a point to a content_object

    POST the point and the zoom.  The owner is request.user and the related
    obj is received from the url.
    '''
    try:
        ct = ContentType.objects.get(\
                app_label = app_label,
                model = model_name)
        obj = ct.get_object_for_this_type( id=id )

    except:
        return HttpResponseNotFound()

    if request.method == 'POST':
        request.POST.update( {'owner':request.user.id, 'object_id':id,\
                'content_type':ct.id, 'content_obj':obj,} )
        form = GeomForm(request.POST)

        if form.is_valid():
            form.save()

            #try:
            #    return HttpResponseRedirect(request.META['HTTP_REFERER'])

            #except:

            try:
                return HttpResponseRedirect(obj.get_absolute_url())

            except:
                return HttpResponseRedirect(reverse('geoms_list'))

    else:
        form = GeomForm()

    context = {'form':form, 'object':obj, 'content_type':ct, }
    context.update(locals())

    return render_to_response('geoms/add.html', context,\
            context_instance = RequestContext(request))
Пример #2
0
def change(request, id):
    ''' Change the data for a single Geom() obj '''

    try:
        point = Geom.objects.get(id=id)
    except:
        return HttpResponseNotFound()

    if request.method == 'POST' and point.owner == request.user:

        form = GeomForm(request.POST, instance=point)

        if form.is_valid():
            form.save()
            return HttpResponseRedirect(point.get_absolute_url())

    elif point.owner == request.user:
        form = GeomForm( instance=point)
        context = {'point':point, 'form':form, }
        return render_to_response('geoms/change.html', context,\
                context_instance=RequestContext(request) )

    else:
        return HttpResponseNotFound()