Ejemplo n.º 1
0
def new_useful_link(request):
    c = {}
    c.update(csrf(request))
    if request.method == 'POST':
        link = UsefulLinkForm(request.POST, auto_id=True)
        if link.is_valid():
            link.save()
        else:
            link = UsefulLinkForm(request.POST)
            link.error = 'Data format did not validate.'
            return render_to_response('poly_assoc_website/usefullink_add.html', {'form' : link }, RequestContext(request))
    else:
        link = UsefulLinkForm()
    try:
        return render_to_response('poly_assoc_website/usefullink_add.html', {'form' : link }, RequestContext(request))
    except TemplateDoesNotExist:
        raise Http404()
Ejemplo n.º 2
0
def link_edit(request, link_id):
    c = {}
    c.update(csrf(request))   
    if request.method == 'GET':
        link = UsefulLink.objects.get(id=link_id)
        form = UsefulLinkForm(instance=link)
        try:
            return render_to_response('poly_assoc_website/usefullink_edit.html',
                                      {'form' : form}, 
                                      RequestContext(request))
        except TemplateDoesNotExist:
            raise Http404()
    if request.method == 'POST':
        link = UsefulLink.objects.get(id=link_id)
        form = UsefulLinkForm(request.POST,instance=link)
        if form.is_valid():
            form.save()
            return redirect('/my-items/%d/' % link.posted_by.id)
        else:
            form.error = "Useful link did not validate. Maybe some field are missing"
            return render_to_response('poly_assoc_website/usefullink_edit.html', {'form' : form }, RequestContext(request))