Beispiel #1
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 #2
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 #3
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 #4
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 #5
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 #6
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)
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 #8
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 #9
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)