示例#1
0
文件: views.py 项目: annasob/mirosubs
def upload_subtitles(request):
    output = dict(success=False)
    form = SubtitlesUploadForm(request.user, request.POST, request.FILES)
    if form.is_valid():
        form.save()
        output['success'] = True
    else:
        output['errors'] = form.get_errors()
    return HttpResponse(json.dumps(output), "text/javascript")
示例#2
0
def upload_subtitles(request):
    output = dict(success=False)
    form = SubtitlesUploadForm(request.user, request.POST, request.FILES)
    if form.is_valid():
        language = form.save()
        output['success'] = True
        output['next'] = language.get_absolute_url()
    else:
        output['errors'] = form.get_errors()
    return HttpResponse(json.dumps(output), "text/javascript")
示例#3
0
def upload_subtitles(request):
    output = dict(success=False)
    form = SubtitlesUploadForm(request.user, request.POST, request.FILES)
    if form.is_valid():
        language = form.save()
        output["success"] = True
        output["next"] = language.get_absolute_url()
    else:
        output["errors"] = form.get_errors()
    return HttpResponse(json.dumps(output), "text/javascript")
示例#4
0
文件: views.py 项目: crodjer/mirosubs
def upload_subtitles(request):
    output = dict(success=False)
    form = SubtitlesUploadForm(request.user, request.POST, request.FILES)
    if form.is_valid():
        try:
            language = form.save()
            output['success'] = True
            output['next'] = language.get_absolute_url()
            transaction.commit()
        except AlreadyEditingException, e:
            output['errors'] = {"_all__":[force_unicode(e.msg)]}
            transaction.rollback()
示例#5
0
    def _import_srt(self, video, videosrt_url):
        h = httplib2.Http()
        resp, content = h.request(videosrt_url, "GET")

        if resp.status == 200:
            data = {'video': video.id,
                    'language': 'en',
                    'video_language': 'en',
                    'is_complete': True }
            file_data = {'subtitles': SimpleUploadedFile('subs.srt', content)}
            form = SubtitlesUploadForm(
                CustomUser.get_youtube_anonymous(), data, file_data)
            if form.is_valid():
                form.save()
            else:
                print('url {0} did not return valid srt data'.format(videosrt_url))
示例#6
0
    def _import_srt(self, video, videosrt_url):
        h = httplib2.Http()
        resp, content = h.request(videosrt_url, "GET")

        if resp.status == 200:
            data = {
                'video': video.id,
                'language': 'en',
                'video_language': 'en',
                'is_complete': True
            }
            file_data = {'subtitles': SimpleUploadedFile('subs.srt', content)}
            form = SubtitlesUploadForm(CustomUser.get_youtube_anonymous(),
                                       data, file_data)
            if form.is_valid():
                form.save()
            else:
                print('url {0} did not return valid srt data'.format(
                    videosrt_url))
示例#7
0
def upload_subtitles(request):
    output = dict(success=False)
    form = SubtitlesUploadForm(request.user, request.POST, request.FILES)

    if form.is_valid():
        try:
            language = form.save()
            output['success'] = True
            if form._sl_created:
                output['msg'] = ugettext(u'Thank you for uploading. It will take a minute or so for your subtitles to appear.')
            else:
                output['msg'] = ugettext(u'Your changes have been saved.')
            output['next'] = language.get_absolute_url()
            transaction.commit()
        except AlreadyEditingException, e:
            output['errors'] = {"_all__":[force_unicode(e.msg)]}
            transaction.rollback()
        except Exception, e:
            #trying find out one error on dev-server. hope this should help
            transaction.rollback()
            raise e
示例#8
0
def upload_subtitles(request):
    output = dict(success=False)
    form = SubtitlesUploadForm(request.user, request.POST, request.FILES)

    if form.is_valid():
        try:
            language = form.save()
            output['success'] = True
            if form._sl_created:
                output['msg'] = ugettext(
                    u'Thank you for uploading. It will take a minute or so for your subtitles to appear.'
                )
            else:
                output['msg'] = ugettext(u'Your changes have been saved.')
            output['next'] = language.get_absolute_url()
            transaction.commit()
        except AlreadyEditingException, e:
            output['errors'] = {"_all__": [force_unicode(e.msg)]}
            transaction.rollback()
        except Exception, e:
            #trying find out one error on dev-server. hope this should help
            transaction.rollback()
            raise e
示例#9
0
def upload_subtitles(request):
    output = dict(success=False)
    form = SubtitlesUploadForm(request.user, request.POST, request.FILES)

    if form.is_valid():
        try:
            language = form.save()
            output['success'] = True
            if form._sl_created:
                output['msg'] = ugettext(
                    u'Thank you for uploading. It will take a minute or so for your subtitles to appear.'
                )
            else:
                output['msg'] = ugettext(u'Your changes have been saved.')
            output['next'] = language.get_absolute_url()
            transaction.commit()
        except AlreadyEditingException, e:
            output['errors'] = {"_all__": [force_unicode(e.msg)]}
            transaction.rollback()
        except Exception, e:
            output['errors'] = {"_all__": [force_unicode(e)]}
            transaction.rollback()
            from raven.contrib.django.models import client
            client.create_from_exception()