default/upload_to=lambda breaks migrations, use functions
This commit is contained in:
parent
e22cc432b3
commit
5d63ad1760
6 changed files with 38 additions and 21 deletions
|
@ -23,6 +23,9 @@ from person.models import get_name_sort
|
|||
from chunk import save_chunk
|
||||
import extract
|
||||
|
||||
def get_path(f, x): return f.path(x)
|
||||
def get_data_path(f, x): return get_path(f, 'data.bin')
|
||||
|
||||
class File(models.Model):
|
||||
AV_INFO = (
|
||||
'duration', 'video', 'audio', 'oshash', 'size',
|
||||
|
@ -89,7 +92,7 @@ class File(models.Model):
|
|||
|
||||
#upload and data handling
|
||||
data = models.FileField(null=True, blank=True,
|
||||
upload_to=lambda f, x: f.get_path('data.bin'))
|
||||
upload_to=get_data_path)
|
||||
|
||||
def __unicode__(self):
|
||||
return self.path
|
||||
|
@ -565,6 +568,9 @@ class Volume(models.Model):
|
|||
'items': self.files.count()
|
||||
}
|
||||
|
||||
def inttime():
|
||||
return int(time.time())
|
||||
|
||||
class Instance(models.Model):
|
||||
|
||||
class Meta:
|
||||
|
@ -573,9 +579,9 @@ class Instance(models.Model):
|
|||
created = models.DateTimeField(auto_now_add=True)
|
||||
modified = models.DateTimeField(auto_now=True)
|
||||
|
||||
atime = models.IntegerField(default=lambda: int(time.time()), editable=False)
|
||||
ctime = models.IntegerField(default=lambda: int(time.time()), editable=False)
|
||||
mtime = models.IntegerField(default=lambda: int(time.time()), editable=False)
|
||||
atime = models.IntegerField(default=inttime, editable=False)
|
||||
ctime = models.IntegerField(default=inttime, editable=False)
|
||||
mtime = models.IntegerField(default=inttime, editable=False)
|
||||
|
||||
path = models.CharField(max_length=2048)
|
||||
ignore = models.BooleanField(default=False)
|
||||
|
@ -641,7 +647,7 @@ class Stream(models.Model):
|
|||
resolution = models.IntegerField(default=96)
|
||||
format = models.CharField(max_length=255, default='webm')
|
||||
|
||||
media = models.FileField(default=None, blank=True, upload_to=lambda f, x: f.path(x))
|
||||
media = models.FileField(default=None, blank=True, upload_to=get_path)
|
||||
source = models.ForeignKey('Stream', related_name='derivatives', default=None, null=True)
|
||||
available = models.BooleanField(default=False)
|
||||
oshash = models.CharField(max_length=16, null=True, db_index=True)
|
||||
|
|
|
@ -21,6 +21,7 @@ from archive.chunk import save_chunk
|
|||
import managers
|
||||
import utils
|
||||
|
||||
def get_path(f, x): return f.path(x)
|
||||
|
||||
class Document(models.Model):
|
||||
|
||||
|
@ -42,7 +43,7 @@ class Document(models.Model):
|
|||
description = models.TextField(default="")
|
||||
oshash = models.CharField(max_length=16, unique=True, null=True)
|
||||
|
||||
file = models.FileField(default=None, blank=True,null=True, upload_to=lambda f, x: f.path(x))
|
||||
file = models.FileField(default=None, blank=True,null=True, upload_to=get_path)
|
||||
|
||||
objects = managers.DocumentManager()
|
||||
uploading = models.BooleanField(default = False)
|
||||
|
|
|
@ -26,6 +26,9 @@ from archive import extract
|
|||
|
||||
import managers
|
||||
|
||||
def get_path(f, x): return f.path(x)
|
||||
def get_icon_path(f, x): return get_path(f, 'icon.jpg')
|
||||
|
||||
class Edit(models.Model):
|
||||
|
||||
class Meta:
|
||||
|
@ -46,8 +49,7 @@ class Edit(models.Model):
|
|||
query = DictField(default={"static": True})
|
||||
type = models.CharField(max_length=255, default='static')
|
||||
|
||||
icon = models.ImageField(default=None, blank=True, null=True,
|
||||
upload_to=lambda i, x: i.path("icon.jpg"))
|
||||
icon = models.ImageField(default=None, blank=True, null=True, upload_to=get_icon_path)
|
||||
|
||||
poster_frames = TupleField(default=[], editable=False)
|
||||
subscribed_users = models.ManyToManyField(User, related_name='subscribed_edits')
|
||||
|
|
|
@ -144,6 +144,11 @@ def get_item(info, user=None, async=False):
|
|||
tasks.update_poster.delay(item.public_id)
|
||||
return item
|
||||
|
||||
def get_path(f, x): return f.path(x)
|
||||
def get_icon_path(f, x): return get_path(f, 'icon.jpg')
|
||||
def get_poster_path(f, x): return get_path(f, 'poster.jpg')
|
||||
def get_torrent_path(f, x): return get_path(f, 'torrent.torrent')
|
||||
|
||||
class Item(models.Model):
|
||||
created = models.DateTimeField(auto_now_add=True)
|
||||
modified = models.DateTimeField(auto_now=True)
|
||||
|
@ -161,18 +166,15 @@ class Item(models.Model):
|
|||
external_data = fields.DictField(default={}, editable=False)
|
||||
data = fields.DictField(default={}, editable=False)
|
||||
json = fields.DictField(default={}, editable=False)
|
||||
poster = models.ImageField(default=None, blank=True,
|
||||
upload_to=lambda i, x: i.path("poster.jpg"))
|
||||
poster = models.ImageField(default=None, blank=True, upload_to=get_poster_path)
|
||||
poster_source = models.TextField(blank=True)
|
||||
poster_height = models.IntegerField(default=0)
|
||||
poster_width = models.IntegerField(default=0)
|
||||
poster_frame = models.FloatField(default=-1)
|
||||
|
||||
icon = models.ImageField(default=None, blank=True,
|
||||
upload_to=lambda i, x: i.path("icon.jpg"))
|
||||
icon = models.ImageField(default=None, blank=True, upload_to=get_icon_path)
|
||||
|
||||
torrent = models.FileField(default=None, blank=True, max_length=1000,
|
||||
upload_to=lambda i, x: i.path('torrent.torrent'))
|
||||
torrent = models.FileField(default=None, blank=True, max_length=1000, upload_to=get_torrent_path)
|
||||
stream_info = fields.DictField(default={}, editable=False)
|
||||
|
||||
#stream related fields
|
||||
|
|
|
@ -17,6 +17,11 @@ from ox.django.fields import DictField, TupleField
|
|||
from archive import extract
|
||||
import managers
|
||||
|
||||
def get_path(f, x): return f.path(x)
|
||||
def get_icon_path(f, x): return get_path(f, 'icon.jpg')
|
||||
def get_listview(): return settings.CONFIG['user']['ui']['listView']
|
||||
def get_listsort(): return tuple(settings.CONFIG['user']['ui']['listSort'])
|
||||
|
||||
class List(models.Model):
|
||||
|
||||
class Meta:
|
||||
|
@ -32,11 +37,10 @@ class List(models.Model):
|
|||
type = models.CharField(max_length=255, default='static')
|
||||
description = models.TextField(default='')
|
||||
|
||||
icon = models.ImageField(default=None, blank=True,
|
||||
upload_to=lambda i, x: i.path("icon.jpg"))
|
||||
icon = models.ImageField(default=None, blank=True, upload_to=get_icon_path)
|
||||
|
||||
view = models.TextField(default=lambda: settings.CONFIG['user']['ui']['listView'])
|
||||
sort = TupleField(default=lambda: tuple(settings.CONFIG['user']['ui']['listSort']), editable=False)
|
||||
view = models.TextField(default=get_listview)
|
||||
sort = TupleField(default=get_listsort, editable=False)
|
||||
|
||||
poster_frames = TupleField(default=[], editable=False)
|
||||
|
||||
|
|
|
@ -21,6 +21,9 @@ from archive.chunk import save_chunk
|
|||
import managers
|
||||
|
||||
|
||||
def get_path(i, x): return i.path(x)
|
||||
def get_icon_path(i, x): return get_path(i, 'icon.jpg')
|
||||
|
||||
class Text(models.Model):
|
||||
|
||||
class Meta:
|
||||
|
@ -35,8 +38,7 @@ class Text(models.Model):
|
|||
type = models.CharField(max_length=255, default='html')
|
||||
description = models.TextField(default='')
|
||||
rightslevel = models.IntegerField(db_index=True, default=0)
|
||||
icon = models.ImageField(default=None, blank=True,
|
||||
upload_to=lambda i, x: i.path("icon.jpg"))
|
||||
icon = models.ImageField(default=None, blank=True, upload_to=get_icon_path)
|
||||
|
||||
text = models.TextField(default="")
|
||||
embeds = TupleField(default=[], editable=True)
|
||||
|
@ -46,7 +48,7 @@ class Text(models.Model):
|
|||
|
||||
objects = managers.TextManager()
|
||||
uploading = models.BooleanField(default = False)
|
||||
file = models.FileField(default=None, blank=True,null=True, upload_to=lambda f, x: f.path(x))
|
||||
file = models.FileField(default=None, blank=True,null=True, upload_to=get_path)
|
||||
|
||||
def save(self, *args, **kwargs):
|
||||
self.rightslevel = min(self.rightslevel, len(settings.CONFIG['textRightsLevels']) - 1)
|
||||
|
|
Loading…
Reference in a new issue