<commit_before>from django.shortcuts import render, get_object_or_404
from .models import Question, Reply, Comment
from django.contrib.auth.decorators import login_required
from django.http.response import HttpResponse
from django.db.models import Q
# Create your views here.

from zhihuuser.models import ZhihuUser
from questions.models import UpDownVote,Topic, Notification,\
    UserNotificationCounter
from .models import createNotifications, deleteNotifications, mark_as_read
from questions.forms import addQuestionForm, addReplyForm
from django.shortcuts import redirect

import json

def getQuestionArgs(request,question_id):
    q = get_object_or_404(Question,pk=question_id)
    replies = Reply.objects.filter(question__id=question_id)
    args = dict()
    args['q'] = q
    
    if 'sort' in request.GET:
        newSort = request.GET['sort']
        if newSort == 'created':
            args['replies'] = replies.order_by('create_date')
    else:
        args['replies'] = replies
    
    zhihuuser = request.user.zhihuuser
    args['zhihuuser'] = request.user.zhihuuser
    
    if zhihuuser.questions.filter(pk=question_id).exists():
        args['isfollow'] = True
    else:
        args['isfollow'] = False
    
    for reply in replies:
        if reply.votepeoples.filter(pk=zhihuuser.id).exists():
            updownvote = UpDownVote.objects.get(voteman=zhihuuser,reply=reply)
            reply.updownflag = updownvote.opinions
        else:
            reply.updownflag = 'N'
        reply.save()
    
    if Reply.objects.filter(question=q, author=zhihuuser).exists():
        args['hasReplied'] = True
    else:
        args['hasReplied'] = False
    
    return args

@login_required
def questionShow(request,question_id):
    args = getQuestionArgs(request, question_id)
    args['addReply'] = addReplyForm()
    return render(request, 'questions/question.html', args)

@login_required
def upVoteAnswer(request):
    print '>>>>>>>>upVoteAnswer'
    reply_id = None
    if request.method == 'GET':<commit_msg>fix bug: the question view can also see the message details.<commit_after>from django.shortcuts import render, get_object_or_404
from .models import Question, Reply, Comment
from django.contrib.auth.decorators import login_required
from django.http.response import HttpResponse
from django.db.models import Q
# Create your views here.

from zhihuuser.models import ZhihuUser
from questions.models import UpDownVote,Topic, Notification,\
    UserNotificationCounter
from .models import createNotifications, deleteNotifications, mark_as_read
from questions.forms import addQuestionForm, addReplyForm
from django.shortcuts import redirect

import json

def getQuestionArgs(request,question_id):
    q = get_object_or_404(Question,pk=question_id)
    replies = Reply.objects.filter(question__id=question_id)
    args = dict()
    args['q'] = q
    
    if 'sort' in request.GET:
        newSort = request.GET['sort']
        if newSort == 'created':
            args['replies'] = replies.order_by('create_date')
    else:
        args['replies'] = replies
    
    zhihuuser = request.user.zhihuuser
    args['zhihuuser'] = request.user.zhihuuser
    
    if zhihuuser.questions.filter(pk=question_id).exists():
        args['isfollow'] = True
    else:
        args['isfollow'] = False
    
    for reply in replies:
        if reply.votepeoples.filter(pk=zhihuuser.id).exists():
            updownvote = UpDownVote.objects.get(voteman=zhihuuser,reply=reply)
            reply.updownflag = updownvote.opinions
        else:
            reply.updownflag = 'N'
        reply.save()
    
    if Reply.objects.filter(question=q, author=zhihuuser).exists():
        args['hasReplied'] = True
    else:
        args['hasReplied'] = False

    messages = Notification.objects.filter(notify_to_user__id=zhihuuser.id)
    args['messages'] = messages
    args['message_count'] = UserNotificationCounter.objects.get(pk=zhihuuser.id).unread_count 
    
    return args

@login_required
def questionShow(request,question_id):
    args = getQuestionArgs(request, question_id)
    args['addReply'] = addReplyForm()
    return render(request, 'questions/question.html', args)

@login_required
def upVoteAnswer(request):
    print '>>>>>>>>upVoteAnswer'
    reply_id = None
    if request.method == 'GET':
{'fraction_non_alphanumeric': 0.10326464459365593, 'fraction_numerical': 0.0027784209307710117, 'mean_word_length': 3.6153846153846154, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 19, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4695322', 'n_tokens_mistral': 1344, 'n_tokens_neox': 1302, 'n_words': 285}