'Name of the file on the client file system, but normalized to ensure
file system compatibility. An empty filename is returned as \'empty\'.
Only ASCII letters, digits, dashes, underscores and dots are
allowed in the final filename. Accents are removed, if possible.
Whitespace is replaced by a single dash. Leading or tailing dots
or dashes are removed. The filename is limited to 255 characters.'

@cached_property
def filename(self):

    fname = self.raw_filename
    if (not isinstance(fname, unicode)):
        fname = fname.decode('utf8', 'ignore')
    fname = normalize('NFKD', fname)
    fname = fname.encode('ASCII', 'ignore').decode('ASCII')
    fname = os.path.basename(fname.replace('\\', os.path.sep))
    fname = re.sub('[^a-zA-Z0-9-_.\\s]', '', fname).strip()
    fname = re.sub('[-\\s]+', '-', fname).strip('.-')
    return (fname[:255] or 'empty')
