Beispiel #1
0
def addvideo(request):
    """View to present a video upload form and process
    the upload"""

    if request.method == 'POST':

        form = VideoUploadForGlossForm(request.POST, request.FILES)
        if form.is_valid():

            gloss_id = form.cleaned_data['gloss_id']
            gloss = get_object_or_404(Gloss, pk=gloss_id)
            
            vfile = form.cleaned_data['videofile']
            
            # construct a filename for the video, use sn
            # if present, otherwise use idgloss+gloss id
            if gloss.sn != None:
                vfile.name = str(gloss.sn) + ".mp4"
            else:
                vfile.name = gloss.idgloss + "-" + str(gloss.pk) + ".mp4"
            
            redirect_url = form.cleaned_data['redirect']

            # deal with any existing video for this sign
            oldvids = GlossVideo.objects.filter(gloss=gloss)
            for v in oldvids:
                v.reversion()

            video = GlossVideo(videofile=vfile, gloss=gloss)
            video.save()
        
            # TODO: provide some feedback that it worked (if
            # immediate display of video isn't working)
            return redirect(redirect_url)

    # if we can't process the form, just redirect back to the
    # referring page, should just be the case of hitting
    # Upload without choosing a file but could be
    # a malicious request, if no referrer, go back to root
    if request.META.has_key('HTTP_REFERER'):
        url = request.META['HTTP_REFERER']
    else:
        url = '/'
    return redirect(url)
Beispiel #2
0
def addvideo(request):
    """View to present a video upload form and process the upload"""

    if request.method == 'POST':

        form = VideoUploadForGlossForm(request.POST, request.FILES)
        if form.is_valid():
            gloss_id = form.cleaned_data['gloss_id']
            gloss = get_object_or_404(Gloss, pk=gloss_id)

            vfile = form.cleaned_data['videofile']

            video = GlossVideo(gloss=gloss)
            # Save the GlossVideo to get a primary key
            video.save()

            # Construct a filename for the video
            vfile.name = GlossVideo.create_filename(gloss.idgloss, gloss.pk, video.pk)
            video.videofile = vfile
            video.save()

            # TODO: provide some feedback that it worked (if immediate display of video isn't working)

            redirect_url = form.cleaned_data['redirect']

            return redirect(redirect_url)

    # if we can't process the form, just redirect back to the
    # referring page, should just be the case of hitting
    # Upload without choosing a file but could be
    # a malicious request, if no referrer, go back to root
    if 'HTTP_REFERER' in request.META:
        url = request.META['HTTP_REFERER']
    else:
        url = '/'
    return redirect(url)
Beispiel #3
0
def addvideo(request):
    """View to present a video upload form and process
    the upload"""

    if request.method == 'POST':

        form = VideoUploadForGlossForm(request.POST, request.FILES)
        if form.is_valid():

            gloss_id = form.cleaned_data['gloss_id']
            gloss = get_object_or_404(Gloss, pk=gloss_id)

            vfile = form.cleaned_data['videofile']

            # construct a filename for the video, use sn
            # if present, otherwise use idgloss+gloss id
            if gloss.sn != None:
                vfile.name = str(gloss.sn) + ".mp4"
            else:
                vfile.name = gloss.idgloss + "-" + str(gloss.pk) + ".mp4"

            redirect_url = form.cleaned_data['redirect']

            # deal with any existing video for this sign
            goal_folder = WRITABLE_FOLDER + GLOSS_VIDEO_DIRECTORY + '/' + gloss.idgloss[:
                                                                                        2] + '/'
            goal_filename = gloss.idgloss + '-' + str(gloss.pk) + '.mp4'
            goal_location = goal_folder + goal_filename
            if os.path.isfile(goal_location):
                backup_id = 1
                made_backup = False

                while not made_backup:

                    if not os.path.isfile(goal_location + '_' +
                                          str(backup_id)):
                        os.rename(goal_location,
                                  goal_location + '_' + str(backup_id))
                        made_backup = True
                        # Issue #162: log the upload history
                        log_entry = GlossVideoHistory(
                            action="rename",
                            gloss=gloss,
                            actor=request.user,
                            uploadfile=vfile,
                            goal_location=goal_location + '_' + str(backup_id))
                        log_entry.save()
                    else:
                        backup_id += 1

            video = GlossVideo(videofile=vfile, gloss=gloss)
            video.save()

            # Issue #162: log the upload history
            log_entry = GlossVideoHistory(action="upload",
                                          gloss=gloss,
                                          actor=request.user,
                                          uploadfile=vfile,
                                          goal_location=goal_location)
            log_entry.save()

            # Issue #197: convert to thumbnail
            try:
                from CNGT_scripts.python.resizeVideos import VideoResizer

                resizer = VideoResizer([goal_location], FFMPEG_PROGRAM, 180, 0,
                                       0)
                resizer.run()
            except ImportError as i:
                print(i.message)

            # Issue #214: generate still image
            from signbank.tools import generate_still_image
            generate_still_image(gloss.idgloss[:2], goal_folder, goal_filename)

            # TODO: provide some feedback that it worked (if
            # immediate display of video isn't working)
            return redirect(redirect_url)

    # if we can't process the form, just redirect back to the
    # referring page, should just be the case of hitting
    # Upload without choosing a file but could be
    # a malicious request, if no referrer, go back to root
    if request.META.has_key('HTTP_REFERER'):
        url = request.META['HTTP_REFERER']
    else:
        url = '/'
    return redirect(url)