Пример #1
0
def index(request):
    latest_article_list = Article.objects.all().order_by('-post_date')[:5]
    form = ArticleForm()
    template = loader.get_template('index.html')
    # user = User.objects.get(pk=User.pk)
    if request.user.is_active:
    # if user is not None:
        
        return render_to_response('index.html', { 'form': form, 'posts': latest_article_list })
    elif request.user.is_active != False and latest_article_list is not None:
        return render_to_response('index.html', { 'posts': latest_article_list })
        
    else:
        return render_to_response('index.html', {  }, context_instance=RequestContext(request))
        
    if request.method == 'POST':
        if form.is_valid():
            postedArticle = Article()
            postedArticle.post_date = timezone.now()
            postedArticle.title = request.POST.getlist('title')
            postedArticle.article = request.POST.getlist('article')
            postedArticle.save()
        else:
            form = ArticleForm(instance=article)
    return render_to_response('index.html', { 'form': form, 'posts': latest_article_list }, context_instance=RequestContext(request))
Пример #2
0
def article_post(request):
    if request.method == 'POST':
        form = ArticleForm(request.POST, )
        if form.is_valid():
            postedArticle = Article()
            postedArticle.post_date = timezone.now()
            postedArticle.title = request.POST.getlist('title')
            postedArticle.article = request.POST.getlist('article')
            postedArticle.save()
    
            # return redirect('index')
    else:
        form = ArticleForm(instance=article)
        
    return render_to_response('post_article.html', dict(form=form), context_instance=RequestContext(request))