Exemplo n.º 1
0
def edit_article(request,pk=0,template='user_control_panel.html'):
    data={}
    article_object= None
    try:
        article_object = Article.objects.get(id = pk)
        
        form = ArticleForm(instance=article_object)
    except:
        form = ArticleForm()
    if request.POST:
        if article_object== None:
            form = ArticleForm(request.POST)
            if form.is_valid():
                form.save()
            return HttpResponseRedirect('/home')    
        else:
            article_object = Article.objects.get(id = pk)
            form =ArticleForm(request.POST or None, instance=article_object)
            if form.is_valid():
                form.save()
            return HttpResponseRedirect('/home')
    data['article_object']=article_object
    data['form']=form
    return render_to_response('user_control_panel.html',data,context_instance=RequestContext(request))
Exemplo n.º 2
0
def add_article(request,pk=0,template='user_control_panel.html'):
    data={}
    
    form = ArticleForm()
    if request.POST:
        form = ArticleForm(request.POST or None)
        if form.is_valid():
#             form.save()
            article = form.save(commit=False)
            article.created_by = request.user
            article.save()
            msg = "Article saved successfully"
            messages.success(request, msg, fail_silently=True)
        return HttpResponseRedirect('/home/')    
    data['article_object']=article_object
    data['form']=form
    return render_to_response('user_control_panel.html',data,context_instance=RequestContext(request))
Exemplo n.º 3
0
def ajax_add_article(request,pk=0,template='ajax_article_form.html'):
    print"yeeeeeeeeeeeeeh ureeeeeeeeeeeeka"
    data={}
    
    form = ArticleForm()
    if request.POST:
        form = ArticleForm(request.POST or None)
        if form.is_valid():
#             form.save()
            article = form.save(commit=False)
            article.created_by = request.user
            article.save()
            msg = "Article saved successfully"
            messages.success(request, msg)
        return HttpResponseRedirect('/home/')    
#     data['article_object']=article_object
    data['form']=form
    return render_to_response(template,data,context_instance=RequestContext(request))