def project_details(request, id):
    project = get_object_or_404(Project, id=id)
    pictures = Project_Pictures.objects.all().filter(project_id=project)
    comments = Comment.objects.all().filter(project_id=project)
    commented_users = {}
    profiles = {}
    for comment in comments:
        profiles[comment.id] = Profile.objects.get(user=comment.user_id)
    comment_form = CommentForm()
    donation_form = DonationForm()
    rating_form = RatingForm()
    donation = Donation.objects.all().filter(project_id=project).aggregate(
        Sum('amount'))
    context = {
        'project': project,
        'pictures': pictures,
        'comments': comments,
        'commented_users': commented_users,
        'profiles': profiles,
        'comment_form': comment_form,
        'donation_form': donation_form,
        'rating_form': rating_form,
        'donation': donation,
    }
    return render(request, 'project/project_details.html', context)
Esempio n. 2
0
def project_details(request, id):
    project = get_object_or_404(Project, id=id)
    pictures = Project_Pictures.objects.all().filter(project_id=project)
    comments = Comment.objects.all().filter(project_id=project)
    rate = Rate_Project.objects.all().filter(project_id=project).aggregate(
        rate=Avg('rate'))
    tags = project.tags.names()
    similar_projects = Project.objects.filter(
        tags__name__in=tags).order_by('id')[1:5]
    commented_users = {}
    profiles = {}
    for comment in comments:
        profiles[comment.id] = Profile.objects.get(user=comment.user_id)
    comment_form = CommentForm()
    donation_form = DonationForm()
    rating_form = RatingForm()
    donation = Donation.objects.all().filter(project_id=project).aggregate(
        amount=Sum('amount'))
    categories = Category.objects.all()
    is_deletable = 0
    if donation['amount'] is None:
        donation['amount'] = 0
    if donation['amount'] < project.total_target / 4:
        is_deletable = 1
    context = {
        'project': project,
        'pictures': pictures,
        'comments': comments,
        'commented_users': commented_users,
        'profiles': profiles,
        'comment_form': comment_form,
        'donation_form': donation_form,
        'rating_form': rating_form,
        'donation': donation,
        'rate': rate['rate'],
        'current_user': request.user,
        'is_deletable': is_deletable,
        'similar_projects': similar_projects,
        'categories': categories,
    }
    return render(request, 'project/project_details.html', context)