make sure settings are dicts

This commit is contained in:
j 2018-11-15 10:28:30 +00:00
parent 503ae10e89
commit 687738ff46
7 changed files with 53 additions and 31 deletions

View File

@ -145,7 +145,11 @@ class ClipManager(Manager):
keys = layer_ids + ['annotations', 'text', '*'] keys = layer_ids + ['annotations', 'text', '*']
conditions = data.get('query', {}).get('conditions', []) conditions = data.get('query', {}).get('conditions', [])
conditions = flatten_conditions(conditions) conditions = flatten_conditions(conditions)
conditions = list(filter(lambda c: c.get('key') in keys, conditions)) conditions_ = []
for c in conditions:
if c.get('key') in keys and c not in conditions_:
conditions_.append(c)
conditions = conditions_
operator = data.get('query', {}).get('operator', '&') operator = data.get('query', {}).get('operator', '&')
def parse(condition): def parse(condition):

View File

@ -95,7 +95,7 @@ def findClips(request, data):
if 'keys' in data: if 'keys' in data:
qs = order_query(qs, query['sort']) qs = order_query(qs, query['sort'])
qs = qs[query['range'][0]:query['range'][1]] qs = qs[query['range'][0]:query['range'][1]]
qs = qs.select_related('item') #qs = qs.select_related('item')
layers = settings.CONFIG['layers'] layers = settings.CONFIG['layers']
entity_layer_ids = [k['id'] for k in layers if k['type'] == 'entity'] entity_layer_ids = [k['id'] for k in layers if k['type'] == 'entity']

View File

@ -11,9 +11,10 @@ import tempfile
from six.moves.urllib.parse import quote from six.moves.urllib.parse import quote
import ox import ox
from django.conf import settings from django.conf import settings
from django.contrib.auth import get_user_model
from django.core.cache import cache
from django.db import models, transaction from django.db import models, transaction
from django.db.models import Max from django.db.models import Max
from django.contrib.auth import get_user_model
from django.utils.encoding import python_2_unicode_compatible from django.utils.encoding import python_2_unicode_compatible
from oxdjango.fields import JSONField from oxdjango.fields import JSONField
@ -118,7 +119,7 @@ class Edit(models.Model):
c = self.add_clip(data) c = self.add_clip(data)
if c: if c:
ids.insert(index, c.id) ids.insert(index, c.id)
added.append(c.json(user)) added.append(c.json(user=user))
added[-1]['index'] = index added[-1]['index'] = index
index += 1 index += 1
else: else:
@ -488,32 +489,38 @@ class Clip(models.Model):
self.sortvolume = 0 self.sortvolume = 0
def json(self, user=None): def json(self, user=None):
data = { cache_key = 'edit:clip:' + str(self.get_id())
'id': self.get_id(), if user:
'index': self.index, cache_key += ':' + user.username
'volume': self.volume, data = cache.get(cache_key)
} if not data:
if self.annotation: data = {
data['annotation'] = self.annotation.public_id 'id': self.get_id(),
data['item'] = self.item.public_id 'index': self.index,
data['in'] = self.annotation.start 'volume': self.volume,
data['out'] = self.annotation.end }
data['parts'] = self.annotation.item.cache['parts'] if self.annotation:
data['durations'] = self.annotation.item.cache['durations'] data['annotation'] = self.annotation.public_id
else: data['item'] = self.item.public_id
data['item'] = self.item.public_id data['in'] = self.annotation.start
data['in'] = self.start data['out'] = self.annotation.end
data['out'] = self.end data['parts'] = self.annotation.item.cache['parts']
data['parts'] = self.item.cache['parts'] data['durations'] = self.annotation.item.cache['durations']
data['durations'] = self.item.cache['durations'] else:
for key in ('title', 'director', 'year', 'videoRatio'): data['item'] = self.item.public_id
value = self.item.cache.get(key) data['in'] = self.start
if value: data['out'] = self.end
data[key] = value data['parts'] = self.item.cache['parts']
data['duration'] = data['out'] - data['in'] data['durations'] = self.item.cache['durations']
data['cuts'] = tuple([c for c in self.item.get('cuts', []) if c > self.start and c < self.end]) for key in ('title', 'director', 'year', 'videoRatio'):
data['layers'] = self.get_layers(user) value = self.item.cache.get(key)
data['streams'] = [s.file.oshash for s in self.item.streams()] if value:
data[key] = value
data['duration'] = data['out'] - data['in']
data['cuts'] = tuple([c for c in self.item.get('cuts', []) if c > self.start and c < self.end])
data['layers'] = self.get_layers(user)
data['streams'] = [s.file.oshash for s in self.item.streams()]
cache.set(cache_key, data, 180)
return data return data
def get_annotations(self): def get_annotations(self):

View File

@ -170,6 +170,13 @@ LOGGING = {
} }
} }
CACHES = {
'default': {
'BACKEND': 'django.core.cache.backends.db.DatabaseCache',
'LOCATION': 'cache',
}
}
AUTH_PROFILE_MODULE = 'user.UserProfile' AUTH_PROFILE_MODULE = 'user.UserProfile'
AUTH_CHECK_USERNAME = True AUTH_CHECK_USERNAME = True
FFMPEG = 'ffmpeg' FFMPEG = 'ffmpeg'

View File

@ -785,7 +785,7 @@ def setUI(request, data):
if isinstance(p, list): if isinstance(p, list):
p = p[getPositionById(p, key)] p = p[getPositionById(p, key)]
else: else:
if key not in p: if key not in p or not isinstance(p[key], dict):
p[key] = {} p[key] = {}
p = p[key] p = p[key]
if value == None and keys[0] in p: if value == None and keys[0] in p:

View File

@ -10,3 +10,4 @@ requests==2.19.1
tornado<5 tornado<5
geoip2==2.9.0 geoip2==2.9.0
youtube-dl youtube-dl
python-memcached

View File

@ -249,6 +249,9 @@ if __name__ == "__main__":
update_service('pandora-tasks') update_service('pandora-tasks')
if old < 5975: if old < 5975:
run('./bin/pip', 'install', '-r', 'requirements.txt') run('./bin/pip', 'install', '-r', 'requirements.txt')
if old <= 6064:
run('./bin/pip', 'install', '-r', 'requirements.txt')
run('./pandora/manage.py', 'createcachetable')
else: else:
if len(sys.argv) == 1: if len(sys.argv) == 1:
release = get_release() release = get_release()