<commit_before>import logging
import random

from django.conf import settings

from django.http import (HttpResponseRedirect, HttpResponse,
        HttpResponseForbidden, HttpResponseNotFound)

from django.utils import simplejson

from django.shortcuts import get_object_or_404, render_to_response
from django.template import RequestContext
from django.template.defaultfilters import slugify

try:
    from commons.urlresolvers import reverse
except ImportError, e:
    from django.core.urlresolvers import reverse

try:
    from tower import ugettext_lazy as _
except ImportError, e:
    from django.utils.translation import ugettext_lazy as _

from django.views.generic.base import View
from django.views.generic.list_detail import object_list
from django.views.decorators.http import (require_GET, require_POST,
                                          require_http_methods)

from django.contrib import messages

from django.contrib.auth.decorators import login_required
from django.contrib.auth.models import User

try:
    import taggit
    from taggit.models import Tag, TaggedItem
except:
    taggit = None

from .models import (Progress,
        BadgeAwardNotAllowedException)

# TODO: Is there an extensible way to do this, where "add-ons" introduce proxy
# model objects?
try:
    from badger_multiplayer.models import Badge, Award, DeferredAward
except ImportError:
    from badger.models import Badge, Award, DeferredAward

from .forms import (BadgeAwardForm, DeferredAwardGrantForm)

BADGE_PAGE_SIZE = 21
MAX_RECENT = 15


def home(request):
    """Badger home page"""
    badge_list = Badge.objects.order_by('-modified').all()[:MAX_RECENT]
    award_list = Award.objects.order_by('-modified').all()[:MAX_RECENT]
    badge_tags = Badge.objects.top_tags()

    return render_to_response('badger/home.html', dict(
        badge_list=badge_list, award_list=award_list, badge_tags=badge_tags
    ), context_instance=RequestContext(request))


def badges_list(request, tag_name=None):
    """Badges list page"""
    awards_list = None
    query_string = request.GET.get('q', None)
    if query_string is not None:
        sort_order = request.GET.get('sort', 'created')
        queryset = Badge.objects.search(query_string, sort_order)
        # TODO: Is this the most efficient query?
        award_list = (Award.objects.filter(badge__in=queryset))
    elif taggit and tag_name:
        tag = get_object_or_404(Tag, name=tag_name)
        queryset = (Badge.objects.filter(tags__in=[tag]).distinct())
        # TODO: Is this the most efficient query?
        award_list = (Award.objects.filter(badge__in=queryset))
    else:
        queryset = Badge.objects.order_by('-modified').all()
    return object_list(request, queryset,
        paginate_by=BADGE_PAGE_SIZE, allow_empty=True,
        extra_context=dict(
            tag_name=tag_name,
            query_string=query_string,
            award_list=award_list,
        ),
        template_object_name='badge',
        template_name='badger/badges_list.html')


@require_http_methods(['HEAD', 'GET'])
def detail(request, slug, format="html"):
    """Badge detail view"""
    badge = get_object_or_404(Badge, slug=slug)
    if not badge.allows_detail_by(request.user):
        return HttpResponseForbidden('Detail forbidden')
<commit_msg>Bugfix since adding recent awards to badges list<commit_after>import logging
import random

from django.conf import settings

from django.http import (HttpResponseRedirect, HttpResponse,
        HttpResponseForbidden, HttpResponseNotFound)

from django.utils import simplejson

from django.shortcuts import get_object_or_404, render_to_response
from django.template import RequestContext
from django.template.defaultfilters import slugify

try:
    from commons.urlresolvers import reverse
except ImportError, e:
    from django.core.urlresolvers import reverse

try:
    from tower import ugettext_lazy as _
except ImportError, e:
    from django.utils.translation import ugettext_lazy as _

from django.views.generic.base import View
from django.views.generic.list_detail import object_list
from django.views.decorators.http import (require_GET, require_POST,
                                          require_http_methods)

from django.contrib import messages

from django.contrib.auth.decorators import login_required
from django.contrib.auth.models import User

try:
    import taggit
    from taggit.models import Tag, TaggedItem
except:
    taggit = None

from .models import (Progress,
        BadgeAwardNotAllowedException)

# TODO: Is there an extensible way to do this, where "add-ons" introduce proxy
# model objects?
try:
    from badger_multiplayer.models import Badge, Award, DeferredAward
except ImportError:
    from badger.models import Badge, Award, DeferredAward

from .forms import (BadgeAwardForm, DeferredAwardGrantForm)

BADGE_PAGE_SIZE = 21
MAX_RECENT = 15


def home(request):
    """Badger home page"""
    badge_list = Badge.objects.order_by('-modified').all()[:MAX_RECENT]
    award_list = Award.objects.order_by('-modified').all()[:MAX_RECENT]
    badge_tags = Badge.objects.top_tags()

    return render_to_response('badger/home.html', dict(
        badge_list=badge_list, award_list=award_list, badge_tags=badge_tags
    ), context_instance=RequestContext(request))


def badges_list(request, tag_name=None):
    """Badges list page"""
    award_list = None
    query_string = request.GET.get('q', None)
    if query_string is not None:
        sort_order = request.GET.get('sort', 'created')
        queryset = Badge.objects.search(query_string, sort_order)
        # TODO: Is this the most efficient query?
        award_list = (Award.objects.filter(badge__in=queryset))
    elif taggit and tag_name:
        tag = get_object_or_404(Tag, name=tag_name)
        queryset = (Badge.objects.filter(tags__in=[tag]).distinct())
        # TODO: Is this the most efficient query?
        award_list = (Award.objects.filter(badge__in=queryset))
    else:
        queryset = Badge.objects.order_by('-modified').all()
    return object_list(request, queryset,
        paginate_by=BADGE_PAGE_SIZE, allow_empty=True,
        extra_context=dict(
            tag_name=tag_name,
            query_string=query_string,
            award_list=award_list,
        ),
        template_object_name='badge',
        template_name='badger/badges_list.html')


@require_http_methods(['HEAD', 'GET'])
def detail(request, slug, format="html"):
    """Badge detail view"""
    badge = get_object_or_404(Badge, slug=slug)
    if not badge.allows_detail_by(request.user):
        return HttpResponseForbidden('Detail forbidden')

{'fraction_non_alphanumeric': 0.08833283087126922, 'fraction_numerical': 0.003919204100090443, 'mean_word_length': 3.907544378698225, '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': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7270597', 'n_tokens_mistral': 2023, 'n_tokens_neox': 1995, 'n_words': 483}