File helpers

barbeque.files.upload_to_path(base_path, attr=None, uuid_filename=False)

Returns a callback suitable as upload_to argument for Django’s FileField.

Parameters:
  • base_path – Base folder structure for uploaded files. Note that you cannot use strftime placeholders here.
  • attr – Attribute to use for base path generation.
  • uuid_filename – Render file names as UUIDs.

Usage:

class Picture(models.Model):
    image = models.ImageField(_('Image'), upload_to=upload_to_path('uploads/images/'))

Use attr for base path generation:

class Picture(models.Model):
    image = models.ImageField(
        _('Image'),
        upload_to=upload_to_path('uploads/%s/images/', attr='category.name')
    )
    category = models.ForeignKey(Category)
class barbeque.files.MoveableNamedTemporaryFile(name)

Wraps NamedTemporaryFile() and implements chunks, close and temporary_file_path on top of it.

Suitable for the django storage system to allow files to simply get moved to it’s final location instead of copying the file-contents.