<commit_before>import json
import logging
import random
import time
from datetime import date, datetime, timedelta

from django.conf import settings
from django.contrib import auth
from django.contrib import messages
from django.contrib.auth.forms import AuthenticationForm
from django.contrib.contenttypes.models import ContentType
from django.contrib.sites.models import Site
from django.core.cache import cache
from django.core.exceptions import PermissionDenied
from django.core.paginator import EmptyPage, PageNotAnInteger
from django.db.models import Q
from django.http import (HttpResponseRedirect, HttpResponse, Http404,
                         HttpResponseBadRequest, HttpResponseForbidden)
from django.shortcuts import get_object_or_404, render
from django.views.decorators.csrf import csrf_exempt
from django.views.decorators.http import (require_POST, require_GET,
                                          require_http_methods)

import jingo
import waffle
from mobility.decorators import mobile_template
from ratelimit.decorators import ratelimit
from session_csrf import anonymous_csrf
from statsd import statsd
from taggit.models import Tag
from tidings.events import ActivationRequestFailed
from tidings.models import Watch
from tower import ugettext as _, ugettext_lazy as _lazy

from access.decorators import (has_perm_or_owns_or_403, permission_required,
                               login_required)
from karma.manager import KarmaManager
from products.models import Product
import questions as constants
from questions.events import QuestionReplyEvent, QuestionSolvedEvent
from questions.feeds import QuestionsFeed, AnswersFeed, TaggedQuestionsFeed
from questions.forms import (NewQuestionForm, EditQuestionForm, AnswerForm,
                             WatchQuestionForm, FREQUENCY_CHOICES,
                             MarketplaceAaqForm, StatsForm)
from questions.karma_actions import (SolutionAction, AnswerMarkedHelpfulAction,
                                     AnswerMarkedNotHelpfulAction)
from questions.marketplace import (MARKETPLACE_CATEGORIES, submit_ticket,
                                   ZendeskError)
from questions.models import Question, Answer, QuestionVote, AnswerVote
from questions.question_config import products
from search.utils import locale_or_default, clean_excerpt
from search.es_utils import (ESTimeoutError, ESMaxRetryError, ESException,
                             Sphilastic, F)
from sumo.helpers import urlparams
from sumo.urlresolvers import reverse
from sumo.utils import paginate, simple_paginate, build_paged_url, user_or_ip
from tags.utils import add_existing_tag
from topics.models import Topic
from upload.models import ImageAttachment
from upload.views import upload_imageattachment
from users.forms import RegisterForm
from users.models import Setting
from users.utils import handle_login, handle_register
from wiki.models import Document
from wiki.facets import documents_for


log = logging.getLogger('k.questions')


UNAPPROVED_TAG = _lazy(u'That tag does not exist.')
NO_TAG = _lazy(u'Please provide a tag.')


@mobile_template('questions/{mobile/}questions.html')
def questions(request, template):
    """View the questions."""

    filter_ = request.GET.get('filter')
    tagged = request.GET.get('tagged')
    tags = None
    sort_ = request.GET.get('sort', None)
    product_slug = request.GET.get('product')
    topic_slug = request.GET.get('topic')

    if sort_ == 'requested':
        order = ['-num_votes_past_week', '-_num_votes']
    elif sort_ == 'created':
        order = ['-created']
    else:
        order = ['-updated']

    if product_slug:
        product = get_object_or_404(Product, slug=product_slug)
    else:
        product = None

    if topic_slug:
        topic = get_object_or_404(Topic, slug=topic_slug)
    else:
        topic = None

    question_qs = Question.objects.select_related(
        'creator', 'last_answer', 'last_answer__creator')

    if (not waffle.switch_is_active('hide-total-question-votes') or
        sort_ == 'requested'):
            question_qs = question_qs.extra(
                {'_num_votes': 'SELECT COUNT(*) FROM questions_questionvote WHERE '
                               'questions_questionvote.question_id = '
                               'questions_question.id'})

    question_qs = question_qs.filter(creator__is_active=1)

    if filter_ == 'no-replies':
        question_qs = question_qs.filter(num_answers=0, is_locked=False)
    elif filter_ == 'replies':
        question_qs = question_qs.filter(num_answers__gt=0)
    elif filter_ == 'solved':
        question_qs = question_qs.exclude(solution=None)
    elif filter_ == 'unsolved':
        question_qs = question_qs.filter(solution=None)
    elif filter_ == 'my-contributions' and request.user.is_authenticated():
        criteria = Q(answers__creator=request.user) | Q(creator=request.user)
        question_qs = question_qs.filter(criteria).distinct()
    elif filter_ == 'recent-unanswered':
        # Only unanswered questions from the last 72 hours.
        start = datetime.now() - timedelta(hours=72)
        question_qs = question_qs.filter(
            num_answers=0, created__gt=start, is_locked=False)
    else:
        filter_ = None<commit_msg>This flag (hide-total-question-votes) is gone.<commit_after>import json
import logging
import random
import time
from datetime import date, datetime, timedelta

from django.conf import settings
from django.contrib import auth
from django.contrib import messages
from django.contrib.auth.forms import AuthenticationForm
from django.contrib.contenttypes.models import ContentType
from django.contrib.sites.models import Site
from django.core.cache import cache
from django.core.exceptions import PermissionDenied
from django.core.paginator import EmptyPage, PageNotAnInteger
from django.db.models import Q
from django.http import (HttpResponseRedirect, HttpResponse, Http404,
                         HttpResponseBadRequest, HttpResponseForbidden)
from django.shortcuts import get_object_or_404, render
from django.views.decorators.csrf import csrf_exempt
from django.views.decorators.http import (require_POST, require_GET,
                                          require_http_methods)

import jingo
import waffle
from mobility.decorators import mobile_template
from ratelimit.decorators import ratelimit
from session_csrf import anonymous_csrf
from statsd import statsd
from taggit.models import Tag
from tidings.events import ActivationRequestFailed
from tidings.models import Watch
from tower import ugettext as _, ugettext_lazy as _lazy

from access.decorators import (has_perm_or_owns_or_403, permission_required,
                               login_required)
from karma.manager import KarmaManager
from products.models import Product
import questions as constants
from questions.events import QuestionReplyEvent, QuestionSolvedEvent
from questions.feeds import QuestionsFeed, AnswersFeed, TaggedQuestionsFeed
from questions.forms import (NewQuestionForm, EditQuestionForm, AnswerForm,
                             WatchQuestionForm, FREQUENCY_CHOICES,
                             MarketplaceAaqForm, StatsForm)
from questions.karma_actions import (SolutionAction, AnswerMarkedHelpfulAction,
                                     AnswerMarkedNotHelpfulAction)
from questions.marketplace import (MARKETPLACE_CATEGORIES, submit_ticket,
                                   ZendeskError)
from questions.models import Question, Answer, QuestionVote, AnswerVote
from questions.question_config import products
from search.utils import locale_or_default, clean_excerpt
from search.es_utils import (ESTimeoutError, ESMaxRetryError, ESException,
                             Sphilastic, F)
from sumo.helpers import urlparams
from sumo.urlresolvers import reverse
from sumo.utils import paginate, simple_paginate, build_paged_url, user_or_ip
from tags.utils import add_existing_tag
from topics.models import Topic
from upload.models import ImageAttachment
from upload.views import upload_imageattachment
from users.forms import RegisterForm
from users.models import Setting
from users.utils import handle_login, handle_register
from wiki.models import Document
from wiki.facets import documents_for


log = logging.getLogger('k.questions')


UNAPPROVED_TAG = _lazy(u'That tag does not exist.')
NO_TAG = _lazy(u'Please provide a tag.')


@mobile_template('questions/{mobile/}questions.html')
def questions(request, template):
    """View the questions."""

    filter_ = request.GET.get('filter')
    tagged = request.GET.get('tagged')
    tags = None
    sort_ = request.GET.get('sort', None)
    product_slug = request.GET.get('product')
    topic_slug = request.GET.get('topic')

    if sort_ == 'requested':
        order = ['-num_votes_past_week', '-_num_votes']
    elif sort_ == 'created':
        order = ['-created']
    else:
        order = ['-updated']

    if product_slug:
        product = get_object_or_404(Product, slug=product_slug)
    else:
        product = None

    if topic_slug:
        topic = get_object_or_404(Topic, slug=topic_slug)
    else:
        topic = None

    question_qs = Question.objects.select_related(
        'creator', 'last_answer', 'last_answer__creator')

    question_qs = question_qs.extra(
        {'_num_votes': 'SELECT COUNT(*) FROM questions_questionvote WHERE '
                       'questions_questionvote.question_id = '
                       'questions_question.id'})

    question_qs = question_qs.filter(creator__is_active=1)

    if filter_ == 'no-replies':
        question_qs = question_qs.filter(num_answers=0, is_locked=False)
    elif filter_ == 'replies':
        question_qs = question_qs.filter(num_answers__gt=0)
    elif filter_ == 'solved':
        question_qs = question_qs.exclude(solution=None)
    elif filter_ == 'unsolved':
        question_qs = question_qs.filter(solution=None)
    elif filter_ == 'my-contributions' and request.user.is_authenticated():
        criteria = Q(answers__creator=request.user) | Q(creator=request.user)
        question_qs = question_qs.filter(criteria).distinct()
    elif filter_ == 'recent-unanswered':
        # Only unanswered questions from the last 72 hours.
        start = datetime.now() - timedelta(hours=72)
        question_qs = question_qs.filter(
            num_answers=0, created__gt=start, is_locked=False)
    else:
        filter_ = None
{'fraction_non_alphanumeric': 0.07378622145461523, 'fraction_numerical': 0.004413740165035502, 'mean_word_length': 3.595679012345679, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 8, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7283952', 'n_tokens_mistral': 2963, 'n_tokens_neox': 2851, 'n_words': 765}