예제 #1
0
def event_detail(request, event_id):
    ''' Get and return all details for the Event with event_id = event_id.
    '''
    
    now = timezone.now()
    
    event = get_object_or_404(Event, id=event_id)    
    profile = UserProfile.objects.get(user_id=request.user.id)
    
    participants = all_info_many_profiles(event.participants.all())    
    owners = all_info_many_profiles(event.owners.all())
    comments = Comment.objects.filter(event=event_id)
    
    editform = EditEventForm(instance=event)   
    event_over = event.end_time <= now
    in_progress = event.event_time <= now and now <= event.end_time
    
    if request.method == 'POST':
        comment_form = CommentForm(request.POST)

        if comment_form.is_valid():
            note = comment_form.save(commit=False)
            note.author = profile
            note.event = event
            note.created = now
            note.save()
            return HttpResponseRedirect('/event/%d' % event.id)
    else:
        comment_form = CommentForm()
        
    context = {'event': event, 'participants': participants, 'owners': owners, 
               'editform': editform, 'comments': comments, 'comment_form': comment_form,
               'event_over': event_over, 'in_progress': in_progress}
    
    return render(request, 'app/event_detail.html', context)
예제 #2
0
def create_comment(request):
    http_referer = request.META.get('HTTP_REFERER')
    if not http_referer:
        return HttpResponseForbidden()
    if request.method == 'POST':

        form = CommentForm(request.POST)

        if form.is_valid():
            article_id = form.cleaned_data['article_id']
            path = parse.urlparse(http_referer).path
            a_id = path.split('/')[-1]
            if int(article_id) != int(a_id):
                return HttpResponseForbidden()

            anchor = request.POST.get('err_anchor', '')

            success, msg = is_valid_comment(form)
            if not success:
                return HttpResponseRedirect(
                    reverse('app:detail_article', args=(article_id,)) + '?form_error=' + msg + anchor)
            # article_meta.comment_num += 1
            # article_meta.save()
            comment = form.save()
            anchor = request.POST.get('success_anchor', '')
            anchor += str(comment.id)
            return HttpResponseRedirect(reverse('app:detail_article', args=(article_id,)) + anchor)
        else:
            anchor = request.POST.get('err_anchor', '')
            article_id = form.cleaned_data['article_id']
            return HttpResponseRedirect(
                reverse('app:detail_article', args=(article_id,)) + '?form_error=' + '验证码错误' + anchor)
예제 #3
0
def comment(request, event_id):
    ''' Create new Comment.
    '''
    
    context = RequestContext(request)
    now = timezone.now()
    event = get_object_or_404(Event, id=event_id)
    profile = UserProfile.objects.get(user_id=request.user.id)
    
    if request.method == 'POST':
        comment_form = CommentForm(request.POST)

        if comment_form.is_valid():
            note = comment_form.save(commit=False)
            note.author = profile
            note.event = event
            note.created = now
            note.save()
            return HttpResponseRedirect('/event/%d' % event.id)
    else:
        comment_form = CommentForm()
        
    return render(request, 'app/comment.html', 
                  {'event': event, 'profile': profile, 'comment_form': comment_form}
                  )
예제 #4
0
 def post(self, request, pk):
     form = CommentForm(request.POST)
     if form.is_valid():
         self.object = form.save(commit=False)
         self.object.user = get_object_or_404(User, pk=self.request.user.id)
         self.object.tweet = get_object_or_404(Tweet, pk=pk)
         self.object = form.save()
     return HttpResponseRedirect(reverse('tweet-detail', args=(pk, )))
예제 #5
0
 def post(self, request, *args, **kwargs):
     form = CommentForm(request.POST)
     if form.is_valid():
         comment = form.save()
         comment.save()
         messages = Message.objects.all()
         cache.set('messages', pickle.dumps(messages))
         return HttpResponseRedirect(reverse_lazy('app:message_list'))
     return HttpResponseRedirect(reverse_lazy('app:message_list'))
예제 #6
0
def comment_create(request, pk):
    if request.method == "POST":
        form = CommentForm(request.POST)
        if form.is_valid():
            post = Post.objects.get(id=pk)
            Comment.objects.create(created_by=request.user,
                                   post=post,
                                   **form.cleaned_data)
            return redirect(reverse_lazy("post_detail", kwargs={"pk": pk}))
예제 #7
0
def add_comment_to_post(request, pk):
    post = get_object_or_404(Post, pk=pk)
    if request.method == "POST":
        form = CommentForm(request.POST)
        if form.is_valid():
            comment = form.save(commit=False)
            comment.post = post
            comment.save()
            return redirect('post_detail', pk=post.pk)
    else:
        form = CommentForm()
    return render(request, 'blog/comment_form.html', {'form': form})
예제 #8
0
def create_comment_view(request):
    if request.method == 'POST':

        form = CommentForm(request.POST)
        if form.is_valid():
            article_id = form.cleaned_data['article_id']
            article = get_article_by_id(article_id)

            if not article:
                return JsonFailResponse({'msg': 'article_id不存在'})
            form.save()

            return JsonSuccessResponse({})
def add_comment(request, slug):
    # if request.user.is_anonymous:
    #    return HttpResponseRedirect(reverse('user_login'))
    if request.method == 'GET':
        return HttpResponseBadRequest()
    product = get_object_or_404(Product, slug=slug)
    form = CommentForm(data=request.POST)
    if form.is_valid():
        new_comment = form.save(commit=False)
        new_comment.product = product
        new_comment.user = request.user
        new_comment.save()
        messages.success(request, 'Tebrikler yorumunuz oluşturuldu.')
        return HttpResponseRedirect(product.get_absolute_url())
예제 #10
0
파일: views.py 프로젝트: ahDDD/BlogDemo
def comment_post(request, art_id, tag=None, error_form=None):
    if datetime.datetime.utcnow().strftime(
            '%Y-%m-%d %H:%M:%S') > request.session['ttl']:
        if UserProfile.objects.get(
                belong_to=request.user).full_information is False:
            return redirect(to='complete')
    form = CommentForm(request.POST)
    if form.is_valid():
        name = form.cleaned_data['name']
        comment = form.cleaned_data['comment']
        c = Comment(name=name, comment=comment, article_id=art_id)
        c.save()
    else:
        return detail(request, art_id, tag, error_form=form)
    return redirect(to='detail', art_id=art_id, tag=tag)
예제 #11
0
def blog_single(request, id):
    product = Product.objects.filter(id=id).first()
    comments = Comment.objects.filter(product_id=id)
    if request.method == 'POST':
        commentForm = CommentForm(request.POST)

        if commentForm.is_valid():
            comment = commentForm.save(commit=False)
            comment.user = request.user
            comment.product = product
            
            comment.save()
    else:
        commentForm = CommentForm()
    return render(request, "app/blog_single.html", {"product": product, 'commentForm': commentForm, 'comments': comments})
예제 #12
0
def comments(request: HttpRequest):
    """ Отзывы """
    Visit.make(request, '/comments')
    if request.method == 'POST' and request.is_ajax():
        form = CommentForm(request.POST)
        if form.is_valid():
            response_data = Comment.make(request, form)
            return JsonResponse(response_data)
    return render(
        request, 'comments.html', {
            'name': 'comments',
            'title': 'Отзывы',
            'form': CommentForm,
            'last': Comment.last_order,
            'comments': list(
                zip(Comment.next_tuples(), Comment.comment_tuples())),
            'year': datetime.now().year,
        })
예제 #13
0
def singlebook(request, book_id):
    if request.user.is_authenticated():
        print(book_id)
        book = Book.objects.get(id=int(book_id))
        if request.method == 'POST':
            form = CommentForm(request.POST)
            if form.is_valid():
                cd = form.cleaned_data
                comment = BookComment(body=cd['body'])
                comment.post = book
                comment.save()
        comments = book.comments.all
        commentform = CommentForm()
        ctx = {'book':book, 'form':commentform, 'comments':comments}
        ctx.update(csrf(request))
        return render_to_response('app/single_book.html', ctx)
    else:
         return render_to_response('app/index.html')
예제 #14
0
파일: views.py 프로젝트: pangting/myBlog
def article_comment(request, post_id, parent_comment_id=None):
    # 这个函数的作用是当获取的文章(Article)存在时,则获取;否则返回 404 页面给用户。
    article = get_object_or_404(Article, id=post_id)
    u_id = request.session.get('id', '')
    if request.method == 'POST':
        form = CommentForm(request.POST)

        # 当调用 form.is_valid() 方法时,Django 自动帮我们检查表单的数据是否符合格式要求。
        if form.is_valid():
            # 检查到数据是合法的,调用表单的 save 方法保存数据到数据库,
            # commit=False 的作用是仅仅利用表单的数据生成 Comment 模型类的实例,但还不保存评论数据到数据库。
            new_comment = form.save(commit=False)
            new_comment.article = article
            # new_comment.user = request.user
            new_comment.user = User.objects.get(id=u_id)
            new_comment.nickname = new_comment.user.nickname

            # 二级回复
            if parent_comment_id:
                print(parent_comment_id)
                parent_comment = ArticleComment.objects.get(id=parent_comment_id)
                # 如果回复层级超过二层,强制转化成二级
                new_comment.parent_id = parent_comment.get_root().id
                # 被回复的人
                new_comment.reply_to = parent_comment.user
                new_comment.nickname = User.objects.get(id=u_id).nickname
                new_comment.save()
                return HttpResponse('200 OK')

            new_comment.save()
            return redirect('/blog/blog_detail/{}/'.format(article.id))
        else:
            return HttpResponse('提交表单有问题')
    elif request.method == 'GET':
        form = CommentForm()
        comment_list = article.articlecomment_set.all()
        context = {
            'article_id': post_id,
            'form': form,
            'parent_comment_id': parent_comment_id,
        }
        print('12232321231321321')
        return render(request, 'blog/reply.html', context=context)
예제 #15
0
def post_detail(request, pk):
    post = get_object_or_404(Post, pk=pk)
    comments = Comment.objects.filter(post=post).order_by('-created_date')
    comment_form = CommentForm()
    if request.method == "POST":
        comment_form = CommentForm(request.POST)
        if comment_form.is_valid():
            comment = comment_form.save(commit=False)
            comment.post = post
            comment.user = request.user
            comment.save()
            return redirect(request.path)
    page = pagination(request, comments, 5)

    return render(request, 'post_detail.html', {
        'post': post,
        'comment_form': comment_form,
        'page': page
    })
예제 #16
0
def post(request, pk):
    category_count = get_category_count()
    most_recent = Post.objects.order_by('-timestamp')[:3]
    post = get_object_or_404(Post, pk=pk)
    if request.user.is_authenticated:
        PostView.objects.get_or_create(user=request.user, post=post)
    form = CommentForm(request.POST or None)
    if request.method == 'POST':
        if form.is_valid():
            form.instance.user = request.user
            form.instance.post = post
            form.save()
            return redirect(reverse('post-detail', kwargs={'pk': post.pk}))
    context = {
        'form': form,
        'post': post,
        'most_recent': most_recent,
        'category_count': category_count
    }
    return render(request, 'post.html', context)
예제 #17
0
def create_comment(request):
    if request.method == 'POST':

        form = CommentForm(request.POST)
        if form.is_valid():
            article_id = form.cleaned_data['article_id']
            article = get_article_by_id(article_id)

            if not article:
                msg = '错误id'
                return HttpResponseRedirect(
                    reverse('app:detail_article', args=(article_id, )) +
                    '?form_error=' + msg + '#comment')
            # article_meta.comment_num += 1
            # article_meta.save()
            form.save()

            return HttpResponseRedirect(
                reverse('app:detail_article', args=(article_id, )) +
                '#comment')
예제 #18
0
def add_comment(request, article_id):
    """Add a new comment."""
    template = "comment.html"
    if request.method == 'POST':
        form = CommentForm(request.POST)
        if form.is_valid():
            temp = form.save(commit=False)
            temp.user = request.user
            temp.date = datetime.datetime.now()
            temp.article_id = article_id
            temp.save()
            return HttpResponseRedirect('/accounts/articles/comments/'+str(article_id))
    else:
        form = CommentForm()
    try:
        comments = Comment.objects.filter(article_id=article_id)
        return render_to_response(template, {"form":form, "comments":comments, "article_id":article_id, "full_name":request.user.username},\
                                 RequestContext(request))
    except:
        return render_to_response(template, {"form":form, "article_id":article_id, "full_name": request.user.username}, RequestContext(request))
예제 #19
0
    def school_detail(request, school_id):
        latitude, longitude, has_coordinate = utils.get_coordinate_from_request(
            request)
        school = get_object_or_404(SecondarySchoolProxy, id=school_id)

        # queryset and pagination
        queryset = SchoolComment.objects.filter(school=school)
        paginator = Paginator(queryset, 10)  # one page contains 10 items
        page = request.GET.get('page')
        try:
            comment_list = paginator.page(page)
        except PageNotAnInteger:
            # If page is not an integer, deliver first page.
            comment_list = paginator.page(1)
        except EmptyPage:
            # If page is out of range (e.g. 9999), deliver last page of results.
            comment_list = paginator.page(paginator.num_pages)

        comment_form = ''
        if request.user.is_authenticated():
            if request.POST:
                comment_form = CommentForm(request.POST)
                if comment_form.is_valid():
                    comment = comment_form.save(commit=False)
                    comment.school = school
                    comment.created_by = request.user
                    comment.save()
                    return HttpResponseRedirect(
                        request.META.get('HTTP_REFERER'))
            comment_form = CommentForm()

        return render(
            request, 'app/school/school_detail.html', {
                'school': school,
                'comment_form': comment_form,
                'comment_list': comment_list,
                'has_coordinate': has_coordinate,
                'latitude': latitude,
                'longitude': longitude
            })
def post_details_and_comment(request, pk):
    post = Post.objects.get(pk=pk)

    if request.method == 'GET':
        post.likes_count = post.like_set.count()
        context = {
            'post':
            post,
            'form':
            CommentForm(),
            'can_delete':
            request.user == post.user.user or request.user.is_staff,
            'can_edit':
            request.user == post.user.user or request.user.is_staff,
            'can_like':
            request.user != post.user.user,
            'has_liked':
            post.like_set.filter(user_id=request.user.userprofile.id).exists(),
            'can_comment':
            request.user != post.user.user or request.user.is_staff,
        }

        return render(request, 'post_details.html', context)
    else:
        form = CommentForm(request.POST)

        if form.is_valid():
            comment = Comment(text=form.cleaned_data['text'], )
            comment.post = post
            comment.user = request.user.userprofile
            comment.save()
            return redirect('post details', pk)

        context = {
            'post': post,
            'form': form,
        }
        return render(request, 'post_details.html', context)
예제 #21
0
def lois_view_detail(request, id):
    """
        Vue detail de la lois
    """
    lois = Lois.objects.get(id=id)
    comments = Comment.objects.filter(lois=id)
    if request.method == 'POST':
        form = CommentForm(request.POST)
        if form.is_valid():
            form = form.save(commit=False)
            form.comment_title = request.user
            form.lois = lois
            form.comment = request.POST['comment']
            form.save()
            return redirect('app:lois-view', id)
    else:
        form = CommentForm()
    context = {
        'lois': lois,
        'comments': comments,
        'form': form,
    }
    template_name = 'pages/lois-view.html'
    return render(request, template_name, context)
예제 #22
0
def post_detail(req, year, month, day, post):
    post = get_object_or_404(Post,
                             slug=post,
                             status='published',
                             publish__day=day,
                             publish__year=year,
                             publish__month=month)
    comments = post.comments.filter(active=True)  # comments is related name
    csubmit = False
    if req.method == 'POST':
        form = CommentForm(req.POST)
        if form.is_valid():
            new_comment = form.save(commit=False)
            new_comment.post = post
            new_comment.save()
            csubmit = True
    else:
        form = CommentForm()
    return render(req, 'post_detail.html', {
        'post': post,
        'form': form,
        'csubmit': csubmit,
        'comments': comments
    })
예제 #23
0
def post_details(request, post_id):
    post = get_object_or_404(Post, pk=post_id)
    # comments = post.comment.filter(active=True)
    comments = post.comment.all()
    comment_form = CommentForm()

    if request.method == 'POST':
        comment_form = CommentForm(request.POST)
        if comment_form.is_valid():
            new_comment = comment_form.save(commit=False)
            new_comment.post = post
            new_comment.save()
            comment_form = CommentForm()

    else:
        comment_form = CommentForm()

    context = {
        'title': 'تفاصيل التدوينة',
        'post': post,
        'comments': comments,
        'comment_form': comment_form,
    }
    return render(request, 'app/post_details.html', context)
예제 #24
0
파일: views.py 프로젝트: simonv3/ideas
def idea(request,idea_id, edit=False):
    try:
        idea = Idea.objects.get(id =idea_id)
    except Idea.DoesNotExist:
        return HttpResponseRedirect("/")
    tags = Tag.objects.filter(idea = idea)
    try:
        voted_on = idea.vote_on.get(user = request.user)
    except:
        pass
    relevant_comments = Comment.objects.filter(idea = idea).order_by("date_posted")
    commentForm = CommentForm(request.POST or None)
    comments_num = len(relevant_comments)

    if request.method == 'POST': #If something has been submitted
            if 'vote' in request.POST:
                voteForm = VoteForm(request.POST)
                if voteForm.is_valid():
                    helpers.vote(voteForm,request.user)
            if 'edit_idea' in request.POST:
                ideaForm = IdeaForm(request.POST)
                if ideaForm.is_valid():
                    clean = ideaForm.cleaned_data
                    idea.idea = clean['idea_content']
                    idea.elaborate = clean['elaborate']
                    helpers.filter_tags(clean['tags'], idea)
                    idea.private = clean['private']
                    idea.save()
                    edit = False
                    return HttpResponseRedirect("/idea/"+str(idea.id)+"/")
            if 'submit_comment' in request.POST:
                print "submit"
                commentForm = CommentForm(request.POST)
                if commentForm.is_valid():
                    clean = commentForm.cleaned_data
                    comment = Comment(text = clean['comment'],idea=idea,user = request.user)
                    comment.save()
                    all_comments_idea = Comment.objects.filter(idea = idea)
                    #if the user posting the comment doesn't own the idea, send the email to the user who owns the idea
                    if request.user != idea.user:
                        helpers.send_comment_email(True, request, idea, idea.user.email, comment.text)
                    #add the user who owns the idea to the list, because either they've already received it from above, or they're the ones posting the comment
                    user_emails_sent = [idea.user,]
                    #for every comment on the idea
                    for comment_for_idea in all_comments_idea:
                        #if the commenter is not the request user we want to send the email, but
                        if comment_for_idea.user != request.user:
                            #only if the comment hasn't already been sent an email.
                            if not comment_for_idea.user in user_emails_sent:

                                user_emails_sent.append(comment_for_idea.user)
                                helpers.send_comment_email(False, request, idea, comment_for_idea.user.email, comment.text)
                    return HttpResponseRedirect("/idea/"+str(idea.id)+"/")
                                        #encoded_email = user.email
    voteUpForm = VoteForm({'vote':'+'})
    if edit and (idea.user == request.user):
        tagString = ''
        for tag in tags:
            tagString += tag.tag + ","
        tagString = tagString[0:(len(tagString)-1)]
        ideaForm = IdeaForm({
            'idea_content':idea.idea,
            'elaborate':idea.elaborate,
            'tags':tagString})
    else:
        edit = False
    voteDownForm = VoteForm({'vote':'-'})
    commentForm = CommentForm(None)
    return render_to_response('main/idea.html',locals(),
            context_instance=RequestContext(request))
예제 #25
-1
파일: handlers.py 프로젝트: simonv3/ideas
 def create(self, request, apikey, apisignature):
     print "creating"
     if not key_check( apikey, apisignature, '/idea/comment/'):
         return {'error':'authentication failed'}
     else:
         print 
         commentForm = CommentForm({"comment":request.POST['comment']})
         if commentForm.is_valid():
             print "form valid"
             clean = commentForm.cleaned_data
             print clean
             print request.POST
             idea = Idea.objects.get(id = request.POST['idea_id'])
             print idea
             try:
                 print "trying"
                 comment = Comment(
                     text = clean['comment'], 
                     user = User.objects.get(id = request.POST['user_id']), 
                     idea = idea)
                 print comment
             except Idea.DoesNotExist:
                 return {'error':'no idea'}
             except User.DoesNotExist:
                 return {'error':'no user'}
             else:
                 comment.save()
                 #helpers.filter_tags(clean['tags'], idea)
                 print comment
                 return comment
         else:
             return {'error':'no comment'}