<commit_before>import typing

from django import template
from django.urls import reverse

from projects.project_models import Project
from projects.source_item_models import DirectoryListEntry, DirectoryEntryType
from projects.source_models import DiskFileSource

register = template.Library()


@register.simple_tag
def source_path(project: Project, directory_entry: DirectoryListEntry):
    if directory_entry.is_directory and directory_entry.path:
        view_name = 'project_files_path'
        view_args = project.pk, directory_entry.path
        return reverse(view_name, args=view_args)

    if directory_entry.type == DirectoryEntryType.FILE:
        if isinstance(directory_entry.source, DiskFileSource):
            return reverse('real_file_source_open', args=(project.pk, directory_entry.path))
        else:
            return reverse('file_source_open', args=(project.pk, directory_entry.source.pk, directory_entry.path))

    return ""


@register.filter
def is_text_editable(directory_entry: typing.Any):
    if not isinstance(directory_entry, DirectoryListEntry):
        return False

    directory_entry = typing.cast(DirectoryListEntry, directory_entry)

    if directory_entry.is_directory or not directory_entry.mimetype:
        return False

    return directory_entry.mimetype == 'Unknown' or (
                '/' in directory_entry.mimetype and directory_entry.mimetype.split('/')[0] == 'text')<commit_msg>fix: Made javascript files editable<commit_after>import typing

from django import template
from django.urls import reverse

from projects.project_models import Project
from projects.source_item_models import DirectoryListEntry, DirectoryEntryType
from projects.source_models import DiskFileSource

register = template.Library()


@register.simple_tag
def source_path(project: Project, directory_entry: DirectoryListEntry):
    if directory_entry.is_directory and directory_entry.path:
        view_name = 'project_files_path'
        view_args = project.pk, directory_entry.path
        return reverse(view_name, args=view_args)

    if directory_entry.type == DirectoryEntryType.FILE:
        if isinstance(directory_entry.source, DiskFileSource):
            return reverse('real_file_source_open', args=(project.pk, directory_entry.path))
        else:
            return reverse('file_source_open', args=(project.pk, directory_entry.source.pk, directory_entry.path))

    return ""


def mimetype_text_editable(mimetype: str) -> bool:
    if mimetype in ('Unknown', 'application/javascript'):
        return True

    return '/' in mimetype and mimetype.split('/')[0] == 'text'


@register.filter
def is_text_editable(directory_entry: typing.Any) -> bool:
    if not isinstance(directory_entry, DirectoryListEntry):
        return False

    directory_entry = typing.cast(DirectoryListEntry, directory_entry)

    if directory_entry.is_directory or not directory_entry.mimetype:
        return False

    return mimetype_text_editable(directory_entry.mimetype)
{'fraction_non_alphanumeric': 0.08066666666666666, 'fraction_numerical': 0.0006666666666666666, 'mean_word_length': 4.476277372262774, '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': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3305997', 'n_tokens_mistral': 838, 'n_tokens_neox': 801, 'n_words': 192}