Beispiel #1
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 #2
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 #3
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})
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 #5
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 #6
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 #7
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 #8
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 #9
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 #10
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 #11
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 #12
0
def get_blog_comment():
    return CommentForm()
Beispiel #13
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)