This commit is contained in:
rolux 2011-10-19 10:47:58 +00:00
commit e53c6dfef3
8 changed files with 162 additions and 71 deletions

View file

@ -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:
@ -298,7 +295,7 @@ class File(models.Model):
qs = self.item.files.filter(Q(is_video=True)|Q(is_audio=True), qs = self.item.files.filter(Q(is_video=True)|Q(is_audio=True),
selected=True, path__startswith=name) selected=True, path__startswith=name)
if qs.count()>0: if qs.count()>0:
return qs[0].part return qs[0].get_part()
if self.selected: if self.selected:
files = list(self.item.files.filter(type=self.type, language=self.language, files = list(self.item.files.filter(type=self.type, language=self.language,
selected=self.selected).order_by('sort_path')) selected=self.selected).order_by('sort_path'))
@ -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):

View file

@ -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({})

View file

@ -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()

View file

@ -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):
''' '''

View file

@ -33,11 +33,6 @@ class UserProfile(models.Model):
info = DictField(default={}) info = DictField(default={})
notes = models.TextField(default='') notes = models.TextField(default='')
def get_preferences(self):
prefs = self.preferences
prefs['email'] = self.user.email
return prefs
def get_ui(self): def get_ui(self):
return get_ui(self.ui, self.user) return get_ui(self.ui, self.user)
@ -154,7 +149,7 @@ def init_user(user, request=None):
result[key] = getattr(user, key) result[key] = getattr(user, key)
result['level'] = profile.get_level() result['level'] = profile.get_level()
result['groups'] = [g.name for g in user.groups.all()] result['groups'] = [g.name for g in user.groups.all()]
result['preferences'] = profile.get_preferences() result['email'] = user.email
result['ui'] = profile.get_ui() result['ui'] = profile.get_ui()
result['volumes'] = [v.json() for v in user.volumes.all()] result['volumes'] = [v.json() for v in user.volumes.all()]
return result return result

View file

@ -577,29 +577,34 @@ def getPositionById(list, key):
@login_required_json @login_required_json
def setPreferences(request): def editPreferences(request):
''' '''
param data { param data {
key.subkey: value key: value
} }
keys: email, password
return return
''' '''
data = json.loads(request.POST['data']) data = json.loads(request.POST['data'])
keys = re.sub('([^\\\\])\.', '\\1\n', data.keys()[0]).split('\n') errors = {}
value = data.values()[0] change = False
profile = request.user.get_profile()
p = profile.preferences
while len(keys)>1:
key = keys.pop(0)
if isinstance(p, list):
p = p[getPositionById(p, key)]
else:
p = p[key]
p[keys[0]] = value
profile.save()
response = json_response() response = json_response()
if 'email' in data:
if models.User.objects.filter(
email=data['email']).exclude(username=request.user.username).count()>0:
errors['email'] = 'Email address already in use'
else:
change = True
request.user.email = data['email']
if 'password' in data:
change = True
request.user.password = data['password']
if change:
request.user.save()
if errors:
response = json_response({ 'errors': errors})
return render_to_json_response(response) return render_to_json_response(response)
actions.register(setPreferences, cache=False) actions.register(editPreferences, cache=False)
def resetUI(request): def resetUI(request):

View file

@ -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']});
}); });
} }

View file

@ -1,13 +1,23 @@
// vim: et:ts=4:sw=4:sts=4:ft=javascript // vim: et:ts=4:sw=4:sts=4:ft=javascript
pandora.ui.status = function(key, data) { pandora.ui.status = function(key, data) {
var that = Ox.toTitleCase(key) + ': ' + [ var itemName = data.items != 1 ? pandora.site.itemName.plural : pandora.site.itemName.singular,
Ox.formatNumber(data.items) + ' '+ (data.items != 1 ? pandora.site.itemName.plural : pandora.site.itemName.singular), segments = [],
Ox.formatDuration(data.runtime, 'short'), that = Ox.toTitleCase(key) + ': ';
data.files + ' file' + (data.files != 1 ? 's' : ''), if (!pandora.user.ui.item && pandora.user.ui.listView == 'clip') {
Ox.formatDuration(data.duration), itemName = data.items != 1 ? 'Clips' : 'Clip';
Ox.formatValue(data.size, 'B'), }
Ox.formatValue(data.pixels, 'px')
].join(', '); segments.push(Ox.formatNumber(data.items) + ' '+ itemName);
return that; if (data.runtime)
segments.push(Ox.formatDuration(data.runtime, 'short'));
if (data.files)
segments.push(data.files + ' file' + (data.files != 1 ? 's' : ''));
if (data.duration)
segments.push(Ox.formatDuration(data.duration));
if (data.size)
segments.push(Ox.formatValue(data.size, 'B'));
if (data.pixels)
segments.push(Ox.formatValue(data.pixels, 'px'));
return that + segments.join(', ');
}; };