Exemple #1
0
    def content_html(self):
        """直接渲染模板"""
        from Blog.models import Article
        from Comment.models import Comment

        result = ''

        if self.display_type == self.DISPLAY_HTML:  # HTML
            result = self.content
        elif self.display_type == self.DISPLAY_LATEST:  # 最新文章
            context = {
                # with_related=False 侧边栏不需要Owner和Category
                'articles':
                Article.latest_articles(with_related=False)[:15]  # 展示前15条数据
            }
            result = render_to_string('config/blocks/sidebar_articles.html',
                                      context)
        elif self.display_type == self.DISPLAY_HOT:  # 最热文章
            context = {
                'articles': Article.hot_article(with_related=False)[:15]
            }
            result = render_to_string('config/blocks/sidebar_articles.html',
                                      context)
        elif self.display_type == self.DISPLAY_COMMENT:  # 最近评论
            context = {
                'comments':
                Comment.objects.filter(status=Comment.STATUS_NORMAL).order_by(
                    '-id')[:10]  # 降序排列取前10条数据
            }
            result = render_to_string('config/blocks/sidebar_comments.html',
                                      context)
        return result
Exemple #2
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))
Exemple #3
0
def Article_Formu(request):
    article = Article()
    if request.method == 'POST':
        form = ArticleForm(request.POST, instance=article)
        if form.is_valid():
            form.save()

            envoi = True
    else:
        form = ArticleForm(request.POST, instance=article)
    return render(request, 'blog/HTML/creation_article.html', locals())
Exemple #4
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))