<commit_before>from django.conf import settings
from django.views.static import serve
from django.http import HttpResponse
from django.views.decorators.csrf import csrf_view_exempt

import json
import os

from projects.models import Project
from projects.tasks import update_docs
from projects.utils import get_project_path, find_file


@csrf_view_exempt
def github_build(request):
    obj = json.loads(request.POST['payload'])
    name = obj['repository']['name']
    url = obj['repository']['url']
    project = Project.objects.get(github_repo=url)
    update_docs.delay(slug=project.slug)
    return HttpResponse('Build Started')

def serve_docs(request, username, project_slug, filename="index.html"):
    proj = Project.objects.get(slug=project_slug, user__username=username)
    project = proj.slug
    path = get_project_path(proj)
    filename = filename.rstrip('/')

    doc_base = os.path.join(path, project)
    for possible_path in ['docs', 'doc']:
        if os.path.exists( os.path.join(doc_base, '%s/build/html' % possible_path)):
            final_path = os.path.join(doc_base, '%s/build/html' % possible_path) 
        elif os.path.exists( os.path.join(doc_base, '%s/_build/html' % possible_path)):
            final_path = os.path.join(doc_base, '%s/_build/html' % possible_path) 
        elif os.path.exists( os.path.join(doc_base, '%s/.build/html' % possible_path)):
            final_path = os.path.join(doc_base, '%s/.build/html' % possible_path) 
    return serve(request, filename, final_path)
<commit_msg>Simplify looking for doc paths.<commit_after>from django.conf import settings
from django.views.static import serve
from django.http import HttpResponse
from django.views.decorators.csrf import csrf_view_exempt

import json
import os

from projects.models import Project
from projects.tasks import update_docs
from projects.utils import get_project_path, find_file


@csrf_view_exempt
def github_build(request):
    obj = json.loads(request.POST['payload'])
    name = obj['repository']['name']
    url = obj['repository']['url']
    project = Project.objects.get(github_repo=url)
    update_docs.delay(slug=project.slug)
    return HttpResponse('Build Started')

def serve_docs(request, username, project_slug, filename="index.html"):
    proj = Project.objects.get(slug=project_slug, user__username=username)
    project = proj.slug
    path = get_project_path(proj)
    filename = filename.rstrip('/')

    doc_base = os.path.join(path, project)
    for possible_path in ['docs', 'doc']:
        for pos_build in ['build', '_build', '.build']:
            if os.path.exists(os.path.join(doc_base, '%s/%s/html' % (possible_path, pos_build))):
                final_path = os.path.join(doc_base, '%s/%s/html' % (possible_path, pos_build))
                return serve(request, filename, final_path)

{'fraction_non_alphanumeric': 0.12402826855123675, 'fraction_numerical': 0.0, 'mean_word_length': 4.194495412844037, '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': '6364703', 'n_tokens_mistral': 882, 'n_tokens_neox': 882, 'n_words': 195}