kopia lustrzana https://github.com/wagtail/wagtail
Make get_upload_to an overrideable method of AbstractRendition
rodzic
9cd2bf6447
commit
2de05fb14f
|
@ -0,0 +1,20 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
from __future__ import unicode_literals
|
||||
|
||||
from django.db import models, migrations
|
||||
import wagtail.wagtailimages.models
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('wagtailimages', '0012_copy_image_permissions_to_collections'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.AlterField(
|
||||
model_name='rendition',
|
||||
name='file',
|
||||
field=models.ImageField(upload_to=wagtail.wagtailimages.models.get_rendition_upload_to, width_field='width', height_field='height'),
|
||||
),
|
||||
]
|
|
@ -45,7 +45,24 @@ class ImageQuerySet(SearchableQuerySetMixin, models.QuerySet):
|
|||
|
||||
|
||||
def get_upload_to(instance, filename):
|
||||
# Dumb proxy to instance method.
|
||||
"""
|
||||
Obtain a valid upload path for an image file.
|
||||
|
||||
This needs to be a module-level function so that it can be referenced within migrations,
|
||||
but simply delegates to the `get_upload_to` method of the instance, so that AbstractImage
|
||||
subclasses can override it.
|
||||
"""
|
||||
return instance.get_upload_to(filename)
|
||||
|
||||
|
||||
def get_rendition_upload_to(instance, filename):
|
||||
"""
|
||||
Obtain a valid upload path for an image rendition file.
|
||||
|
||||
This needs to be a module-level function so that it can be referenced within migrations,
|
||||
but simply delegates to the `get_upload_to` method of the instance, so that AbstractRendition
|
||||
subclasses can override it.
|
||||
"""
|
||||
return instance.get_upload_to(filename)
|
||||
|
||||
|
||||
|
@ -439,7 +456,7 @@ class Filter(models.Model):
|
|||
|
||||
class AbstractRendition(models.Model):
|
||||
filter = models.ForeignKey(Filter, related_name='+')
|
||||
file = models.ImageField(upload_to='images', width_field='width', height_field='height')
|
||||
file = models.ImageField(upload_to=get_rendition_upload_to, width_field='width', height_field='height')
|
||||
width = models.IntegerField(editable=False)
|
||||
height = models.IntegerField(editable=False)
|
||||
focal_point_key = models.CharField(max_length=255, blank=True, default='', editable=False)
|
||||
|
@ -480,6 +497,11 @@ class AbstractRendition(models.Model):
|
|||
def __html__(self):
|
||||
return self.img_tag()
|
||||
|
||||
def get_upload_to(self, filename):
|
||||
folder_name = 'images'
|
||||
filename = self.file.field.storage.get_valid_name(filename)
|
||||
return os.path.join(folder_name, filename)
|
||||
|
||||
class Meta:
|
||||
abstract = True
|
||||
|
||||
|
|
Ładowanie…
Reference in New Issue