diff --git a/backend/db.sqlite3 b/backend/db.sqlite3 index 91e430b..b64c046 100644 Binary files a/backend/db.sqlite3 and b/backend/db.sqlite3 differ diff --git a/backend/postings/api/views.py b/backend/postings/api/views.py index c21d82f..e8c228b 100644 --- a/backend/postings/api/views.py +++ b/backend/postings/api/views.py @@ -2,7 +2,6 @@ from rest_framework import generics, mixins from postings.models import * from .serializers import * from django.db.models import Q -from django.http import * # The view for listing all generic Review objects. @@ -15,6 +14,13 @@ class ReviewView(generics.RetrieveUpdateDestroyAPIView): queryset = Review.objects.all() serializer_class = ReviewSerializer +class ReviewHelpfulVote(mixins.CreateModelMixin): + lookup_field = 'pk' + serializer_class = ReviewHelpfulVoteSerializer + + def post(self, request, *args, **kwargs): + return self.create(request, *args, **kwargs) + def review_helpful_vote(request, review_id): if request.method == 'POST': helpful = request.POST.get('helpful') @@ -32,6 +38,4 @@ def review_helpful_vote(request, review_id): helpful=helpful ) - return HttpResponse(status=201) - return HttpResponseBadRequest("Bad Request") \ No newline at end of file diff --git a/backend/postings/migrations/0004_remove_reviewhelpfulvote_user.py b/backend/postings/migrations/0004_remove_reviewhelpfulvote_user.py deleted file mode 100644 index 2f1223a..0000000 --- a/backend/postings/migrations/0004_remove_reviewhelpfulvote_user.py +++ /dev/null @@ -1,17 +0,0 @@ -# Generated by Django 2.1.1 on 2018-10-11 09:27 - -from django.db import migrations - - -class Migration(migrations.Migration): - - dependencies = [ - ('postings', '0003_auto_20181002_1355'), - ] - - operations = [ - migrations.RemoveField( - model_name='reviewhelpfulvote', - name='user', - ), - ] diff --git a/backend/postings/models.py b/backend/postings/models.py index cf9fd89..d660248 100644 --- a/backend/postings/models.py +++ b/backend/postings/models.py @@ -62,14 +62,12 @@ class Review(models.Model): author = models.ForeignKey('postings.User', on_delete=models.PROTECT, null=True, blank=True) # Gets the total number of votes which marked this review as 'helpful'. - @property - def helpful_vote_count(self): - return ReviewHelpfulVote.objects.filter(review=self.pk, helpful=True).count() + def getHelpfulVoteCount(self): + return ReviewHelpfulVote.objects.filter(pk=self.pk, helpful=True).count() # Gets the total number of votes which marked this review as 'unhelpful'. - @property - def unhelpful_vote_count(self): - return ReviewHelpfulVote.objects.filter(review=self.pk, helpful=False).count() + def getUnhelpfulVoteCount(self): + return ReviewHelpfulVote.objects.filter(pk=self.pk, helpful=False).count() # A vote for a review as either positive or negative. class ReviewHelpfulVote(models.Model): @@ -77,6 +75,8 @@ class ReviewHelpfulVote(models.Model): review = models.ForeignKey('postings.Review', on_delete=models.CASCADE) # Whether or not the referenced review was helpful. helpful = models.BooleanField() + # The user who made this vote. + user = models.ForeignKey('postings.User', on_delete=models.CASCADE) # A RateableEntity for universities. class University(RateableEntity): diff --git a/backend/postings/static/postings/js/main.js b/backend/postings/static/postings/js/main.js index 771d39e..64bda14 100644 --- a/backend/postings/static/postings/js/main.js +++ b/backend/postings/static/postings/js/main.js @@ -99,5 +99,11 @@ $(function(){ ((''+month).length<2 ? '0' : '') + month + '/' + d.getFullYear(); $(".date").append(output); - + if ($('.landingpage').length > 0) { + $("body").addClass("box"); + }else if ($('.results').length > 0) { + $("body").addClass("box3"); + }else if ($('.entity').length > 0) { + $("body").addClass("box2"); + } }); \ No newline at end of file diff --git a/backend/postings/static/postings/js/voting.js b/backend/postings/static/postings/js/voting.js index 26a6a6c..c65915b 100644 --- a/backend/postings/static/postings/js/voting.js +++ b/backend/postings/static/postings/js/voting.js @@ -33,27 +33,6 @@ // }); // }); -// Sends either an up- or down-vote for a particular review. -function sendVote (event, is_helpful) { - var csrf_token = $('#csrf-token input').val(); - var review_id = $(event.target).closest('.js_votes').data('review_id'); - var data = { - 'csrfmiddlewaretoken': csrf_token, - 'helpful': is_helpful - }; - $.post( - '/api/postings/reviews/' + review_id + '/helpful_vote/', - data, - ) - .done(function (response) { - console.log(response); - }) - .fail(function (response) { - console.log(response); - }); -} - -// Registers all events to the document. function registerEvents () { $(document.body) .off('click.js_vote_up') @@ -62,7 +41,6 @@ function registerEvents () { function (event) { event.preventDefault(); console.log("updoot"); - sendVote(event, true); }); $(document.body) @@ -72,7 +50,6 @@ function registerEvents () { function (event) { event.preventDefault(); console.log("downdoot"); - sendVote(event, false); }); } diff --git a/backend/postings/templates/postings/frontend/base_page.html b/backend/postings/templates/postings/frontend/base_page.html index 0bd4f60..4e6f40a 100644 --- a/backend/postings/templates/postings/frontend/base_page.html +++ b/backend/postings/templates/postings/frontend/base_page.html @@ -33,11 +33,11 @@ -
+ {% block content %} {# Fill in this block in child pages to display content for the page. #} {% endblock %} -
+ {# Javascript dependencies #} diff --git a/backend/postings/templates/postings/frontend/entity.html b/backend/postings/templates/postings/frontend/entity.html index 2303ce7..000ecdf 100644 --- a/backend/postings/templates/postings/frontend/entity.html +++ b/backend/postings/templates/postings/frontend/entity.html @@ -8,6 +8,7 @@ {% endblock %} {% block content %} +

{{ entity.name }} {{ entity.average }}

@@ -92,6 +93,7 @@
+ {% endblock %} {% block extra_js %} diff --git a/backend/postings/templates/postings/frontend/landing.html b/backend/postings/templates/postings/frontend/landing.html index c333292..f1b6bf1 100644 --- a/backend/postings/templates/postings/frontend/landing.html +++ b/backend/postings/templates/postings/frontend/landing.html @@ -6,6 +6,8 @@ {% endblock %} {% block content %} + +

Find rated courses

The best course reviews by your fellow students!

@@ -20,4 +22,7 @@
+
+ + {% endblock %} diff --git a/backend/postings/templates/postings/frontend/results.html b/backend/postings/templates/postings/frontend/results.html index dcdcab8..6649fee 100644 --- a/backend/postings/templates/postings/frontend/results.html +++ b/backend/postings/templates/postings/frontend/results.html @@ -5,6 +5,7 @@ {% endblock %} {% block content %} +
@@ -42,4 +43,8 @@ {% endif %}
+
+
+
+ {% endblock %} \ No newline at end of file diff --git a/backend/postings/templates/postings/frontend/review.html b/backend/postings/templates/postings/frontend/review.html index 0cbb7d6..41ab8bc 100644 --- a/backend/postings/templates/postings/frontend/review.html +++ b/backend/postings/templates/postings/frontend/review.html @@ -19,14 +19,14 @@
{{ review.title }}
{{ review.content }}
-
+
Was this review helpful? - Yes - No + Yes + No
- {{ review.helpful_vote_count }} / - {{ review.unhelpful_vote_count }} + {{ review.getHelpfulVoteCount }} / + {{ review.getUnhelpfulVoteCount }}
\ No newline at end of file diff --git a/frontpage/js/main.js b/frontpage/js/main.js index 771d39e..4afcb81 100644 --- a/frontpage/js/main.js +++ b/frontpage/js/main.js @@ -100,4 +100,13 @@ $(function(){ d.getFullYear(); $(".date").append(output); + if ($('.fullcontainer .landingpage')[0]) { + alert("yihaa"); + }else{ + alert("noo"); + } + if ($('.fullcontainer landingpage')[0]) { + alert("yihaa2"); + } + }); \ No newline at end of file diff --git a/frontpage/rateables/js/main.js b/frontpage/rateables/js/main.js index 771d39e..ac6a657 100644 --- a/frontpage/rateables/js/main.js +++ b/frontpage/rateables/js/main.js @@ -100,4 +100,13 @@ $(function(){ d.getFullYear(); $(".date").append(output); + + if ($('.fullcontainer .landingpage')[0]) { + alert("yihaa"); + }else{ + alert("noo"); + } + if ($('.fullcontainer landingpage')[0]) { + alert("yihaa2"); + } }); \ No newline at end of file