diff --git a/signbank/dictionary/models.py b/signbank/dictionary/models.py index 9d21eae8..68f618e9 100755 --- a/signbank/dictionary/models.py +++ b/signbank/dictionary/models.py @@ -3972,10 +3972,14 @@ def add_video(self, user, videofile, eaffile, corpus): """Add a video to the annotated sentence""" from signbank.video.models import AnnotatedVideo - if (isinstance(videofile, File) or videofile.content_type == 'django.core.files.uploadedfile.InMemoryUploadedFile')\ - and eaffile.content_type == 'application/octet-stream': + if ((isinstance(videofile, File) or videofile.content_type == 'django.core.files.uploadedfile.InMemoryUploadedFile' \ + or videofile.content_type == 'django.core.files.uploadedfile.TemporaryUploadedFile')\ + and (eaffile.content_type == 'application/octet-stream' or eaffile.content_type == 'django.core.files.uploadedfile.TemporaryUploadedFile'\ + or eaffile.content_type == 'django.core.files.uploadedfile.InMemoryUploadedFile')): annotatedVideo = AnnotatedVideo.objects.create(annotatedsentence=self, videofile=videofile, eaffile=eaffile) - + else: + return None + annotatedVideo.corpus = corpus annotatedVideo.save() diff --git a/signbank/video/views.py b/signbank/video/views.py index cd29fec8..fa19804f 100755 --- a/signbank/video/views.py +++ b/signbank/video/views.py @@ -1,6 +1,7 @@ from django.shortcuts import render, get_object_or_404, redirect from django.template import Context, RequestContext from django.contrib.auth.decorators import login_required +from django.contrib import messages from django.http import HttpResponse from django.conf import settings from django.core.exceptions import ObjectDoesNotExist @@ -65,9 +66,13 @@ def addvideo(request): annotatedSentence.add_contexts(json.loads(contexts)) corpus = form.cleaned_data['corpus_name'] - annotatedSentence.add_video(request.user, vfile, eaf_file, corpus) + annotatedVideo = annotatedSentence.add_video(request.user, vfile, eaf_file, corpus) - annotatedSentence.save() + if annotatedVideo == None: + messages.add_message(request, messages.ERROR, _('Annotated sentence upload went wrong. Please try again.')) + annotatedSentence.delete() + else: + annotatedSentence.save() return redirect(redirect_url)