<commit_before>from django.shortcuts import render, redirect, resolve_url, HttpResponse

from testcube.settings import logger
from .forms import AnalysisForm
from .models import TestRun, ObjectSource
from ..utils import read_document


def index(request):
    if TestRun.objects.count() > 0:
        return redirect(resolve_url('runs'))
    else:
        return redirect(resolve_url('welcome'))


def welcome(request):
    logger.debug('visit welcome view.')
    return render(request, 'welcome.html')


def document(request, name):
    content = read_document(name)
    return render(request, 'document.html', {'content': content, 'name': name})


def runs(request):
    return render(request, 'runs.html')


def cases(request):
    return render(request, 'testcases.html')


def results(request):
    return render(request, 'results.html')


def run_detail(request, run_id):
    if request.method == 'GET':
        outcome = request.GET.get('outcome', default='')
        source = ObjectSource.objects.filter(testrun__id=run_id).first()
        return render(request, 'run_detail.html', {'run_id': run_id,
                                                   'outcome': outcome,
                                                   'source': source})


def case_detail(request, case_id):
    if request.method == 'GET':
        return render(request, 'testcase_detail.html', {'case_id': case_id})


def result_detail(request, result_id):
    result_id = int(result_id)

    if request.method == 'POST':
        form = AnalysisForm(data=request.POST)
        form.by_post = True

        if form.is_valid():
            if request.user.is_authenticated():
                form.save(result_id, request.user.username)
            else:
                form.add_error('description', 'Login required.')

        if form.errors:
            errors = [m[0] for e, m in form.errors.items()]
            message = ', '.join(errors)
            return HttpResponse(content=message, status=400)
        else:
            return HttpResponse(content='Analyzed just now.')

    else:
        form = AnalysisForm()
        form.load(result_id)

    return render(request, 'result_detail.html', {'result_id': result_id, 'form': form})
<commit_msg>able to redirect run from source link.<commit_after>from django.shortcuts import render, redirect, resolve_url, HttpResponse, reverse

from testcube.settings import logger
from .forms import AnalysisForm
from .models import TestRun, ObjectSource
from ..utils import read_document


def index(request):
    if TestRun.objects.count() > 0:
        return redirect(resolve_url('runs'))
    else:
        return redirect(resolve_url('welcome'))


def welcome(request):
    logger.debug('visit welcome view.')
    return render(request, 'welcome.html')


def document(request, name):
    content = read_document(name)
    return render(request, 'document.html', {'content': content, 'name': name})


def runs(request):
    source = request.GET.get('source', default=None)
    if source:
        found = ObjectSource.objects.filter(link__contains=source).first()
        if found:
            return redirect('/runs/{}'.format(found.testrun.id))

    return render(request, 'runs.html')


def cases(request):
    return render(request, 'testcases.html')


def results(request):
    return render(request, 'results.html')


def run_detail(request, run_id):
    if request.method == 'GET':
        source = ObjectSource.objects.filter(testrun__id=run_id).first()
        return render(request, 'run_detail.html', {'run_id': run_id,
                                                   'source': source})


def case_detail(request, case_id):
    if request.method == 'GET':
        return render(request, 'testcase_detail.html', {'case_id': case_id})


def result_detail(request, result_id):
    result_id = int(result_id)

    if request.method == 'POST':
        form = AnalysisForm(data=request.POST)
        form.by_post = True

        if form.is_valid():
            if request.user.is_authenticated():
                form.save(result_id, request.user.username)
            else:
                form.add_error('description', 'Login required.')

        if form.errors:
            errors = [m[0] for e, m in form.errors.items()]
            message = ', '.join(errors)
            return HttpResponse(content=message, status=400)
        else:
            return HttpResponse(content='Analyzed just now.')

    else:
        form = AnalysisForm()
        form.load(result_id)

    return render(request, 'result_detail.html', {'result_id': result_id, 'form': form})

{'fraction_non_alphanumeric': 0.12236011321576312, 'fraction_numerical': 0.002177226213803614, 'mean_word_length': 2.8092868988391375, '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': 6, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5751029', 'n_tokens_mistral': 1321, 'n_tokens_neox': 1280, 'n_words': 317}