<commit_before>from django import forms
from django.core.urlresolvers import reverse
from django.forms.widgets import Input
from django.template.loader import render_to_string


class FilemanagerWidget(Input):
    input_type = 'text'

    def __init__(self, attrs={}):
        super(FilemanagerWidget, self).__init__(attrs)
        self.path = attrs.get('path', '')
        if attrs is not None:
            self.attrs = attrs.copy()
        else:
            self.attrs = {}
        super(FilemanagerWidget, self).__init__(attrs)

    def render(self, name, value, attrs=None):
        url = reverse("filemanager:browser")
        if value is None:
            value = ""
        final_attrs = self.build_attrs(attrs, type=self.input_type, name=name)
        final_attrs['url'] = url
        final_attrs['path'] = self.path
        return render_to_string('filemanager/filemanager_field.html', locals())


class FilemanagerFormField(forms.CharField):
    def __init__(self, max_length=None, min_length=None, path=None, *args, **kwargs):
        self.max_length = max_length
        self.min_length = min_length
        self.path = path
        super(FilemanagerFormField, self).__init__(*args, **kwargs)<commit_msg>include filemanager css and js files for widget as media<commit_after>from django import forms
from django.core.urlresolvers import reverse
from django.forms.widgets import Input
from django.template.loader import render_to_string


class FilemanagerWidget(Input):
    input_type = 'text'

    def __init__(self, attrs={}):
        super(FilemanagerWidget, self).__init__(attrs)
        self.path = attrs.get('path', '')
        if attrs is not None:
            self.attrs = attrs.copy()
        else:
            self.attrs = {}
        super(FilemanagerWidget, self).__init__(attrs)

    def render(self, name, value, attrs=None):
        url = reverse("filemanager:browser")
        if value is None:
            value = ""
        final_attrs = self.build_attrs(attrs, type=self.input_type, name=name)
        final_attrs['url'] = url
        final_attrs['path'] = self.path
        return render_to_string('filemanager/filemanager_field.html', locals())

    class Media:
        css = {
            'all': ('css/filemanager.css',),
        }
        js = ('js/filemanager.js',)


class FilemanagerFormField(forms.CharField):
    def __init__(self, max_length=None, min_length=None, path=None, *args, **kwargs):
        self.max_length = max_length
        self.min_length = min_length
        self.path = path
        super(FilemanagerFormField, self).__init__(*args, **kwargs)
{'fraction_non_alphanumeric': 0.11269230769230769, 'fraction_numerical': 0.0, 'mean_word_length': 2.977064220183486, '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': '730210', 'n_tokens_mistral': 756, 'n_tokens_neox': 753, 'n_words': 173}