diff --git a/pandora/annotation/models.py b/pandora/annotation/models.py
index 2f7b78440..53f162a8e 100644
--- a/pandora/annotation/models.py
+++ b/pandora/annotation/models.py
@@ -368,7 +368,7 @@ class Annotation(models.Model):
if key in self._clip_keys:
j[key] = getattr(self.clip, key)
elif key not in self.annotation_keys:
- value = self.item.get(key) or self.item.json.get(key)
+ value = self.item.get(key) or self.item.cache.get(key)
if not value and hasattr(self.item.sort, key):
value = getattr(self.item.sort, key)
if value != None:
diff --git a/pandora/clip/models.py b/pandora/clip/models.py
index 121040fc1..82e446d45 100644
--- a/pandora/clip/models.py
+++ b/pandora/clip/models.py
@@ -131,7 +131,7 @@ class MetaClip(object):
if key == 'streams':
value = [s.file.oshash for s in self.item.streams()]
else:
- value = self.item.get(key) or self.item.json.get(key)
+ value = self.item.get(key) or self.item.cache.get(key)
if not value and hasattr(self.item.sort, key):
value = getattr(self.item.sort, key)
if value is not None:
@@ -148,10 +148,10 @@ class MetaClip(object):
qs = self.annotations.all()
if qs.count():
data['annotation'] = qs[0].public_id
- data['parts'] = self.item.json['parts']
- data['durations'] = self.item.json['durations']
+ data['parts'] = self.item.cache['parts']
+ data['durations'] = self.item.cache['durations']
for key in ('title', 'director', 'year', 'videoRatio'):
- value = self.item.json.get(key)
+ value = self.item.cache.get(key)
if value:
data[key] = value
data['duration'] = data['out'] - data['in']
diff --git a/pandora/edit/models.py b/pandora/edit/models.py
index 278e88048..75a6987a3 100644
--- a/pandora/edit/models.py
+++ b/pandora/edit/models.py
@@ -493,16 +493,16 @@ class Clip(models.Model):
data['item'] = self.item.public_id
data['in'] = self.annotation.start
data['out'] = self.annotation.end
- data['parts'] = self.annotation.item.json['parts']
- data['durations'] = self.annotation.item.json['durations']
+ data['parts'] = self.annotation.item.cache['parts']
+ data['durations'] = self.annotation.item.cache['durations']
else:
data['item'] = self.item.public_id
data['in'] = self.start
data['out'] = self.end
- data['parts'] = self.item.json['parts']
- data['durations'] = self.item.json['durations']
+ data['parts'] = self.item.cache['parts']
+ data['durations'] = self.item.cache['durations']
for key in ('title', 'director', 'year', 'videoRatio'):
- value = self.item.json.get(key)
+ value = self.item.cache.get(key)
if value:
data[key] = value
data['duration'] = data['out'] - data['in']
diff --git a/pandora/item/migrations/0004_json_cache.py b/pandora/item/migrations/0004_json_cache.py
new file mode 100644
index 000000000..899624894
--- /dev/null
+++ b/pandora/item/migrations/0004_json_cache.py
@@ -0,0 +1,22 @@
+# -*- coding: utf-8 -*-
+# Generated by Django 1.11.13 on 2018-06-19 20:24
+from __future__ import unicode_literals
+
+import django.core.serializers.json
+from django.db import migrations, models
+import oxdjango.fields
+
+
+class Migration(migrations.Migration):
+
+ dependencies = [
+ ('item', '0003_jsonfield'),
+ ]
+
+ operations = [
+ migrations.RenameField(
+ model_name='item',
+ old_name='json',
+ new_name='cache',
+ ),
+ ]
diff --git a/pandora/item/models.py b/pandora/item/models.py
index c03b163ae..f255500c8 100644
--- a/pandora/item/models.py
+++ b/pandora/item/models.py
@@ -177,7 +177,7 @@ class Item(models.Model):
oxdbId = models.CharField(max_length=42, unique=True, blank=True, null=True)
external_data = JSONField(default=dict, editable=False)
data = JSONField(default=dict, editable=False)
- json = JSONField(default=dict, editable=False)
+ cache = JSONField(default=dict, editable=False)
poster = models.ImageField(default=None, blank=True, upload_to=get_poster_path)
poster_source = models.TextField(blank=True)
poster_height = models.IntegerField(default=0)
@@ -425,8 +425,8 @@ class Item(models.Model):
self.poster_width = 80
self.update_sort()
self.update_languages()
- self.json = self.get_json()
- self.json['modified'] = datetime.now()
+ self.cache = self.get_json()
+ self.cache['modified'] = datetime.now()
super(Item, self).save(*args, **kwargs)
self.update_find()
self.update_sort()
@@ -1360,7 +1360,7 @@ class Item(models.Model):
if offset:
self.data['volume'] /= offset
# extract.timeline_strip(self, self.data['cuts'], stream.info, self.timeline_prefix[:-8])
- self.json = self.get_json()
+ self.cache = self.get_json()
self.update_sort()
self.select_frame()
self.make_poster()
@@ -1383,9 +1383,9 @@ class Item(models.Model):
self.poster_height = self.poster.height
self.poster_width = self.poster.width
self.clear_poster_cache(self.poster.path)
- if self.json.get('posterRatio') != self.poster_width / self.poster_height:
- self.json = self.get_json()
- Item.objects.filter(id=self.id).update(json=self.json,
+ if self.cache.get('posterRatio') != self.poster_width / self.poster_height:
+ self.cache = self.get_json()
+ Item.objects.filter(id=self.id).update(cache=self.cache,
poster_width=self.poster_width,
poster_height=self.poster_height)
@@ -1467,7 +1467,7 @@ class Item(models.Model):
timeline = audio_timeline
cmd = [settings.ITEM_POSTER, '-d', '-', '-p', poster]
- data = self.json.copy()
+ data = self.cache.copy()
if frame:
data['frame'] = frame
if os.path.exists(timeline):
@@ -1495,8 +1495,8 @@ class Item(models.Model):
})
offset += f.duration
else:
- if 'videoRatio' in self.json and self.sort.duration and self.streams():
- width, height = self.json['resolution']
+ if 'videoRatio' in self.cache and self.sort.duration and self.streams():
+ width, height = self.cache['resolution']
if width and height:
pos = self.sort.duration / 2
for p in [pos/2, pos, pos+pos/2]:
@@ -1636,9 +1636,9 @@ class Item(models.Model):
for data in s.srt(offset):
subtitles_added = True
value = data['value'].replace('\n', '
\n').replace('
\n', '
\n')
- if data['in'] < self.json['duration'] and data['out'] > self.json['duration']:
- data['out'] = self.json['duration']
- if data['in'] < self.json['duration']:
+ if data['in'] < self.cache['duration'] and data['out'] > self.cache['duration']:
+ data['out'] = self.cache['duration']
+ if data['in'] < self.cache['duration']:
new.append((float('%0.03f' % data['in']), float('%0.03f' % data['out']), value))
# otherwise add empty 5 seconds annotation every minute
if not subtitles_added:
diff --git a/pandora/item/views.py b/pandora/item/views.py
index 07d9f4b89..40f3c02c6 100644
--- a/pandora/item/views.py
+++ b/pandora/item/views.py
@@ -175,11 +175,11 @@ def only_p_sums(request, query, m):
if p == 'accessed':
r[p] = m.sort.accessed or ''
elif p == 'editable':
- r[p] = is_editable(request, m.json)
+ r[p] = is_editable(request, m.cache)
elif p in item_sort_keys:
r[p] = getattr(m.sort, p)
else:
- r[p] = m.json.get(p)
+ r[p] = m.cache.get(p)
if 'clip_qs' in query:
r['clips'] = get_clips(query, query['clip_qs'].filter(item=m))
return r
@@ -212,7 +212,7 @@ def get_items(request, query):
qs = qs.select_related()
items = [only_p_sums(request, query, m) for m in qs]
else:
- items = [only_p(request, query, m['json']) for m in qs.values('json')]
+ items = [only_p(request, query, m['cache']) for m in qs.values('cache')]
return items
def get_stats(request, query):
@@ -1040,7 +1040,7 @@ def video(request, id, resolution, format, index=None, track=None):
if not r:
return HttpResponseForbidden()
path = video.name
- duration = sum(item.json['durations'])
+ duration = sum(item.cache['durations'])
content_type = mimetypes.guess_type(path)[0]
if len(t) == 2 and t[1] > t[0] and duration >= t[1]:
diff --git a/pandora/sequence/models.py b/pandora/sequence/models.py
index 9abc68464..2970c3f25 100644
--- a/pandora/sequence/models.py
+++ b/pandora/sequence/models.py
@@ -55,5 +55,5 @@ class Sequence(models.Model):
if keys:
for key in keys:
if key not in j:
- j[key] = self.sort.item.json.get(key)
+ j[key] = self.sort.item.cache.get(key)
return j