@spam.global_handler('FileField')  # ImageField's internal type is FileField
def random_file(record, field):
    """
    For your convinience, all files and images generated by Dilla
    will have ``dilla_`` prefix.

    For ImageFields this handler will generate images using PIL.
    Since it is required by Django to have PIL installed when
    using ImageFields, there is no point in providing
    alternate routine other than lazy import.
    """
    #destination = os.path.join(field.storage.location, field.upload_to)
    #if not os.path.exists(destination):
    #    os.makedirs(destination)

    def _random_image(field):
        log.debug("Generating identicon image")
        from identicon import identicon
        name = random_slug(record, field) % "dilla_%s.png"
        icon = identicon.render_identicon( \
                random.randint(5 ** 5, 10 ** 10), \
                random.randint(64, 250))
        # using storage
        tmp_file = StringIO()
        icon.save(tmp_file, 'PNG')
        name = field.generate_filename(record.obj, name)
        saved_name = field.storage.save(name, ContentFile(tmp_file.getvalue()))
        return saved_name

    def _random_textfile(field):
        log.debug("Generating text file")
        name = "dilla_%s.txt" % random_slug(record, field)
        name = field.generate_filename(record.obj, name)
        saved_name = field.storage.save(name, ContentFile(_random_words(10)))
        return saved_name

    try:
        from django.db.models import ImageField
        if isinstance(field, ImageField):
            return _random_image(field)
        return _random_textfile(field)
    except ImportError, e:
        log.warn(e)
        return _random_textfile(field)
dataset/ETHPy150Open aerosol/django-dilla/dilla/spammers.py/random_file/swapped operands of `%`