<commit_before>from django.forms.widgets import ClearableFileInput
from django.utils.safestring import mark_safe
#from django.utils.html import escape
from django.template import Context, Template

class ImageClearableFileInput(ClearableFileInput):
    template_with_initial = u'%(clear_template)s<br />%(input_text)s: %(input)s'

    def __init__(self, size="80x80", attrs=None):
        self.size = size
        super(ImageClearableFileInput, self).__init__(attrs)

    def img_id(self, name):
        return name + "_img_id"

    def render(self, name, value, attrs=None):
        html = super(ImageClearableFileInput, self).render(name, value, attrs)
        t = Template("{% load thumbnail %}{% thumbnail v " + self.size + " %}")
        c = Context({"v": value})
        img = u'<img id="%s" src="%s"/>' % (self.img_id(name), t.render(c))
        img = u'<a href="%s" target="_blank">%s</a>' % (value.url, img)
        html = img + html
        return mark_safe(html)
<commit_msg>* for ImageClearableFileInput --> def __init__(self, thumbnail_size=(80, 80), thumbnail_options={}, attrs=None):<commit_after>from django.forms.widgets import ClearableFileInput
from django.utils.safestring import mark_safe
from easy_thumbnails.files import get_thumbnailer

class ImageClearableFileInput(ClearableFileInput):
    template_with_initial = u'%(clear_template)s<br />%(input_text)s: %(input)s'

    def __init__(self, thumbnail_size=(80, 80), thumbnail_options={}, attrs=None):
        self.thumbnail_size = thumbnail_size
        self.thumbnail_options = thumbnail_options
        super(ImageClearableFileInput, self).__init__(attrs)

    def img_id(self, name):
        return name + "_img_id"

    def render(self, name, value, attrs=None):
        html = super(ImageClearableFileInput, self).render(name, value, attrs)
        opts = self.thumbnail_options.copy()
        opts['size'] = self.thumbnail_size
        img = get_thumbnailer(value).get_thumbnail(opts).tag(id=self.img_id(name))
        img = u'<a href="%s" target="_blank">%s</a>' % (value.url, img)
        html = img + html
        return mark_safe(html)

{'fraction_non_alphanumeric': 0.1352497643732328, 'fraction_numerical': 0.005655042412818096, 'mean_word_length': 4.030805687203792, 'pattern_counts': {'":': 1, '<': 10, '<?xml version=': 0, '>': 11, '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': '1329860', 'n_tokens_mistral': 696, 'n_tokens_neox': 681, 'n_words': 145}