rendered, editFile
This commit is contained in:
parent
8d98cb79de
commit
4f71992f2b
10 changed files with 66 additions and 36 deletions
|
|
@ -20,13 +20,14 @@ import chardet
|
|||
from item import utils
|
||||
from item.models import Item
|
||||
from person.models import get_name_sort
|
||||
from annotation.models import Annotation, Layer
|
||||
|
||||
|
||||
class File(models.Model):
|
||||
created = models.DateTimeField(auto_now_add=True)
|
||||
modified = models.DateTimeField(auto_now=True)
|
||||
|
||||
verified = models.BooleanField(default=False)
|
||||
auto = models.BooleanField(default=True)
|
||||
|
||||
oshash = models.CharField(max_length=16, unique=True)
|
||||
item = models.ForeignKey(Item, related_name='files')
|
||||
|
|
@ -75,7 +76,7 @@ class File(models.Model):
|
|||
def __unicode__(self):
|
||||
return self.name
|
||||
|
||||
def save(self, *args, **kwargs):
|
||||
def set_state(self):
|
||||
instance = self.get_instance()
|
||||
if instance:
|
||||
if instance.name.lower().startswith('extras/'):
|
||||
|
|
@ -152,6 +153,10 @@ class File(models.Model):
|
|||
|
||||
if self.type not in ('audio', 'video'):
|
||||
self.duration = None
|
||||
|
||||
def save(self, *args, **kwargs):
|
||||
if self.auto:
|
||||
self.set_state()
|
||||
super(File, self).save(*args, **kwargs)
|
||||
|
||||
#upload and data handling
|
||||
|
|
@ -268,7 +273,7 @@ class File(models.Model):
|
|||
'height': self.height,
|
||||
'width': self.width,
|
||||
'resolution': resolution,
|
||||
'oshash': self.oshash,
|
||||
'id': self.oshash,
|
||||
'samplerate': self.samplerate,
|
||||
'video_codec': self.video_codec,
|
||||
'audio_codec': self.audio_codec,
|
||||
|
|
|
|||
|
|
@ -119,7 +119,7 @@ actions.register(encodingProfile)
|
|||
@login_required_json
|
||||
def upload(request):
|
||||
'''
|
||||
oshash: string
|
||||
id: string
|
||||
frame: [] //multipart frames
|
||||
file: [] //multipart file
|
||||
|
||||
|
|
@ -132,7 +132,7 @@ def upload(request):
|
|||
}
|
||||
'''
|
||||
response = json_response({})
|
||||
f = get_object_or_404_json(models.File, oshash=request.POST['oshash'])
|
||||
f = get_object_or_404_json(models.File, oshash=request.POST['id'])
|
||||
if 'frame' in request.FILES:
|
||||
if f.frames.count() == 0:
|
||||
for frame in request.FILES.getlist('frame'):
|
||||
|
|
@ -164,7 +164,7 @@ class VideoChunkForm(forms.Form):
|
|||
@login_required_json
|
||||
def firefogg_upload(request):
|
||||
profile = request.GET['profile']
|
||||
oshash = request.GET['oshash']
|
||||
oshash = request.GET['id']
|
||||
#handle video upload
|
||||
if request.method == 'POST':
|
||||
#post next chunk
|
||||
|
|
@ -203,7 +203,7 @@ def firefogg_upload(request):
|
|||
f.save()
|
||||
response = {
|
||||
#is it possible to no hardcode url here?
|
||||
'uploadUrl': request.build_absolute_uri('/api/upload/?oshash=%s&profile=%s' % (f.oshash, profile)),
|
||||
'uploadUrl': request.build_absolute_uri('/api/upload/?id=%s&profile=%s' % (f.oshash, profile)),
|
||||
'result': 1
|
||||
}
|
||||
return render_to_json_response(response)
|
||||
|
|
@ -221,6 +221,7 @@ def taskStatus(request):
|
|||
return render_to_json_response(response)
|
||||
actions.register(taskStatus, cache=False)
|
||||
|
||||
|
||||
@login_required_json
|
||||
def moveFiles(request):
|
||||
'''
|
||||
|
|
@ -253,37 +254,34 @@ def moveFiles(request):
|
|||
return render_to_json_response(response)
|
||||
actions.register(moveFiles, cache=False)
|
||||
|
||||
|
||||
@login_required_json
|
||||
def editFile(request):
|
||||
'''
|
||||
change file / item link
|
||||
param data {
|
||||
oshash: hash of file
|
||||
itemId: new itemId
|
||||
id: hash of file
|
||||
part:
|
||||
id_extra: boolean
|
||||
}
|
||||
|
||||
return {
|
||||
status: {'code': int, 'text': string},
|
||||
data: {
|
||||
imdbId:string
|
||||
}
|
||||
}
|
||||
'''
|
||||
#FIXME: permissions, need to be checked
|
||||
data = json.loads(request.POST['data'])
|
||||
f = get_object_or_404_json(models.File, oshash=data['oshash'])
|
||||
f = get_object_or_404_json(models.File, oshash=data['id'])
|
||||
response = json_response()
|
||||
if f.item.id != data['itemId']:
|
||||
if len(data['itemId']) != 7:
|
||||
folder = f.instances.all()[0].folder
|
||||
item_info = utils.parse_path(folder)
|
||||
item = get_item(item_info)
|
||||
else:
|
||||
item = get_item({'imdbId': data['itemId']})
|
||||
f.item = item
|
||||
if data.keys() != ('id', ):
|
||||
for key in data:
|
||||
if key in ('is_extra', 'is_subtitle', 'is_video', 'is_version',
|
||||
'part', 'language'):
|
||||
setattr(f, key, data[key])
|
||||
f.auto = False
|
||||
f.save()
|
||||
#FIXME: other things might need updating here
|
||||
response = json_response(text='updated')
|
||||
return render_to_json_response(response)
|
||||
actions.register(editFile, cache=False)
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue