<commit_before>import logging
import random

from django.conf import settings

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

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 funfactory.urlresolvers import (get_url_prefix, Prefixer, reverse,
                                         set_url_prefix)
    from tower import activate
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.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

import badger
from badger import settings as bsettings
from .models import (Badge, Award, Nomination, DeferredAward,
                     Progress, BadgeAwardNotAllowedException,
                     BadgeAlreadyAwardedException, BadgePrerequisitesNotFullfilledException,
                     BadgeRetiredException,
                     NominationApproveNotAllowedException,
                     NominationAcceptNotAllowedException)
from .forms import (BadgeAwardForm, DeferredAwardGrantForm,
                    DeferredAwardMultipleGrantForm, BadgeNewForm,
                    BadgeEditForm, BadgeSubmitNominationForm)


def home(request):
    """Badger home page"""
    badge_list = Badge.objects.order_by('-modified').all()
    completed_prereqs =[]
    uncompleted_prereqs =[]
    for badge in badge_list:
        if badge.is_awarded_to(request.user):
            completed_prereqs.append(badge)
        else:    
            uncompleted_prereqs.append(badge)
    progresses=Progress.objects.filter(user=request.user)
    progs=[]
    for progress in progresses:
        if progress.percent > .66:
            progs.append(progress.badge)
    return render_to_response('%s/home.html' % bsettings.TEMPLATE_BASE, dict(
        uncompleted_prereqs=uncompleted_prereqs, completed_prereqs=completed_prereqs, badge_list=badge_list, progress=progs, request=request, 
    ), context_instance=RequestContext(request))

@login_required
def your_badges(request):
    user = get_object_or_404(User, username=request.user.username)
    nominations= Nomination.objects.filter(nominee=user)
    created = Badge.objects.filter(creator=user)
    awards = Award.objects.filter(user=user)
    return render_to_response('%s/your_badges.html' % bsettings.TEMPLATE_BASE, dict(
        award_list=awards, count=awards.count(), badges_list=created, request=request, user=user, nominations=nominations,
    ), 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())<commit_msg>Fixed a bug where created badges weren't showing up on the your badges page<commit_after>import logging
import random

from django.conf import settings

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

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 funfactory.urlresolvers import (get_url_prefix, Prefixer, reverse,
                                         set_url_prefix)
    from tower import activate
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.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

import badger
from badger import settings as bsettings
from .models import (Badge, Award, Nomination, DeferredAward,
                     Progress, BadgeAwardNotAllowedException,
                     BadgeAlreadyAwardedException, BadgePrerequisitesNotFullfilledException,
                     BadgeRetiredException,
                     NominationApproveNotAllowedException,
                     NominationAcceptNotAllowedException)
from .forms import (BadgeAwardForm, DeferredAwardGrantForm,
                    DeferredAwardMultipleGrantForm, BadgeNewForm,
                    BadgeEditForm, BadgeSubmitNominationForm)
from labgeeks_people.models import UserProfile

def home(request):
    """Badger home page"""
    badge_list = Badge.objects.order_by('-modified').all()
    completed_prereqs =[]
    uncompleted_prereqs =[]
    for badge in badge_list:
        if badge.is_awarded_to(request.user):
            completed_prereqs.append(badge)
        else:    
            uncompleted_prereqs.append(badge)
    progresses=Progress.objects.filter(user=request.user)
    progs=[]
    for progress in progresses:
        if progress.percent > .66:
            progs.append(progress.badge)
    return render_to_response('%s/home.html' % bsettings.TEMPLATE_BASE, dict(
        uncompleted_prereqs=uncompleted_prereqs, completed_prereqs=completed_prereqs, badge_list=badge_list, progress=progs, request=request, 
    ), context_instance=RequestContext(request))

@login_required
def your_badges(request):
    user = get_object_or_404(User, username=request.user.username)
    nominations= Nomination.objects.filter(nominee=user)
    created = Badge.objects.filter(creator=user)
    awards = Award.objects.filter(user=user)
    return render_to_response('%s/your_badges.html' % bsettings.TEMPLATE_BASE, dict(
        award_list=awards, count=awards.count(), badge_list=created, request=request, user=user, nominations=nominations,
    ), 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())
{'fraction_non_alphanumeric': 0.07652451175767237, 'fraction_numerical': 0.0037199415437757406, 'mean_word_length': 3.5077844311377246, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, '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': '6150715', 'n_tokens_mistral': 2197, 'n_tokens_neox': 2141, 'n_words': 478}