diff --git a/blt/urls.py b/blt/urls.py index 41b92c104..620a63a83 100644 --- a/blt/urls.py +++ b/blt/urls.py @@ -68,12 +68,14 @@ UserProfileDetailsView, UserProfileDetailView, contributors_view, + dislike_issue2, facebook_callback, flag_issue2, github_callback, google_callback, like_issue2, subscribe_to_domains, + vote_count, ) favicon_view = RedirectView.as_view(url="/static/favicon.ico", permanent=True) @@ -269,7 +271,13 @@ ), re_path(r"^flag_issue/(?P\d+)/$", website.views.flag_issue, name="flag_issue"), re_path(r"^like_issue2/(?P\d+)/$", like_issue2, name="like_issue2"), + re_path(r"^dislike_issue2/(?P\d+)/$", dislike_issue2, name="dislike_issue2"), re_path(r"^flag_issue2/(?P\d+)/$", flag_issue2, name="flag_issue2"), + re_path(r"^vote_count/(?P\d+)/$", vote_count, name="vote_count"), + path("domain//subscribe/", subscribe_to_domains, name="subscribe_to_domains"), + re_path(r"^save_issue/(?P\d+)/$", website.views.save_issue, name="save_issue"), + path("domain//subscribe/", subscribe_to_domains, name="subscribe_to_domains"), + re_path(r"^save_issue/(?P\d+)/$", website.views.save_issue, name="save_issue"), path("domain//subscribe/", subscribe_to_domains, name="subscribe_to_domains"), re_path(r"^save_issue/(?P\d+)/$", website.views.save_issue, name="save_issue"), re_path( diff --git a/website/templates/_bug.html b/website/templates/_bug.html index f375baedd..e1e4b20a7 100644 --- a/website/templates/_bug.html +++ b/website/templates/_bug.html @@ -58,67 +58,84 @@ {% endif %} {% endfor %} -
- - {% with user_issue_upvoted_list=user.userprofile.issue_upvoted.all %} - {% if user_issue_upvoted_list and bug in user_issue_upvoted_list %} - - {% endif %} - {% endwith %} - - {% with user_issue_flagged_list=user.userprofile.issue_flaged.all %} - {% if user_issue_flagged_list and bug in user_issue_flagged_list %} - + {% endif %} + {% endwith %} + + 0 + {% with user_issue_downvoted_list=user.userprofile.issue_downvoted.all %} + {% if user_issue_downvoted_list and bug in user_issue_downvoted_list %} + + {% endif %} + {% endwith %} + + {% with user_issue_flagged_list=user.userprofile.issue_flaged.all %} + {% if user_issue_flagged_list and bug in user_issue_flagged_list %} + - {% endif %} - {% endwith %} - - - - - - + + {% endif %} + {% endwith %} +
+ {% if request.user.is_authenticated %} + +

{{ dislikes }} Downvotes

+ + {% else %} + + {% endif %} + + diff --git a/website/templates/issue2.html b/website/templates/issue2.html index 063f0f6e9..7e59621ae 100644 --- a/website/templates/issue2.html +++ b/website/templates/issue2.html @@ -100,6 +100,7 @@
{% include "includes/_likes2.html" %} + {% include "includes/_dislike2.html" %} {% include "includes/_flags2.html" %} {% include "includes/_bookmark2.html" %}
diff --git a/website/views.py b/website/views.py index ce7ed4ea5..25be84f71 100644 --- a/website/views.py +++ b/website/views.py @@ -3612,9 +3612,12 @@ def flag_issue2(request, issue_pk): def like_issue2(request, issue_pk): context = {} issue_pk = int(issue_pk) - issue = Issue.objects.get(pk=issue_pk) + issue = get_object_or_404(Issue, pk=issue_pk) userprof = UserProfile.objects.get(user=request.user) - if userprof in UserProfile.objects.filter(issue_upvoted=issue): + + if UserProfile.objects.filter(issue_downvoted=issue, user=request.user).exists(): + userprof.issue_downvoted.remove(issue) + if UserProfile.objects.filter(issue_upvoted=issue, user=request.user).exists(): userprof.issue_upvoted.remove(issue) else: userprof.issue_upvoted.add(issue) @@ -3646,13 +3649,41 @@ def like_issue2(request, issue_pk): html_message=msg_html, ) - userprof.save() total_votes = UserProfile.objects.filter(issue_upvoted=issue).count() context["object"] = issue context["likes"] = total_votes return render(request, "includes/_likes2.html", context) +@login_required(login_url="/accounts/login") +def dislike_issue2(request, issue_pk): + context = {} + issue_pk = int(issue_pk) + issue = get_object_or_404(Issue, pk=issue_pk) + userprof = UserProfile.objects.get(user=request.user) + + if UserProfile.objects.filter(issue_upvoted=issue, user=request.user).exists(): + userprof.issue_upvoted.remove(issue) + if UserProfile.objects.filter(issue_downvoted=issue, user=request.user).exists(): + userprof.issue_downvoted.remove(issue) + else: + userprof.issue_downvoted.add(issue) + total_votes = UserProfile.objects.filter(issue_downvoted=issue).count() + context["object"] = issue + context["dislikes"] = total_votes + return render(request, "includes/_dislike2.html", context) + + +@login_required(login_url="/accounts/login") +def vote_count(request, issue_pk): + issue_pk = int(issue_pk) + issue = Issue.objects.get(pk=issue_pk) + + total_upvotes = UserProfile.objects.filter(issue_upvoted=issue).count() + total_downvotes = UserProfile.objects.filter(issue_downvoted=issue).count() + return JsonResponse({"likes": total_upvotes, "dislikes": total_downvotes}) + + @login_required(login_url="/accounts/login") def subscribe_to_domains(request, pk): domain = Domain.objects.filter(pk=pk).first()