<commit_before>from collections import OrderedDict

from django.http import HttpResponse, Http404
from django.shortcuts import render, get_object_or_404
from django.views.generic import ListView, DetailView

from ci.models import Project, Commit
from ci.plugins import BUILD_HOOKS
from ci.tasks import execute_build


def get_project_by_slug(slug):
    return get_object_or_404(Project, slug=slug)


def build_hook(request, project_slug, hook_type):
    project = get_project_by_slug(project_slug)
    if hook_type not in BUILD_HOOKS:
        raise Http404
    hook = BUILD_HOOKS[hook_type](request)
    branches = {branch: project.commits.create(branch=branch)
                for branch in hook.get_changed_branches()}
    for build_config in project.configurations.all():
        for branch, commit in branches.iteritems():
            if build_config.should_build_branch(branch):
                build = commit.builds.create(configuration=build_config)
                execute_build.delay(build.id, build_config.builder)
    return HttpResponse()


class ProjectList(ListView):<commit_msg>Don't use CSRF protection for buildhooks<commit_after>from collections import OrderedDict

from django.http import HttpResponse, Http404
from django.shortcuts import render, get_object_or_404
from django.views.generic import ListView, DetailView
from django.views.decorators.csrf import csrf_exempt

from ci.models import Project, Commit
from ci.plugins import BUILD_HOOKS
from ci.tasks import execute_build


def get_project_by_slug(slug):
    return get_object_or_404(Project, slug=slug)


@csrf_exempt
def build_hook(request, project_slug, hook_type):
    project = get_project_by_slug(project_slug)
    if hook_type not in BUILD_HOOKS:
        raise Http404
    hook = BUILD_HOOKS[hook_type](request)
    branches = {branch: project.commits.create(branch=branch)
                for branch in hook.get_changed_branches()}
    for build_config in project.configurations.all():
        for branch, commit in branches.iteritems():
            if build_config.should_build_branch(branch):
                build = commit.builds.create(configuration=build_config)
                execute_build.delay(build.id, build_config.builder)
    return HttpResponse()


class ProjectList(ListView):
{'fraction_non_alphanumeric': 0.07064501974550241, 'fraction_numerical': 0.010530934620447565, 'mean_word_length': 4.205479452054795, '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': '3039206', 'n_tokens_mistral': 687, 'n_tokens_neox': 669, 'n_words': 165}