Exemple #1
0
def sp(request, id='1'):
    if request.method == "POST":
        text = request.POST['text']
        user = User.objects.get(username=request.user)
        nn = get_object_or_404(News, id=id)
        nc = Comment()
        nc.owner = user
        nc.text = text
        nc.news = nn
        nc.save()
        return redirect(request.path)
    from_date = datetime.datetime.now() - datetime.timedelta(days=2)
    l2dn = News.objects.all().order_by('-date').filter(date__range=[from_date, datetime.datetime.now()])
    ln = News.objects.all()[:5]
    ct = City.objects.all()
    n = get_object_or_404(News, id=id)
    c = Categoryitem.objects.select_related().filter(parent=None)
    com = Comment.objects.select_related().filter(news=n, parent=None)
    context = {'news': n,
               'cats': c,
               'citys': ct,
               'comments': com,
               'lnews': ln,
               'last_news': l2dn}
    return render(request, 'news/sp.html', context)
Exemple #2
0
def addcomment(request):
    if request.method == "POST":
        news = News.objects.get(id=request.POST['news'])
        text = request.POST['text']
        user = User.objects.get(username=request.user)
        c = Comment()
        c.news = news
        c.owner = user
        c.text = text
        if request.POST['pid'] != 'false':
            pid = request.POST['pid']
            c.parent = Comment.objects.get(id=pid)
        c.save()
        return HttpResponse(c.id)