<commit_before>import jingo
import urllib
from django.core.paginator import Paginator, EmptyPage, PageNotAnInteger
from django.shortcuts import get_object_or_404
from make_mozilla.projects import models, forms
from make_mozilla import tools


class Index(object):
    def find(self, model, request, field='value'):
        value = request.GET.get(model._meta.verbose_name)
        if value:
            try:
                value = model.objects.get(**dict([[field, value]]))
            except model.DoesNotExist, e:
                value = False
        else:
            value = None
        return value

    def extract_page(self, request):
        return request.GET.get('page', 1)

    def extract_audience(self, request):
        return self.find(models.Audience, request)

    def extract_tool(self, request):
        return self.find(tools.models.Tool, request, 'slug')

    def extract_difficulty(self, request):
        return self.find(models.Difficulty, request)

    def extract_skill(self, request):
        return self.find(models.Skill, request)

    def results(self, audience=None, tool=None, difficulty=None, skill=None):
        query = {}

        if audience is not None:
            query['audience'] = audience
        if tool is not None:
            query['tool'] = tool
        if difficulty is not None:
            query['difficulty'] = difficulty
        if skill is not None:
            query['skills'] = skill

        return models.Project.objects.filter(**query)

    def paginated_results(self, page=1, audience=None, tool=None, difficulty=None, skill=None, results_per_page=8):

        results = self.results(audience, tool, difficulty, skill)
        paginator = Paginator(results, results_per_page)

        try:
            page = paginator.page(page)
        except PageNotAnInteger:
            page = paginator.page(1)
        except EmptyPage:
            page = paginator.page(paginator.num_pages)

        return page

    def __call__(self, request):
        page = self.extract_page(request)
        audience = self.extract_audience(request)
        tool = self.extract_tool(request)
        difficulty = self.extract_difficulty(request)
        skill = self.extract_skill(request)

        featured = models.Project.objects.filter(featured=True)
        pagination = self.paginated_results(page, audience, tool, difficulty, skill)

        invitation = models.Project(
            name='Submit your own project',
            url_hash='submit',
            image='/media/img/submit-your-own.png',)

        projects = list(pagination.object_list)
        projects.append(invitation)

        filter_form = forms.FilterForm({<commit_msg>Pulling in media root from settings Was hardcoded, which may not be a problem, but better to be safe<commit_after>import jingo
import urllib
from django.conf import settings
from django.core.paginator import Paginator, EmptyPage, PageNotAnInteger
from django.shortcuts import get_object_or_404
from make_mozilla.projects import models, forms
from make_mozilla import tools


class Index(object):
    def find(self, model, request, field='value'):
        value = request.GET.get(model._meta.verbose_name)
        if value:
            try:
                value = model.objects.get(**dict([[field, value]]))
            except model.DoesNotExist, e:
                value = False
        else:
            value = None
        return value

    def extract_page(self, request):
        return request.GET.get('page', 1)

    def extract_audience(self, request):
        return self.find(models.Audience, request)

    def extract_tool(self, request):
        return self.find(tools.models.Tool, request, 'slug')

    def extract_difficulty(self, request):
        return self.find(models.Difficulty, request)

    def extract_skill(self, request):
        return self.find(models.Skill, request)

    def results(self, audience=None, tool=None, difficulty=None, skill=None):
        query = {}

        if audience is not None:
            query['audience'] = audience
        if tool is not None:
            query['tool'] = tool
        if difficulty is not None:
            query['difficulty'] = difficulty
        if skill is not None:
            query['skills'] = skill

        return models.Project.objects.filter(**query)

    def paginated_results(self, page=1, audience=None, tool=None, difficulty=None, skill=None, results_per_page=8):

        results = self.results(audience, tool, difficulty, skill)
        paginator = Paginator(results, results_per_page)

        try:
            page = paginator.page(page)
        except PageNotAnInteger:
            page = paginator.page(1)
        except EmptyPage:
            page = paginator.page(paginator.num_pages)

        return page

    def __call__(self, request):
        page = self.extract_page(request)
        audience = self.extract_audience(request)
        tool = self.extract_tool(request)
        difficulty = self.extract_difficulty(request)
        skill = self.extract_skill(request)

        featured = models.Project.objects.filter(featured=True)
        pagination = self.paginated_results(page, audience, tool, difficulty, skill)

        invitation = models.Project(
            name='Submit your own project',
            url_hash='submit',
            image='%simg/submit-your-own.png' % settings.MEDIA_URL,)

        projects = list(pagination.object_list)
        projects.append(invitation)

        filter_form = forms.FilterForm({
{'fraction_non_alphanumeric': 0.0954627949183303, 'fraction_numerical': 0.002540834845735027, 'mean_word_length': 2.6090373280943027, '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': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5261804', 'n_tokens_mistral': 1551, 'n_tokens_neox': 1493, 'n_words': 380}