<commit_before>from flask import Blueprint, render_template
from markupsafe import Markup

from mass_flask_config.app import app
from mass_flask_core.models import Sample, FileSample, IPSample, DomainSample, URISample, ExecutableBinarySample, Report
from mass_flask_core.utils.pagination_functions import paginate

webui_blueprint = Blueprint('mass_flask_webui', __name__, template_folder='templates', static_folder='static')

webui_blueprint.config = {
}


@webui_blueprint.route('/')
def index():
    index_context = {
        'latest_samples': Sample.objects().limit(10),
        'latest_reports': Report.objects().limit(10),
        'count_sample': Sample.objects().count(),
        'count_file_sample': FileSample.objects.count(),
        'count_executable_binary_sample': ExecutableBinarySample.objects().count(),
        'count_ip_sample': IPSample.objects().count(),
        'count_domain_sample': DomainSample.objects().count(),
        'count_uri_sample': URISample.objects().count()
    }

    return render_template('index.html', **index_context)


@paginate(per_page=100)
def get_samples_paginated():
    return Sample.objects()


@webui_blueprint.route('/sample/')
def sample_list():
    samples = get_samples_paginated()
    return render_template('sample_list.html', samples=samples)


@webui_blueprint.route('/sample/<sample_id>/')
def sample_detail(sample_id):
    sample = Sample.objects(id=sample_id).first()
    reports = Report.objects(sample=sample)
    return render_template('sample_detail.html', sample=sample, reports=reports)


@webui_blueprint.context_processor<commit_msg>Moving Pagination from API to core since it is a shared function for both API and webui<commit_after>from flask import Blueprint, render_template
from markupsafe import Markup

from mass_flask_config.app import app
from mass_flask_core.models import Sample, FileSample, IPSample, DomainSample, URISample, ExecutableBinarySample, Report
from mass_flask_core.utils import PaginationFunctions

webui_blueprint = Blueprint('mass_flask_webui', __name__, template_folder='templates', static_folder='static')

webui_blueprint.config = {
}


@webui_blueprint.route('/')
def index():
    index_context = {
        'latest_samples': Sample.objects().limit(10),
        'latest_reports': Report.objects().limit(10),
        'count_sample': Sample.objects().count(),
        'count_file_sample': FileSample.objects.count(),
        'count_executable_binary_sample': ExecutableBinarySample.objects().count(),
        'count_ip_sample': IPSample.objects().count(),
        'count_domain_sample': DomainSample.objects().count(),
        'count_uri_sample': URISample.objects().count()
    }

    return render_template('index.html', **index_context)


@PaginationFunctions.paginate(per_page=100)
def get_samples_paginated():
    return Sample.objects()


@webui_blueprint.route('/sample/')
def sample_list():
    samples = get_samples_paginated()
    return render_template('sample_list.html', samples=samples)


@webui_blueprint.route('/sample/<sample_id>/')
def sample_detail(sample_id):
    sample = Sample.objects(id=sample_id).first()
    reports = Report.objects(sample=sample)
    return render_template('sample_detail.html', sample=sample, reports=reports)


@webui_blueprint.context_processor
{'fraction_non_alphanumeric': 0.12104622871046229, 'fraction_numerical': 0.004257907542579075, 'mean_word_length': 5.5648702594810375, 'pattern_counts': {'":': 0, '<': 5, '<?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': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2943321', 'n_tokens_mistral': 1004, 'n_tokens_neox': 965, 'n_words': 177}