Пример #1
0
def editLink(request,tid,template_name):
    try:
        tlinks = links.objects.get(id=tid)
        if request.method == 'POST':
            form = linksForm(request.POST,instance=tlinks)
            if form.is_valid():
                form.save()
                return HttpResponseRedirect(reverse('getlinklist'))
        else:
            form = linksForm(instance=tlinks)
        vt = loader.get_template(template_name)
        c = RequestContext(
            request,
            {
                'form':form,
                'form_url':reverse('editlink',args=[tid]),
                'page_title':_('Edit Link')
            }
        )
        return HttpResponse(vt.render(c))
    except links.DoesNotExist:
        return render_to_response(
            'error.html',
                {'message':_('Link does not exist.')},
            context_instance=RequestContext(request)
        )
Пример #2
0
def addLink(request, template_name):
    if request.method == 'POST':
        form = linksForm(request.POST)
        if form.is_valid():
            form.save()
            return HttpResponseRedirect(reverse('getlinklist'))
    else:
        form = linksForm()
    vt = loader.get_template(template_name)
    c = RequestContext(
        request,
        {
            'form':form,
            'form_url':reverse('addlink'),
            'page_title':_('Add Link')
        }
    )
    return HttpResponse(vt.render(c))