# -*- coding: utf-8 -*-

from django import forms
from django.utils.translation import ugettext_lazy as _
from django.utils.safestring import mark_safe

class FileInput(forms.FileInput):
    already = _(u'Déjà reçu :')
    modify = _(u'Pour le remplacer :')
    after = _(u"""
            En cas de document papier, n'envoyez aucun document ici.
            """)

    def render(self, name, value, attrs=None):
        if value:
            before = u'%(already)s <em>%(value)s</em><br />%(modify)s ' % {
                        'already': self.already,
                        'value': value,
                        'modify': self.modify,
                    }
            after = ''
        else:
            before = ''
            after = u'<br />%s' % self.after
        widget = super(FileInput, self).render(name, None, attrs=attrs)
        return mark_safe(u'%s%s%s' % (before, widget, after))

