Example #1
0
def news_edit(request, news_id):
    c = {}
    c.update(csrf(request))   
    news = News.objects.get(id=news_id)
    user = news.published_by
    if request.method == 'GET':       
        #form = CustomNewsForm(instance=news)
        #try:
        return render_to_response('poly_assoc_website/news_add.html', {'form' : form,}, RequestContext(request))
        #except TemplateDoesNotExist:
        #    raise Http404()
    elif request.method == 'POST':
        form = CustomNewsForm(request.POST,instance=news)
        if form.is_valid():
            form.save()
            return redirect('/my-items/%d/' % news.published_by.id)
        else:
            form.error = "news did not validate. Maybe some field are missing"
            return render_to_response('poly_assoc_website/news_add.html', {'form' : form }, RequestContext(request))
Example #2
0
def add_news(request):    
    c = {}
    c.update(csrf(request))
    if request.method == 'POST':
        from django.template.defaultfilters import slugify
        request.POST['slug'] = slugify(request.POST['title'])
        form = CustomNewsForm(request.POST,request.FILES)
        if form.is_valid():
            form.save()
            return redirect('/news/add/complete/')
        else:
            form.error = "News did not validate. Maybe some field are missing"
            return render_to_response('poly_assoc_website/news_add.html', {'form' : form }, RequestContext(request))
    if request.method == 'GET':        
        form = CustomNewsForm(auto_id=True)
        try:
            return render_to_response('poly_assoc_website/news_add.html', {'form' : form,}, RequestContext(request))
        except TemplateDoesNotExist:
            raise Http404()