diff options
-rw-r--r-- | forums/settings.py | 4 | ||||
-rw-r--r-- | static/website/templates/get-question.html | 109 | ||||
-rw-r--r-- | website/views.py | 21 |
3 files changed, 118 insertions, 16 deletions
diff --git a/forums/settings.py b/forums/settings.py index c21d2e0..3bd2cad 100644 --- a/forums/settings.py +++ b/forums/settings.py @@ -183,8 +183,8 @@ TEMPLATE_CONTEXT_PROCESSORS += ( ) COMPRESS_ROOT = PROJECT_DIR + "/static/" -COMPRESS_ENABLED = False # disable in production Env -HTML_MINIFY = False # disable in production Env +COMPRESS_ENABLED = True # disable in production Env +HTML_MINIFY = True # disable in production Env HTML_MINIFY = HTML_MINIFY RECAPTCHA_PUBLIC_KEY = '6LemngMTAAAAAAC0Fkv0CQcavkTIIJ3LTDzi9gMq' diff --git a/static/website/templates/get-question.html b/static/website/templates/get-question.html index ea6bfa3..2c21c10 100644 --- a/static/website/templates/get-question.html +++ b/static/website/templates/get-question.html @@ -110,12 +110,35 @@ </div> -{% for answer in answers %} + +{% for answer,ans_vote in main_list %} <div class="row"> <div class="answer-wrapper col-lg-12 col-md-12 col-sm-12 col-xs-12"> <div class="answer {% if user|can_edit:answer %}editable{% endif %}" id="answer{{answer.id}}"> - + + <div class="votecell" style="padding-top: 0.0cm;"> + + <div class="ans-vote" > + + {% ifequal ans_vote.0 0 %} + <img src="{% static 'website/images/up1-off.png' %}" class="ans-vote-up" id="{{ answer.id }}" title="This question shows research effort; it is useful and clear"/> + {% else %} + <img src="{% static 'website/images/up1-on.png' %}" class="ans-vote-up selected" id="{{ answer.id }}" title="This question shows research effort; it is useful and clear"/> + {% endifequal %} + + <span class="vote-count-post" id="span{{ answer.id }}" > + {{ ans_vote.2 }} + </span> + {% ifequal ans_vote.1 0 %} + <img type="image" src="{% static 'website/images/down1-off.png' %}" class="ans-vote-down" id="{{ answer.id }}" title="This question does not show any research effort; it is not useful and unclear" /> + {% else %} + <img src="{% static 'website/images/down1-on.png' %}" class="ans-vote-down selected" id="{{ answer.id }}" title="This question does not show any research effort; it is not useful and unclear"/> + {% endifequal %} + </div> + </div> + + <div class="body" id="body{{ answer.id }}"> {{ answer.body|safe }} </div> @@ -261,7 +284,7 @@ {% endblock %} {% block javascript %} - <script src="{% static 'website/js/nicEdit.js' %}" type="text/javascript"></script> +<script src="{% static 'website/js/nicEdit.js' %}" type="text/javascript"></script> <script type="text/javascript"> bkLib.onDomLoaded(function() { new nicEditor({ @@ -270,7 +293,7 @@ }).panelInstance('id_body'); }); </script> - <script src="{% static 'website/js/thread-user.js' %}"></script> + <script type="text/javascript"> $(document).ready(function() { @@ -279,11 +302,9 @@ data: {csrfmiddlewaretoken: '{{ csrf_token }}' }, }); + /* VOTE FOR QUESTION */ $('div.vote img.vote-up').click(function() { - - - var id = {{ question.pk }}; var vote_type = 'up'; @@ -346,11 +367,81 @@ } }); - + /* VOTE FOR ANSWERS */ + + /* UP VOTE */ + $('div.ans-vote img.ans-vote-up').click(function(event) { + + var id = event.target.id; + var vote_type = 'up'; + + if ($('img#'+id).hasClass('selected')) { + var vote_action = 'recall-vote' + + $.post('/ans_vote_post/', {id:id, type:vote_type, action:vote_action}, function(response) { + + $('img#'+id).removeAttr('src') + .attr('src', '{% static 'website/images/up1-off.png' %}') + .removeClass('selected'); + + $('span#span'+id).html(response); + }); + } + + /* USER WISHES TO VOTE */ + else { + + var vote_action = 'vote' + $.post('/ans_vote_post/', {id:id, type:vote_type, action:vote_action}, function(response) { + + $('img#'+id).removeAttr('src') + .attr('src', '{% static 'website/images/up1-on.png' %}') + .addClass('selected'); + + $('span#span'+id).html(response); + }); + } + + }); /* END OF UP VOTE FOR ANSWERS */ + + /* DOWNVOTE */ + + $('div.ans-vote img.ans-vote-down').click(function(event) { + + var id = event.target.id; + var vote_type = 'down'; + + /* USER HAS ALREADY DOWN-VOTED */ + + if ($('div.ans-vote img.ans-vote-down').hasClass('selected')) { + var vote_action = 'recall-vote' + + $.post('/ans_vote_post/', {id:id, type:vote_type, action:vote_action}, function(response) { + + $('div.ans-vote img.ans-vote-down').removeAttr('src') + .attr('src', '{% static 'website/images/down1-off.png' %}') + .removeClass('selected'); + + $('div.ans-vote span#span'+id).html(response); + }); + } + /* USER WISHES TO VOTE */ + else { + var vote_action = 'vote' + $.post('/ans_vote_post/', {id:id, type:vote_type, action:vote_action}, function(response) { + + $('div.ans-vote img.ans-vote-down').removeAttr('src') + .attr('src', '{% static 'website/images/down1-on.png' %}') + .addClass('selected'); + + $('div.ans-vote span#span'+id).html(response); + }); + } }); + }); </script> - + <script src="{% static 'website/js/thread-user.js' %}"></script> <script src="{% static 'website/js/custom.js' %}"></script> {% endblock %} diff --git a/website/views.py b/website/views.py index 6e84cfa..b86fdbf 100644 --- a/website/views.py +++ b/website/views.py @@ -36,9 +36,7 @@ def questions(request): questions = Question.objects.all().order_by('date_created').reverse() paginator = Paginator(questions, 20) page = request.GET.get('page') - for q in questions: - print q.title - print q.num_votes + try: questions = paginator.page(page) except PageNotAnInteger: @@ -62,14 +60,26 @@ def get_question(request, question_id=None, pretty_url=None): thisuserdownvote = question.userDownVotes.filter(id=request.user.id).count() net_count = question.userUpVotes.count() - question.userDownVotes.count() + ans_votes = [] + + for vote in answers: + #print "ansvote "+str(vote.userUpVotes.filter(id=request.user.id).count()) + #print "ansvote "+str(vote.userDownVotes.filter(id=request.user.id).count()) + net_ans_count = vote.userUpVotes.count() - vote.userDownVotes.count() + ans_votes.append([vote.userUpVotes.filter(id=request.user.id).count(),vote.userDownVotes.filter(id=request.user.id).count(),net_ans_count]) + #for (f,b) in zip(foo, bar): + #print "f: ", f ,"; b: ", b + main_list = zip(answers,ans_votes) + print "ans : "+str(ans_votes) context = { 'question': question, - 'answers': answers, + 'main_list': main_list, 'form': form, 'thisUserUpvote': thisuserupvote, 'thisUserDownvote': thisuserdownvote, 'net_count': net_count, - 'num_votes':question.num_votes + 'num_votes':question.num_votes, + 'ans_votes':ans_votes } context.update(csrf(request)) # updating views count @@ -356,6 +366,7 @@ def ans_vote_post(request): post_id = int(request.POST.get('id')) + print post_id vote_type = request.POST.get('type') vote_action = request.POST.get('action') |