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 @@ -