'Entry point for Studio transcript handlers.
Dispatches:
/translation/[language_id] - language_id sould be in url.
`translation` dispatch support following HTTP methods:
`POST`:
Upload srt file. Check possibility of generation of proper sjson files.
For now, it works only for self.transcripts, not for `en`.
Do not update self.transcripts, as fields are updated on save in Studio.
`GET:
Return filename from storage. SRT format is sent back on success. Filename should be in GET dict.
We raise all exceptions right in Studio:
NotFoundError:
Video or asset was deleted from module/contentstore, but request came later.
Seems impossible to be raised. module_render.py catches NotFoundErrors from here.
/translation POST:
TypeError:
Unjsonable filename or content.
TranscriptsGenerationException, TranscriptException:
no SRT extension or not parse-able by PySRT
UnicodeDecodeError: non-UTF8 uploaded file content encoding.'

@XBlock.handler
def studio_transcript(self, request, dispatch):

    _ = self.runtime.service(self, 'i18n').ugettext
    if dispatch.startswith('translation'):
        language = dispatch.replace('translation', '').strip('/')
        if (not language):
            log.info('Invalid    /translation    request:    no    language.')
            return Response(status=400)
        if (request.method == 'POST'):
            subtitles = request.POST['file']
            try:
                file_data = subtitles.file.read()
                unicode(file_data, 'utf-8', 'strict')
            except UnicodeDecodeError:
                log.info('Invalid    encoding    type    for    transcript    file:    {}'.format(subtitles.filename))
                msg = _('Invalid    encoding    type,    transcripts    should    be    UTF-8    encoded.')
                return Response(msg, status=400)
            save_to_store(file_data, unicode(subtitles.filename), 'application/x-subrip', self.location)
            generate_sjson_for_all_speeds(self, unicode(subtitles.filename), {}, language)
            response = {'filename': unicode(subtitles.filename), 'status': 'Success'}
            return Response(json.dumps(response), status=201)
        elif (request.method == 'GET'):
            filename = request.GET.get('filename')
            if (not filename):
                log.info('Invalid    /translation    request:    no    filename    in    request.GET')
                return Response(status=400)
            content = Transcript.get_asset(self.location, filename).data
            response = Response(content, headerlist=[('Content-Disposition', 'attachment;    filename="{}"'.format(filename.encode('utf8'))), ('Content-Language', language)])
            response.content_type = Transcript.mime_types['srt']
    else:
        log.debug('Dispatch    is    not    allowed')
        response = Response(status=404)
    return response
