Example #1
0
def add_place(request):
    if request.POST:
        form = PlaceForm(data=request.POST, files=request.FILES)
        if form.is_valid():
            form.save(user=request.user.user)
            return HttpResponseRedirect('/me/')
    else:
        form = PlaceForm()
     
    if request.GET.get('ajax'):
        tpl = 'edit_place_ajax.html'
    else:
        tpl = 'edit_place.html'
        
    return render_to_response(tpl, {
        'form': form,
        'profile': request.user.user,
    }, context_instance=RequestContext(request))
Example #2
0
def edit_place(request, id):
    'Редактирование мест'
    place = get_object_or_404(Place, pk=id, user=request.user.user)
    if request.POST:
        form = PlaceForm(data=request.POST, files=request.FILES, instance=place)
        if form.is_valid():
            form.save(user=request.user.user)
            return HttpResponseRedirect('/me/')
    else:
        form = PlaceForm(instance=place)
     
    if request.GET.get('ajax'):
        tpl = 'edit_place_ajax.html'
    else:
        tpl = 'edit_place.html'
        
    return render_to_response(tpl, {
        'form': form,
        'profile': request.user.user,
    }, context_instance=RequestContext(request))