forked from 0x2620/pandora
show selected/wanted files
This commit is contained in:
parent
3c3f932c68
commit
74f777e0d1
5 changed files with 121 additions and 40 deletions
|
@ -261,28 +261,26 @@ class File(models.Model):
|
||||||
if resolution == (0, 0):
|
if resolution == (0, 0):
|
||||||
resolution = None
|
resolution = None
|
||||||
duration = self.duration
|
duration = self.duration
|
||||||
if self.get_type() != 'video':
|
if self.type != 'video':
|
||||||
duration = None
|
duration = None
|
||||||
data = {
|
data = {
|
||||||
|
'audioCodec': self.audio_codec,
|
||||||
'available': self.available,
|
'available': self.available,
|
||||||
'duration': duration,
|
'duration': duration,
|
||||||
'framerate': self.framerate,
|
'framerate': self.framerate,
|
||||||
#'height': self.height,
|
|
||||||
#'width': self.width,
|
|
||||||
'resolution': resolution,
|
|
||||||
'id': self.oshash,
|
'id': self.oshash,
|
||||||
'samplerate': self.samplerate,
|
|
||||||
'video_codec': self.video_codec,
|
|
||||||
'audio_codec': self.audio_codec,
|
|
||||||
'path': self.path,
|
|
||||||
'size': self.size,
|
|
||||||
#'info': self.info,
|
|
||||||
'users': list(set([u.username
|
|
||||||
for u in User.objects.filter(volumes__files__in=self.instances.all())])),
|
|
||||||
'instances': [i.json() for i in self.instances.all()],
|
'instances': [i.json() for i in self.instances.all()],
|
||||||
'type': self.get_type(),
|
'part': self.part,
|
||||||
'part': self.get_part()
|
'path': self.path,
|
||||||
|
'resolution': resolution,
|
||||||
|
'samplerate': self.samplerate,
|
||||||
|
'selected': self.selected,
|
||||||
|
'size': self.size,
|
||||||
|
'type': self.type,
|
||||||
|
'videoCodec': self.video_codec,
|
||||||
|
'wanted': self.wanted,
|
||||||
}
|
}
|
||||||
|
data['users'] = [i['user'] for i in data['instances']]
|
||||||
if keys:
|
if keys:
|
||||||
for k in data.keys():
|
for k in data.keys():
|
||||||
if k not in keys:
|
if k not in keys:
|
||||||
|
@ -290,7 +288,6 @@ class File(models.Model):
|
||||||
return data
|
return data
|
||||||
|
|
||||||
def get_part(self):
|
def get_part(self):
|
||||||
#FIXME: this breaks for sub/idx/srt
|
|
||||||
if os.path.splitext(self.path)[-1] in ('.sub', '.idx', '.srt'):
|
if os.path.splitext(self.path)[-1] in ('.sub', '.idx', '.srt'):
|
||||||
name = os.path.splitext(self.path)[0]
|
name = os.path.splitext(self.path)[0]
|
||||||
if self.language:
|
if self.language:
|
||||||
|
@ -388,9 +385,10 @@ class Instance(models.Model):
|
||||||
|
|
||||||
def json(self):
|
def json(self):
|
||||||
return {
|
return {
|
||||||
|
'ignore': self.ignore,
|
||||||
|
'path': self.path,
|
||||||
'user': self.volume.user.username,
|
'user': self.volume.user.username,
|
||||||
'volume': self.volume.name,
|
'volume': self.volume.name,
|
||||||
'path': self.path
|
|
||||||
}
|
}
|
||||||
|
|
||||||
def frame_path(frame, name):
|
def frame_path(frame, name):
|
||||||
|
|
|
@ -7,7 +7,7 @@ from datetime import datetime
|
||||||
from django import forms
|
from django import forms
|
||||||
from django.shortcuts import get_object_or_404, redirect
|
from django.shortcuts import get_object_or_404, redirect
|
||||||
from django.conf import settings
|
from django.conf import settings
|
||||||
from django.db.models import Count, Sum
|
from django.db.models import Count
|
||||||
|
|
||||||
import ox
|
import ox
|
||||||
from ox.utils import json
|
from ox.utils import json
|
||||||
|
@ -288,7 +288,8 @@ def editFile(request):
|
||||||
param data {
|
param data {
|
||||||
id: hash of file
|
id: hash of file
|
||||||
part:
|
part:
|
||||||
id_extra: boolean
|
language:
|
||||||
|
ignore: boolean
|
||||||
}
|
}
|
||||||
|
|
||||||
return {
|
return {
|
||||||
|
@ -297,17 +298,26 @@ def editFile(request):
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
'''
|
'''
|
||||||
#FIXME: permissions, need to be checked
|
|
||||||
data = json.loads(request.POST['data'])
|
data = json.loads(request.POST['data'])
|
||||||
f = get_object_or_404_json(models.File, oshash=data['id'])
|
f = get_object_or_404_json(models.File, oshash=data['id'])
|
||||||
response = json_response()
|
response = json_response()
|
||||||
if data.keys() != ('id', ):
|
if f.editable(request.user):
|
||||||
for key in data:
|
update = False
|
||||||
if key in ('is_extra', 'is_subtitle', 'is_video', 'is_version',
|
#FIXME: should all instances be ignored?
|
||||||
'part', 'language'):
|
if 'ignore' in data:
|
||||||
|
f.instances.update(ignore=True)
|
||||||
|
#FIXME: is this to slow to run sync?
|
||||||
|
f.item.update_selected()
|
||||||
|
for key in ('part', 'language'):
|
||||||
|
if key in data:
|
||||||
setattr(f, key, data[key])
|
setattr(f, key, data[key])
|
||||||
f.auto = False
|
f.auto = False
|
||||||
f.save()
|
update = True
|
||||||
|
if update:
|
||||||
|
f.save()
|
||||||
|
response = json_response(status=200, text='updated')
|
||||||
|
else:
|
||||||
|
response = json_response(status=403, text='permissino denied')
|
||||||
return render_to_json_response(response)
|
return render_to_json_response(response)
|
||||||
actions.register(editFile, cache=False)
|
actions.register(editFile, cache=False)
|
||||||
|
|
||||||
|
@ -415,8 +425,6 @@ Positions
|
||||||
}
|
}
|
||||||
'''
|
'''
|
||||||
data = json.loads(request.POST['data'])
|
data = json.loads(request.POST['data'])
|
||||||
if settings.JSON_DEBUG:
|
|
||||||
print json.dumps(data, indent=2)
|
|
||||||
query = parse_query(data, request.user)
|
query = parse_query(data, request.user)
|
||||||
|
|
||||||
response = json_response({})
|
response = json_response({})
|
||||||
|
|
|
@ -59,7 +59,7 @@ def get_id(info):
|
||||||
if settings.DATA_SERVICE:
|
if settings.DATA_SERVICE:
|
||||||
r = external_data('getId', info)
|
r = external_data('getId', info)
|
||||||
if r['status']['code'] == 200:
|
if r['status']['code'] == 200:
|
||||||
imdbId = r['data']['imdbId']
|
imdbId = r['data']['id']
|
||||||
return imdbId
|
return imdbId
|
||||||
return None
|
return None
|
||||||
|
|
||||||
|
@ -542,6 +542,8 @@ class Item(models.Model):
|
||||||
def set_value(s, name, value):
|
def set_value(s, name, value):
|
||||||
if not value:
|
if not value:
|
||||||
value = None
|
value = None
|
||||||
|
if isinstance(value, basestring):
|
||||||
|
value = value.lower()
|
||||||
setattr(s, name, value)
|
setattr(s, name, value)
|
||||||
|
|
||||||
base_keys = (
|
base_keys = (
|
||||||
|
@ -553,7 +555,7 @@ class Item(models.Model):
|
||||||
'lightness',
|
'lightness',
|
||||||
'volume',
|
'volume',
|
||||||
'clips',
|
'clips',
|
||||||
'cuts',
|
'numberofcuts',
|
||||||
'cutsperminute',
|
'cutsperminute',
|
||||||
'words',
|
'words',
|
||||||
'wordsperminute',
|
'wordsperminute',
|
||||||
|
@ -622,8 +624,8 @@ class Item(models.Model):
|
||||||
|
|
||||||
# sort values based on data from videos
|
# sort values based on data from videos
|
||||||
s.words = sum([len(a.value.split()) for a in self.annotations.all()])
|
s.words = sum([len(a.value.split()) for a in self.annotations.all()])
|
||||||
|
s.clips= self.clips.count()
|
||||||
|
|
||||||
s.clips = 0 #FIXME: get clips from all layers or something
|
|
||||||
videos = self.files.filter(selected=True, is_video=True)
|
videos = self.files.filter(selected=True, is_video=True)
|
||||||
if videos.count() > 0:
|
if videos.count() > 0:
|
||||||
s.duration = sum([v.duration for v in videos])
|
s.duration = sum([v.duration for v in videos])
|
||||||
|
@ -657,9 +659,9 @@ class Item(models.Model):
|
||||||
s.hue = None
|
s.hue = None
|
||||||
s.saturation = None
|
s.saturation = None
|
||||||
s.brighness = None
|
s.brighness = None
|
||||||
s.cuts = len(self.data.get('cuts', []))
|
s.numberofcuts = len(self.data.get('cuts', []))
|
||||||
if s.duration:
|
if s.duration:
|
||||||
s.cutsperminute = s.cuts / (s.duration/60)
|
s.cutsperminute = s.numberofcuts / (s.duration/60)
|
||||||
s.wordsperminute = s.words / (s.duration / 60)
|
s.wordsperminute = s.words / (s.duration / 60)
|
||||||
else:
|
else:
|
||||||
s.cutsperminute = None
|
s.cutsperminute = None
|
||||||
|
@ -667,7 +669,6 @@ class Item(models.Model):
|
||||||
s.popularity = self.accessed.aggregate(Sum('accessed'))['accessed__sum']
|
s.popularity = self.accessed.aggregate(Sum('accessed'))['accessed__sum']
|
||||||
s.save()
|
s.save()
|
||||||
|
|
||||||
|
|
||||||
def update_facets(self):
|
def update_facets(self):
|
||||||
#FIXME: what to do with Unkown Director, Year, Country etc.
|
#FIXME: what to do with Unkown Director, Year, Country etc.
|
||||||
for key in self.facet_keys + ['title']:
|
for key in self.facet_keys + ['title']:
|
||||||
|
@ -735,8 +736,10 @@ class Item(models.Model):
|
||||||
return os.path.join(settings.MEDIA_ROOT, self.path(), 'timeline')
|
return os.path.join(settings.MEDIA_ROOT, self.path(), 'timeline')
|
||||||
|
|
||||||
def get_files(self, user):
|
def get_files(self, user):
|
||||||
#FIXME: limit by user
|
files = self.files.all().select_related()
|
||||||
return [f.json() for f in self.files.all()]
|
if user.get_profile().get_level() != 'admin':
|
||||||
|
files = files.filter(instances__volume__user=user)
|
||||||
|
return [f.json() for f in files]
|
||||||
|
|
||||||
def users_with_files(self):
|
def users_with_files(self):
|
||||||
return User.objects.filter(
|
return User.objects.filter(
|
||||||
|
@ -764,6 +767,7 @@ class Item(models.Model):
|
||||||
for s in self.sets():
|
for s in self.sets():
|
||||||
if s.filter(Q(is_video=True)|Q(is_audio=True)).filter(available=False).count() == 0:
|
if s.filter(Q(is_video=True)|Q(is_audio=True)).filter(available=False).count() == 0:
|
||||||
update = False
|
update = False
|
||||||
|
self.files.exclude(id__in=s).exclude(part=None).update(part=None)
|
||||||
deselect = self.files.filter(selected=True).exclude(id__in=s)
|
deselect = self.files.filter(selected=True).exclude(id__in=s)
|
||||||
if deselect.count() > 0:
|
if deselect.count() > 0:
|
||||||
deselect.update(selected=False)
|
deselect.update(selected=False)
|
||||||
|
@ -771,6 +775,10 @@ class Item(models.Model):
|
||||||
if s.filter(selected=False).count() > 0:
|
if s.filter(selected=False).count() > 0:
|
||||||
s.update(selected=True, wanted=False)
|
s.update(selected=True, wanted=False)
|
||||||
update = True
|
update = True
|
||||||
|
for f in s:
|
||||||
|
if f.get_part() != f.part:
|
||||||
|
f.save()
|
||||||
|
update = True
|
||||||
if update:
|
if update:
|
||||||
self.rendered = False
|
self.rendered = False
|
||||||
self.save()
|
self.save()
|
||||||
|
|
|
@ -326,6 +326,38 @@ def autocomplete(request):
|
||||||
return render_to_json_response(response)
|
return render_to_json_response(response)
|
||||||
actions.register(autocomplete)
|
actions.register(autocomplete)
|
||||||
|
|
||||||
|
def findId(request):
|
||||||
|
'''
|
||||||
|
param data {
|
||||||
|
'query': query,
|
||||||
|
'sort': array,
|
||||||
|
'range': array
|
||||||
|
}
|
||||||
|
|
||||||
|
'''
|
||||||
|
data = json.loads(request.POST['data'])
|
||||||
|
response = json_response({})
|
||||||
|
response['data']['items'] = []
|
||||||
|
'''
|
||||||
|
FIXME: can not handle query for director []
|
||||||
|
query = parse_query(data, request.user)
|
||||||
|
qs = _order_query(query['qs'], query['sort'])
|
||||||
|
if qs.count() == 1:
|
||||||
|
response['data']['items'] = [i.get_json(data['keys']) for i in qs]
|
||||||
|
elif settings.DATA_SERVICE:
|
||||||
|
'''
|
||||||
|
if settings.DATA_SERVICE:
|
||||||
|
'''
|
||||||
|
info = {}
|
||||||
|
for c in data['query']['conditions']:
|
||||||
|
info[c['key']] = c['value']
|
||||||
|
r = models.external_data('getId', info)
|
||||||
|
'''
|
||||||
|
r = models.external_data('getId', data)
|
||||||
|
if r['status']['code'] == 200:
|
||||||
|
response['data']['items'] = [r['data']]
|
||||||
|
return render_to_json_response(response)
|
||||||
|
actions.register(findId)
|
||||||
|
|
||||||
def get(request):
|
def get(request):
|
||||||
'''
|
'''
|
||||||
|
|
|
@ -45,13 +45,36 @@ pandora.ui.filesView = function(options, self) {
|
||||||
|
|
||||||
self.$filesList = Ox.TextList({
|
self.$filesList = Ox.TextList({
|
||||||
columns: [
|
columns: [
|
||||||
|
{
|
||||||
|
format: function(value, data) {
|
||||||
|
Ox.print('File', value, data.wanted, data);
|
||||||
|
return $('<img>')
|
||||||
|
.attr({
|
||||||
|
src: data.wanted ? Ox.UI.getImageURL('symbolStar') :
|
||||||
|
Ox.UI.getImageURL('symbolCheck')
|
||||||
|
})
|
||||||
|
.css({
|
||||||
|
width: '10px',
|
||||||
|
height: '10px',
|
||||||
|
padding: '3px',
|
||||||
|
opacity: (value || data.wanted) ? 1 : 0
|
||||||
|
});
|
||||||
|
},
|
||||||
|
id: 'selected',
|
||||||
|
operator: '-',
|
||||||
|
title: $('<img>').attr({
|
||||||
|
src: Ox.UI.getImageURL('symbolCheck')
|
||||||
|
}),
|
||||||
|
visible: true,
|
||||||
|
width: 16
|
||||||
|
},
|
||||||
{
|
{
|
||||||
align: 'left',
|
align: 'left',
|
||||||
id: 'users',
|
id: 'users',
|
||||||
operator: '+',
|
operator: '+',
|
||||||
title: 'Users',
|
title: 'Users',
|
||||||
visible: true,
|
visible: true,
|
||||||
width: 120
|
width: 50
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
align: 'left',
|
align: 'left',
|
||||||
|
@ -133,11 +156,12 @@ pandora.ui.filesView = function(options, self) {
|
||||||
conditions: [{
|
conditions: [{
|
||||||
key: 'id',
|
key: 'id',
|
||||||
value: self.options.id,
|
value: self.options.id,
|
||||||
operator: '='
|
operator: '=='
|
||||||
}]
|
}]
|
||||||
}
|
}
|
||||||
}), callback);
|
}), callback);
|
||||||
},
|
},
|
||||||
|
keys: ['wanted'],
|
||||||
scrollbarVisible: true,
|
scrollbarVisible: true,
|
||||||
sort: [{key: 'path', operator: '+'}]
|
sort: [{key: 'path', operator: '+'}]
|
||||||
})
|
})
|
||||||
|
@ -202,13 +226,14 @@ pandora.ui.filesView = function(options, self) {
|
||||||
change: function(data) {
|
change: function(data) {
|
||||||
var conditions;
|
var conditions;
|
||||||
if (data.value.length) {
|
if (data.value.length) {
|
||||||
|
/*
|
||||||
if (key == 'id') {
|
if (key == 'id') {
|
||||||
conditions = [{key: 'id', value: data.value, operator: '='}]
|
conditions = [{key: 'id', value: data.value, operator: '=='}]
|
||||||
} else {
|
} else {
|
||||||
conditions = Ox.map(['title', 'director', 'year'], function(key) {
|
conditions = Ox.map(['title', 'director', 'year'], function(key) {
|
||||||
var value = self['$' + key + 'Input'].options('value')
|
var value = self['$' + key + 'Input'].options('value')
|
||||||
return value.length ? {key: key, value: value, operator: '='} : null;
|
return value.length ? {key: key, value: value, operator: '='} : null;
|
||||||
})
|
});
|
||||||
}
|
}
|
||||||
pandora.api.find({
|
pandora.api.find({
|
||||||
keys: ['title', 'director', 'year', 'id'],
|
keys: ['title', 'director', 'year', 'id'],
|
||||||
|
@ -218,6 +243,15 @@ pandora.ui.filesView = function(options, self) {
|
||||||
},
|
},
|
||||||
range: [0, 2]
|
range: [0, 2]
|
||||||
}, function(result) {
|
}, function(result) {
|
||||||
|
*/
|
||||||
|
conditions = {};
|
||||||
|
Ox.map(['id', 'title', 'director', 'year'], function(key) {
|
||||||
|
var value = self['$' + key + 'Input'].options('value');
|
||||||
|
if(value.length) {
|
||||||
|
conditions[key] = value;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
pandora.api.findId(conditions, function(result) {
|
||||||
var length = result.data.items.length;
|
var length = result.data.items.length;
|
||||||
if (length == 0) {
|
if (length == 0) {
|
||||||
if (key != 'id') {
|
if (key != 'id') {
|
||||||
|
@ -234,7 +268,7 @@ pandora.ui.filesView = function(options, self) {
|
||||||
} else {
|
} else {
|
||||||
self.$idInput.options({value: ''});
|
self.$idInput.options({value: ''});
|
||||||
}
|
}
|
||||||
})
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
@ -345,6 +379,7 @@ pandora.ui.filesView = function(options, self) {
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
updateForm();
|
updateForm();
|
||||||
|
self.$titleInput.triggerEvent('change', {value: result.data['title']});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue