Beispiel #1
0
def tab_show(id):
    form     = CommentForm(formdata=request.values)
    likeform = LikeForm()
    tab      = Tab.query.filter_by(id=id).first_or_404()
    content  = unicode(escape(tab.content)).replace(' ', '&nbsp;').replace('\r\n', '<br />')
    if tab.tabs_type == 5:
        tab.tab_imgs = tab.tabs_path.split('|')

    dic_codes  = dict([(code.id,code.code_name) for code in Dic_code.query.all()])
    if tab.instrument != 13:
        instrument = dic_codes[tab.instrument] + u'谱'
    else:
        instrument = u'乐谱'

    # 查询评论 type_id: 1-问题,2-曲谱,3-二手交易,4-活动,5-艺人
    comments = comments_query(2, id)

    if current_user.is_anonymous() or current_user.id != tab.uid:
        tab.hot = tab.hot + 1
    db.session.commit()

    is_like = None
    if current_user.is_authenticated():
        is_like = Like.query.filter_by(uid=current_user.id).filter_by(like_type=1)\
                    .filter_by(like_id=id).first()

    if request.method == 'POST' and form.validate_on_submit():
        comment = Comment()
        comment.save(form, current_user.id, 2, id)
        db.session.commit()
        return redirect(url_for('tabs.tab_show', id=id))
    return render_template('tabs/tab_show.html', form=form, tab=tab, comments=comments, content=content,\
        is_like=is_like, likeform=likeform, instrument=instrument)
Beispiel #2
0
def question_show(id):
    form                     = CommentForm(formdata=request.values)
    question                 = Question.query.filter_by(id=id).first_or_404()
    question.uni_content   = unicode(escape(question.content)).replace("\r\n", "<br />")
    
    comments                 = comments_query(1, id)

    dic_codes                = dict([(code.id,code.code_name) for code in Dic_code.query.all()])
    big_cates                = Dic_code.query.filter_by(parent_id=2).all()
    for big_cate in big_cates:
        big_cate.children = Dic_code.query.filter(Dic_code.parent_id == big_cate.type_id).order_by(Dic_code.id)

    if current_user.is_anonymous() or current_user.id != question.uid:
        question.hot = question.hot + 1
    db.session.commit()

    if request.method == 'POST' and form.validate_on_submit():
        comment = Comment()
        comment.save(form, current_user.id, 1, id)
        question.modify_time  = datetime.now()
        question.comments_num = question.comments_num + 1
        db.session.commit()
        return redirect(url_for('questions.question_show', id=id))

    return render_template('questions/question_show.html', question=question, big_cates=big_cates, \
        dic_codes=dic_codes, comments=comments, form=form)
Beispiel #3
0
def thread_show(art_id, thr_id):
    form                  = CommentForm()
    likeform              = LikeForm()
    artist                = Artist.query.filter_by(id=art_id).first_or_404()
    thread                = Thread.query.filter_by(id=thr_id).first_or_404()
    thread.uni_content = unicode(escape(thread.content)).replace("\r\n", "<br />")
    # 查询评论 type_id: 1-问题,2-曲谱,3-二手交易,4-活动,5-艺人
    comments_select       = comments_query(5, thr_id)

    if current_user.is_anonymous() or current_user.id != thread.uid:
        thread.hot = thread.hot + 1
    db.session.commit()

    is_like = None
    if current_user.is_authenticated():
        is_like = Like.query.filter_by(uid=current_user.id).filter_by(like_type=2)\
                    .filter_by(like_id=art_id).first()        


    if request.method == 'POST' and form.validate_on_submit():
        comment = Comment()
        comment.save(form, current_user.id, 5, thr_id)
        thread.comments_num = thread.comments_num + 1
        db.session.commit()
        comments_select  = comments_query(5, thr_id)
        return redirect(url_for('artists.thread_show', art_id=art_id, thr_id=thr_id))
        #return render_template('artists/comments_ajax.html', comments=comments_select, thread=thread)

    return render_template('artists/thread_show.html', comments=comments_select, thread=thread, form=form,\
        artist=artist, likeform=likeform, is_like=is_like)
Beispiel #4
0
def post_comment(request, campaign_id, template='campaign/comment_form.html'):
    campaign = get_object_or_404(Campaign.objects.public(), pk=campaign_id)
    if request.method == 'POST':
        form = CommentForm(author=request.user, target_instance=campaign, data=request.POST)
        if form.is_valid():
            comment = form.save()
            request.user.message_set.create(message=_('Thank you for your <a href="#c%s">comment&nbsp;&raquo;</a>' % comment.pk))
            _log.debug('Campaign comment posted: (%s)', comment.get_as_text())
            cache_killer = "%s-%s"% (random.randint(0, 10000), time())
            return HttpResponseRedirect(reverse('view_campaign', kwargs={'campaign_id':campaign.pk}) + "?q=%s&new_c=y" % cache_killer)
    else:
        form = CommentForm(author=request.user, target_instance=campaign)
    ctx = {'form':form, 'comment_form':form, 'campaign':campaign}
    return render_view(request, template, ctx)
Beispiel #5
0
def view(request, campaign_id, template='campaign/detail.html'):
    """Campaign detail view"""
    ctx = {}
    campaign = get_object_or_404(Campaign.visible_objects, pk=campaign_id)
    ctx['is_owner'] = request.user.is_authenticated(
    ) and request.user.id == campaign.artist.user_profile.user.id
    ctx['is_admin'] = request.user.has_perm('campaign.can_manage_campaigns')
    # Campaign changes, if available, are shown only to the campaign owner and the admin.
    ctx['changes'] = (ctx['is_owner']
                      or ctx['is_admin']) and campaign.changed_version
    if not campaign.is_approved:
        # Only admins and campaign owners may see unapproved campaigns.
        if not request.user.is_authenticated():
            return HttpResponseRedirect("%s?next=%s" %
                                        (reverse('login'), request.path))
        if not (ctx['is_owner'] or ctx['is_admin']):
            # We could return an HTTP forbidden response here but we don't want a malicious user
            # to know if a campaign even exists with this id.
            # So, we raise a 404 - Page Not Found instead.
            raise Http404
    ctx['c'] = campaign
    ctx['campaign'] = campaign
    if request.user.is_authenticated():
        ctx['comment_form'] = CommentForm(author=request.user,
                                          target_instance=campaign)
    if not ctx['is_owner']:
        stats = campaign.stats
        stats.num_views = stats.num_views + 1
        stats.save()
    return render_view(request, template, ctx)
Beispiel #6
0
def update_comment_section(request, pk):
    if request.method == 'GET':
        return redirect('pet_detail', pk)

    try:
        pet = Pet.objects.get(pk=pk)
    except ObjectDoesNotExist:
        return redirect('pet_detail', pk)

    comment = Comment(pet=pet)
    form = CommentForm(request.POST, instance=comment)
    if form.is_valid():
        form.save()
        return redirect('pet_detail',pk)

    return HttpResponse('some ERROR')
Beispiel #7
0
def trade_show(id):
    form    = CommentForm(formdata=request.values)
    thing   = Thing.query.filter_by(id=id).first()
    thing.thing_content = unicode(escape(thing.content)).replace(' ', '&nbsp;').replace('\r\n', '<br />')

    comments = comments_query(4, id)

    if current_user.is_anonymous() or current_user.id != thing.uid:
        thing.things_hot = thing.things_hot + 1
    db.session.commit()

    if request.method == 'POST' and form.validate_on_submit():
        comment = Comment()
        comment.save(form, current_user.id, 4, id)
        db.session.commit()
        return redirect(url_for('trade.trade_show', id=id))

    return render_template('trade/trade_show.html', form=form, thing=thing, comments=comments)
Beispiel #8
0
  def handle(self):
    comment_form = CommentForm()
    if self.request.method == 'POST':
      params = {'author':self.request.user.username,
                'owner':self.content.owner,
                'content':self.content.uuid,
                'content_type':self.content.app_label}

      comment_form = CommentForm(self.request.POST, extra_params=params)

      if comment_form.is_valid():
        comment_ref = comment_form.save()
        message = util.get_message('success_comment_new')
        util.success(self.request, message)
        return http.HttpResponseRedirect(self.content.url())
    self.update_context({"comment_form":comment_form})

    return self.get_response()
Beispiel #9
0
def pet_detail(request, pk):
    pet = Pet.objects.get(pk=pk)
    # total_comments = Comment.objects.filter(pk=pk)

    if request.method == 'POST':
        form = CommentForm(request.POST)
        if form.is_valid():
            comment = Comment(comment=form.cleaned_data['comment'])

            comment.pet = pet
            comment.save()
            return redirect('pet-detail', pk)

        context = {'pet': pet, 'form': form}
        return render(request, 'pets/pet_detail.html', context)

    context = {'pet': pet, 'form': CommentForm()}
    return render(request, 'pets/pet_detail.html', context)
Beispiel #10
0
def pet_detail(request, pk):
    pet_details = Pet.objects.get(pk=pk)
    likes = Like.objects.filter(pet=pet_details).count()
    comments = Comment.objects.all()

    if request.method == 'POST':
        comment = request.POST['comment']
        Comment.objects.create(comment=comment, pet=pet_details)
        return redirect('common:pet_detail', pk)
    form = CommentForm()
    return render(request, 'pet_detail.html', {'detail': pet_details, 'likes': likes, 'form': form, 'comment': comments})
Beispiel #11
0
    def handle(self):
        comment_form = CommentForm()
        if self.request.method == "POST":
            params = {
                "author": self.request.user.username,
                "owner": self.content.owner,
                "content": self.content.uuid,
                "content_type": self.content.app_label,
            }

            comment_form = CommentForm(self.request.POST, extra_params=params)

            if comment_form.is_valid():
                comment_ref = comment_form.save()
                message = util.get_message("success_comment_new")
                util.add_success(self.request, message)
                return http.HttpResponseRedirect(self.content.url())
        self.update_context({"comment_form": comment_form})

        return self.get_response()
Beispiel #12
0
def get_detail_context(req, pet):
    comments = pet.comment_set.all()
    return {
        'pet': pet,
        'form': CommentForm(),
        'can_delete': req.user == pet.user.user,
        'can_edit': req.user == pet.user.user,
        'can_like': req.user != pet.user.user,
        'can_comment': req.user != pet.user.user,
        'has_liked': pet.like_set.filter(user_id=req.user.userprofile.id).exists(),
    }
Beispiel #13
0
def show_pet_detail(req, pk):
    pet = Pet.objects.get(pk=pk)
    pet.likes_count = pet.like_set.count()

    if req.method == 'GET':
        return render(req, 'pets/pet_detail.html', get_detail_context(req, pet))

    elif req.method == 'POST':
        form = CommentForm(req.POST)
        if form.is_valid():
            comment = Comment(comment=form.cleaned_data['comment'])
            comment.pet = pet
            comment.user = req.user.userprofile  # do not link to profile but user
            comment.save()
            pet.comment_set.add(comment)
            pet.save()

        # new_comment = Comment(pet=pet, comment=req.POST['comment'])
        # new_comment.save()
        # pet.comment_set.add(new_comment)
        return redirect('pet_details', pet.id)
Beispiel #14
0
def pet_details(req, pet_id):
    pet = Pet.objects.get(pk=pet_id)
    if req.method == 'GET':
        context = {
            'pet': pet,
            'comment_form': CommentForm()
        }
        return render(req, 'pets/pet_detail.html', context=context)
    else:
        form = CommentForm(req.POST)
        if form.is_valid():
            comment = Comment(comment=form.cleaned_data['comment'])
            comment.pet = pet
            comment.save()
            return redirect('pet details', pet_id)

        context = {
            'pet': pet,
            'comment_form': form
        }

        return render(req, 'pets/pet_detail.html', context=context)
Beispiel #15
0
def pet_detail(request, pk):
    pet = Pet.objects.get(pk=pk)
    if request.method == 'POST':
        Comment.objects.create(pet=pet, comment=request.POST['comment'])

    likes_count = Like.objects.filter(pet_id=pk)
    comment_form = CommentForm()
    comments = Comment.objects.filter(pet_id=pk)

    content = {'pet': pet, 'likes': len(likes_count),
               'comments': comments, 'comment_form': comment_form}

    return render(request, 'pets/pet_detail.html', content)
Beispiel #16
0
def pet_detail(request, pk):
    comment_form = CommentForm()
    try:
        pet = Pet.objects.get(pk=pk)
        number = pet.like_set.count()
        comments = pet.comment_set.all()
    except ObjectDoesNotExist:
        return redirect('pet_all')
    context = {
        'pet': pet,
        'number': number,
        'form': comment_form,
        'comments': comments
    }
    return render(request, 'pets/pet_detail.html', context)
Beispiel #17
0
def post_comment(request, campaign_id, template='campaign/comment_form.html'):
    campaign = get_object_or_404(Campaign.objects.public(), pk=campaign_id)
    if request.method == 'POST':
        form = CommentForm(author=request.user,
                           target_instance=campaign,
                           data=request.POST)
        if form.is_valid():
            comment = form.save()
            request.user.message_set.create(message=_(
                'Thank you for your <a href="#c%s">comment&nbsp;&raquo;</a>' %
                comment.pk))
            _log.debug('Campaign comment posted: (%s)', comment.get_as_text())
            cache_killer = "%s-%s" % (random.randint(0, 10000), time())
            return HttpResponseRedirect(
                reverse('view_campaign', kwargs={'campaign_id': campaign.pk}) +
                "?q=%s&new_c=y" % cache_killer)
    else:
        form = CommentForm(author=request.user, target_instance=campaign)
    ctx = {'form': form, 'comment_form': form, 'campaign': campaign}
    return render_view(request, template, ctx)
Beispiel #18
0
def show_pets_details_and_commits(request, pk):
    pet = Pet.objects.get(pk=pk)
    context = {
        "pet":
        pet,
        "comment":
        CommentForm(),
        'is_owner':
        request.user == pet.user.user,
        'has_liked':
        pet.like_set.filter(user_id=request.user.userprofile.id).exists(),
    }
    if request.method == 'POST':
        comment = CommentForm(request.POST)
        if comment.is_valid():
            comment = comment.clean()['comment']
            com = Comment(pet=pet,
                          comment=comment,
                          user=request.user.userprofile)
            com.save()
            context = {"pet": pet, "comment": CommentForm()}

    return render(request, 'pets/pet_detail.html', context)
Beispiel #19
0
def get_blog_comment():
    return CommentForm()
Beispiel #20
0
 def dispatch(self, request, *args, **kwargs):
     self.pet = Pet.objects.get(pk=kwargs['pk'])
     if self.request.user.pk != self.pet.pk:
         self.comment_form = CommentForm()
     return super().dispatch(request, *args, **kwargs)