示例#1
0
def start_subtitle_download(request):
    update_set = simplejson.loads(request.raw_post_data or "{}").get("update_set", "existing")
    language = simplejson.loads(request.raw_post_data or "{}").get("language", "")

    # Set subtitle language
    Settings.set("subtitle_language", language)

    # Get the json file with all srts
    request_url = "http://%s/static/data/subtitles/languages/%s_available_srts.json" % (settings.CENTRAL_SERVER_HOST, language)
    try:
        r = requests.get(request_url)
        r.raise_for_status() # will return none if 200, otherwise will raise HTTP error
        available_srts = set((r.json)["srt_files"])
    except ConnectionError:
        return JsonResponse({"error": "The central server is currently offline."}, status=500)
    except HTTPError:
        return JsonResponse({"error": "No subtitles available on central server for language code: %s; aborting." % language}, status=500)

    if update_set == "existing":
        videofiles = VideoFile.objects.filter(subtitles_downloaded=False, subtitle_download_in_progress=False)
    else:
        videofiles = VideoFile.objects.filter(subtitle_download_in_progress=False)

    queue_count = 0
    for chunk in break_into_chunks(available_srts):
        queue_count += videofiles.filter(youtube_id__in=chunk).update(flagged_for_subtitle_download=True, subtitles_downloaded=False)

    if queue_count == 0:
        return JsonResponse({"info": "There aren't any subtitles available in this language for your currently downloaded videos."}, status=200)
        
    force_job("subtitledownload", "Download Subtitles")
    return JsonResponse({})
示例#2
0
def start_subtitle_download(request):
    new_only = simplejson.loads(request.raw_post_data
                                or "{}").get("new_only", False)
    language = simplejson.loads(request.raw_post_data
                                or "{}").get("language", "")
    language_list = topicdata.LANGUAGE_LIST
    current_language = Settings.get("subtitle_language")
    new_only = new_only and (current_language == language)
    if language in language_list:
        Settings.set("subtitle_language", language)
    else:
        return JsonResponse(
            {
                "error":
                "This language is not currently supported - please update the language list"
            },
            status=500)
    if new_only:
        videofiles = VideoFile.objects.filter(Q(percent_complete=100)
                                              | Q(flagged_for_download=True),
                                              subtitles_downloaded=False)
    else:
        videofiles = VideoFile.objects.filter(
            Q(percent_complete=100) | Q(flagged_for_download=True))
    for videofile in videofiles:
        videofile.cancel_download = False
        if videofile.subtitle_download_in_progress:
            continue
        videofile.flagged_for_subtitle_download = True
        if not new_only:
            videofile.subtitles_downloaded = False
        videofile.save()
    force_job("subtitledownload", "Download Subtitles")
    return JsonResponse({})
示例#3
0
def set_default_language(request, lang_code, global_set=False):
    """
    global_set has different meanings for different users.
    For students, it means their personal default language
    For teachers, it means their personal default language
    For django users, it means the server language.
    """

    # Get lang packs directly, to force reloading, as they may have changed.
    lang_packs = get_installed_language_packs(force=True).keys()
    lang_code = select_best_available_language(
        lang_code, available_codes=lang_packs
    )  # Make sure to reload available languages; output is in django_lang format

    if lang_code != request.session.get("default_language"):
        logging.debug("setting session language to %s" % lang_code)
        request.session["default_language"] = lang_code

    if global_set:
        if request.is_django_user and lang_code != Settings.get(
                "default_language"):
            logging.debug("setting server default language to %s" % lang_code)
            Settings.set("default_language", lang_code)
        elif not request.is_django_user and request.is_logged_in and lang_code != request.session[
                "facility_user"].default_language:
            logging.debug("setting user default language to %s" % lang_code)
            request.session["facility_user"].default_language = lang_code
            request.session["facility_user"].save()

    set_request_language(request, lang_code)
示例#4
0
    def process_request(self, request):
        """
        Process requests to set language, redirect to the same URL to continue processing
        without leaving the "set" in the browser history.
        """

        # Set the set of available languages
        if "language_choices" not in request.session:
            request.session["language_choices"] = list(LanguagePack.objects.all())
            request.session["language_codes"] = [convert_language_code_format(lp.code) for lp in request.session["language_choices"]]

        # Set the current language, and redirect (to clean browser history)
        if request.is_admin and request.GET.get("set_default_language"):
            Settings.set("default_language", request.GET["set_default_language"])
            request.session["default_language"] = request.GET["set_default_language"]
            logging.debug("setting default language to %s" % request.GET["set_default_language"])

            request.session["django_language"] = request.GET["set_default_language"]
            logging.debug("setting session language to %s" % request.session["django_language"])
            return HttpResponseRedirect(request.path)

        elif request.GET.get("set_language"):
            request.session["django_language"] = request.GET["set_language"]
            logging.debug("setting session language to %s" % request.session["django_language"])
            return HttpResponseRedirect(request.path)

        # Process the current language
        if "default_language" not in request.session:
            request.session["default_language"] = Settings.get("default_language") or settings.LANGUAGE_CODE
        if "django_language" not in request.session:
            request.session["django_language"] = request.session["default_language"]
            logging.debug("setting session language to %s" % request.session["django_language"])

        request.language = request.session["django_language"]
示例#5
0
def set_default_language(request, lang_code, global_set=False):
    """
    global_set has different meanings for different users.
    For students, it means their personal default language
    For teachers, it means their personal default language
    For django users, it means the server language.
    """

    # Get lang packs directly, to force reloading, as they may have changed.
    lang_packs = get_installed_language_packs(force=True).keys()
    lang_code = select_best_available_language(lang_code, available_codes=lang_packs)  # Make sure to reload available languages; output is in django_lang format

    if lang_code != request.session.get("default_language"):
        logging.debug("setting session language to %s" % lang_code)
        request.session["default_language"] = lang_code

    if global_set:
        if request.is_django_user and lang_code != Settings.get("default_language"):
            logging.debug("setting server default language to %s" % lang_code)
            Settings.set("default_language", lang_code)
        elif not request.is_django_user and request.is_logged_in and lang_code != request.session["facility_user"].default_language:
            logging.debug("setting user default language to %s" % lang_code)
            request.session["facility_user"].default_language = lang_code
            request.session["facility_user"].save()

    set_request_language(request, lang_code)
示例#6
0
def start_subtitle_download(request):
    update_set = simplejson.loads(request.raw_post_data or "{}").get("update_set", "existing")
    language = simplejson.loads(request.raw_post_data or "{}").get("language", "")

    # Set subtitle language
    Settings.set("subtitle_language", language)

    # Get the json file with all srts
    request_url = "http://%s/static/data/subtitles/languages/%s_available_srts.json" % (settings.CENTRAL_SERVER_HOST, language)
    try:
        r = requests.get(request_url)
        r.raise_for_status() # will return none if 200, otherwise will raise HTTP error
        available_srts = set((r.json)["srt_files"])
    except ConnectionError:
        return JsonResponse({"error": "The central server is currently offline."}, status=500)
    except HTTPError:
        return JsonResponse({"error": "No subtitles available on central server for language code: %s; aborting." % language}, status=500)

    if update_set == "existing":
        videofiles = VideoFile.objects.filter(subtitles_downloaded=False, subtitle_download_in_progress=False)
    else:
        videofiles = VideoFile.objects.filter(subtitle_download_in_progress=False)

    queue_count = 0
    for chunk in break_into_chunks(available_srts):
        queue_count += videofiles.filter(youtube_id__in=chunk).update(flagged_for_subtitle_download=True, subtitles_downloaded=False)

    if queue_count == 0:
        return JsonResponse({"info": "There aren't any subtitles available in this language for your currently downloaded videos."}, status=200)
        
    force_job("subtitledownload", "Download Subtitles")
    return JsonResponse({})
示例#7
0
 def setUp_fake_device(self):
     """
     Fake the install process, to (quickly) make a key and set up the own_device()
     """
     # Could be a fixture, but safer to simply hard-code.
     Settings.set("public_key", u'MIIBCgKCAQEAlbIPLnQH2dORFBK8i9x7/3E0DR571S01aP7M0TJD8vJf8OrgL8pnru3o2Jaoni1XasCZgizvM4GNImk9geqPP/sFkj0cf/MXSLr1VDKo1SoflST9yTbOi7tzVuhTeL4P3LJL6PO6iNiWkjAdqp9QX3mE/DHh/Q40G68meRw6dPDI4z8pyUcshOpxAHTSh2YQ39LJAxP7YS26yjDX/+9UNhetFxemMrBZO0UKtJYggPYRlMZmlTZLBU4ODMmK6MT26fB4DC4ChA3BD4OFiGDHI/iSy+iYJlcWaldbZtc+YfZlGhvsLnJlrp4WYykJSH5qeBuI7nZLWjYWWvMrDepXowIDAQAB')
     Settings.set("private_key", u'-----BEGIN RSA PRIVATE KEY-----\nMIIEqQIBAAKCAQEAlbIPLnQH2dORFBK8i9x7/3E0DR571S01aP7M0TJD8vJf8Org\nL8pnru3o2Jaoni1XasCZgizvM4GNImk9geqPP/sFkj0cf/MXSLr1VDKo1SoflST9\nyTbOi7tzVuhTeL4P3LJL6PO6iNiWkjAdqp9QX3mE/DHh/Q40G68meRw6dPDI4z8p\nyUcshOpxAHTSh2YQ39LJAxP7YS26yjDX/+9UNhetFxemMrBZO0UKtJYggPYRlMZm\nlTZLBU4ODMmK6MT26fB4DC4ChA3BD4OFiGDHI/iSy+iYJlcWaldbZtc+YfZlGhvs\nLnJlrp4WYykJSH5qeBuI7nZLWjYWWvMrDepXowIDAQABAoIBAD8S/a6XGU/BA1ov\n4t4TkvO44TO96nOSTvTkl6x1v4e4dJBwhvHcGP/uIrRQFtA/TpwedxAQmuFa7vrW\n2SHKkX1l6Z0Kvt1yshblH8XQaq8WxqPzKDQGMdVSsHCoB7PScaCOR8nqGGjcyeTi\n/T0NT7JK46vX4N7dgttrE+WixOrtDOUJLX92tGSp8bZgg284fV053nJqYHHROpmZ\nCibM5HK8B/19ULCpglGQCUVmJPtRzNK1bE9OlB8P5aZzdEd82oC8TKfSGmByO1TI\nCat6x8e0hYVIDElYGdcW5CDAr6rbU0CXOxxQAz3gJFDe1/RbbGJEdjO3IulYbR4H\nBK+nGxECgYkA424wFuQGRAwig//SNasv5aIqz2qnczL5ob3MXCFR4aOMowS94qvd\neRG9McxgRwbEApOTMVMAUYlBMkKE//sBM9XWQ4q8igJ+TUlV8RRQ8AP6hMUhSXX0\nNeEECcauP4vI6hhsnTsG/OQ4pr/4bEewsyXFwPSGkh2v3O+fuc6A8RywQ3u6icc+\n9wJ5AKiACZmpSskyJgp+3X0jpYixb7pQ9gU6QpJmP9Z2DdUNnm0Y5tDjnaCd/Bvy\nmNuCWqNbYdlEYH32B3sCshzFCqQwkgSMOa84cHQHx4Nx7SG2fUp9w1ExvnMRzrnw\n3sjB3ptbNhk1yrkzhFbd6ZG4fsL5Mb0EurAFtQKBiFCUVc2GdQHfGsuR9DS3tnyx\n/GEI9NNIGFJKIQHzfENp4wZPQ8fwBMREmLfwJZyEtSYEi35KXi6FZugb0WuwzzhC\nZ2v+19Y+E+nmNeD4xcSEZFpuTeDtPd1pIDkmf85cBI+Mn88FfvBTHA9YrPgQXnba\nxzoaaSOUCR9Kd1kp5V2IQJtoVytBwPkCeFIDD6kkxuuqZu2Q1gkEgptHkZPjt/rP\nYnuTHNsrVowuNr/u8NkXEC+O9Zg8ub2NcsQzxCpVp4lnaDitFTf/h7Bmm4tvHNx1\n4fX3m1oU51ATXGQXVit8xK+JKU9DN4wLIGgJOwmGLwd5VZ5aIEb2v2vykgzn8l2e\nSQKBiQC7CJVToYSUWnDGwCRsF+fY9jUculveAQpVWj03nYBtBdTh2EWcvfoSjjfl\nmpzrraojpQlUhrbUf5MU1fD9+i6swrCCvfjXITG3c1bkkB5AaQW7NiPHvDRMuDpc\nHIQ+vqzdn4iUlt7KB5ChpnZMmgiOdCBM0vQsZlVCbp0ZNLqVYhFASQnWl6V9\n-----END RSA PRIVATE KEY-----\n')
     Device.initialize_own_device()
示例#8
0
	def process_request(self, request):
		if "django_language" not in request.session:
			request.session["django_language"] = Settings.get("default_language") or "en"
		if request.GET.get("set_language"):
			request.session["django_language"] = request.GET.get("set_language")
			return HttpResponseRedirect(request.path)
		if request.is_admin and request.GET.get("set_default_language"):
			Settings.set("default_language", request.GET.get("set_default_language"))
			return HttpResponseRedirect(request.path)
示例#9
0
 def process_request(self, request):
     if request.user.is_authenticated() and "django_language" not in request.session:
         request.session["django_language"] = Settings.get("default_language") or settings.LANGUAGE_CODE
     if request.GET.get("set_language"):
         request.session["django_language"] = request.GET.get("set_language")
         return HttpResponseRedirect(request.path)
     if request.is_admin and request.GET.get("set_default_language"):
         Settings.set("default_language", request.GET.get("set_default_language"))
         return HttpResponseRedirect(request.path)
示例#10
0
文件: crypto.py 项目: dummey/ka-lite
def reset_keys():
    try:
        (public_key, private_key) = rsa.newkeys(2048, poolsize=4)
    except:
        (public_key, private_key) = rsa.newkeys(2048)
    Settings.set("private_key", private_key.save_pkcs1())
    Settings.set("public_key", serialize_public_key(public_key))
    keys["private"] = private_key
    keys["public"] = public_key
示例#11
0
def initialize_facility(facility_name=None):
    facility_name = facility_name or settings.INSTALL_FACILITY_NAME

    # Finally, install a facility--would help users get off the ground
    if facility_name:
        facility = get_object_or_None(Facility, name=facility_name)
        if not facility:
            facility = Facility(name=facility_name)
            facility.save()
        Settings.set("default_facility", facility.id)
示例#12
0
def initialize_facility(facility_name=None):
    facility_name = facility_name or settings.INSTALL_FACILITY_NAME

    # Finally, install a facility--would help users get off the ground
    if facility_name:
        facility = get_object_or_None(Facility, name=facility_name)
        if not facility:
            facility = Facility(name=facility_name)
            facility.save()
        Settings.set("default_facility", facility.id)
示例#13
0
def get_facility_from_request(request):
    if "facility" in request.GET:
        facility = get_object_or_None(Facility, pk=request.GET["facility"])
        if "set_default" in request.GET and request.is_admin and facility:
            Settings.set("default_facility", facility.id)
    elif "facility_user" in request.session:
        facility = request.session["facility_user"].facility
    elif Facility.objects.count() == 1:
        facility = Facility.objects.all()[0]
    else:
        facility = get_object_or_None(Facility, pk=Settings.get("default_facility"))
    return facility
示例#14
0
文件: views.py 项目: dummey/ka-lite
def get_facility_from_request(request):
    if "facility" in request.GET:
        facility = get_object_or_None(Facility, pk=request.GET["facility"])
        if "set_default" in request.GET and request.is_admin and facility:
            Settings.set("default_facility", facility.id)
    elif "facility_user" in request.session:
        facility = request.session["facility_user"].facility
    elif Facility.objects.count() == 1:
        facility = Facility.objects.all()[0]
    else:
        facility = get_object_or_None(Facility, pk=Settings.get("default_facility"))
    return facility
示例#15
0
 def process_request(self, request):
     if request.user.is_authenticated(
     ) and "django_language" not in request.session:
         request.session["django_language"] = Settings.get(
             "default_language") or settings.LANGUAGE_CODE
     if request.GET.get("set_language"):
         request.session["django_language"] = request.GET.get(
             "set_language")
         return HttpResponseRedirect(request.path)
     if request.is_admin and request.GET.get("set_default_language"):
         Settings.set("default_language",
                      request.GET.get("set_default_language"))
         return HttpResponseRedirect(request.path)
示例#16
0
 def wrapper_fn(request, *args, **kwargs):
     if "facility_id" in kwargs:
         facility = get_object_or_None(Facility, pk=kwargs["facility_id"])
     elif "facility" in request.GET:
         facility = get_object_or_None(Facility, pk=request.GET["facility"])
         if "set_default" in request.GET and request.is_admin and facility:
             Settings.set("default_facility", facility.id)
     elif "facility_user" in request.session:
         facility = request.session["facility_user"].facility
     elif Facility.objects.count() == 1:
         facility = Facility.objects.all()[0]
     else:
         facility = get_object_or_None(Facility, pk=Settings.get("default_facility"))
     return handler(request, *args, facility=facility, **kwargs)
示例#17
0
文件: base.py 项目: louhow/lex
 def setUp_fake_device(self):
     """
     Fake the install process, to (quickly) make a key and set up the own_device()
     """
     # Could be a fixture, but safer to simply hard-code.
     Settings.set(
         "public_key",
         u'MIIBCgKCAQEAlbIPLnQH2dORFBK8i9x7/3E0DR571S01aP7M0TJD8vJf8OrgL8pnru3o2Jaoni1XasCZgizvM4GNImk9geqPP/sFkj0cf/MXSLr1VDKo1SoflST9yTbOi7tzVuhTeL4P3LJL6PO6iNiWkjAdqp9QX3mE/DHh/Q40G68meRw6dPDI4z8pyUcshOpxAHTSh2YQ39LJAxP7YS26yjDX/+9UNhetFxemMrBZO0UKtJYggPYRlMZmlTZLBU4ODMmK6MT26fB4DC4ChA3BD4OFiGDHI/iSy+iYJlcWaldbZtc+YfZlGhvsLnJlrp4WYykJSH5qeBuI7nZLWjYWWvMrDepXowIDAQAB'
     )
     Settings.set(
         "private_key",
         u'-----BEGIN RSA PRIVATE KEY-----\nMIIEqQIBAAKCAQEAlbIPLnQH2dORFBK8i9x7/3E0DR571S01aP7M0TJD8vJf8Org\nL8pnru3o2Jaoni1XasCZgizvM4GNImk9geqPP/sFkj0cf/MXSLr1VDKo1SoflST9\nyTbOi7tzVuhTeL4P3LJL6PO6iNiWkjAdqp9QX3mE/DHh/Q40G68meRw6dPDI4z8p\nyUcshOpxAHTSh2YQ39LJAxP7YS26yjDX/+9UNhetFxemMrBZO0UKtJYggPYRlMZm\nlTZLBU4ODMmK6MT26fB4DC4ChA3BD4OFiGDHI/iSy+iYJlcWaldbZtc+YfZlGhvs\nLnJlrp4WYykJSH5qeBuI7nZLWjYWWvMrDepXowIDAQABAoIBAD8S/a6XGU/BA1ov\n4t4TkvO44TO96nOSTvTkl6x1v4e4dJBwhvHcGP/uIrRQFtA/TpwedxAQmuFa7vrW\n2SHKkX1l6Z0Kvt1yshblH8XQaq8WxqPzKDQGMdVSsHCoB7PScaCOR8nqGGjcyeTi\n/T0NT7JK46vX4N7dgttrE+WixOrtDOUJLX92tGSp8bZgg284fV053nJqYHHROpmZ\nCibM5HK8B/19ULCpglGQCUVmJPtRzNK1bE9OlB8P5aZzdEd82oC8TKfSGmByO1TI\nCat6x8e0hYVIDElYGdcW5CDAr6rbU0CXOxxQAz3gJFDe1/RbbGJEdjO3IulYbR4H\nBK+nGxECgYkA424wFuQGRAwig//SNasv5aIqz2qnczL5ob3MXCFR4aOMowS94qvd\neRG9McxgRwbEApOTMVMAUYlBMkKE//sBM9XWQ4q8igJ+TUlV8RRQ8AP6hMUhSXX0\nNeEECcauP4vI6hhsnTsG/OQ4pr/4bEewsyXFwPSGkh2v3O+fuc6A8RywQ3u6icc+\n9wJ5AKiACZmpSskyJgp+3X0jpYixb7pQ9gU6QpJmP9Z2DdUNnm0Y5tDjnaCd/Bvy\nmNuCWqNbYdlEYH32B3sCshzFCqQwkgSMOa84cHQHx4Nx7SG2fUp9w1ExvnMRzrnw\n3sjB3ptbNhk1yrkzhFbd6ZG4fsL5Mb0EurAFtQKBiFCUVc2GdQHfGsuR9DS3tnyx\n/GEI9NNIGFJKIQHzfENp4wZPQ8fwBMREmLfwJZyEtSYEi35KXi6FZugb0WuwzzhC\nZ2v+19Y+E+nmNeD4xcSEZFpuTeDtPd1pIDkmf85cBI+Mn88FfvBTHA9YrPgQXnba\nxzoaaSOUCR9Kd1kp5V2IQJtoVytBwPkCeFIDD6kkxuuqZu2Q1gkEgptHkZPjt/rP\nYnuTHNsrVowuNr/u8NkXEC+O9Zg8ub2NcsQzxCpVp4lnaDitFTf/h7Bmm4tvHNx1\n4fX3m1oU51ATXGQXVit8xK+JKU9DN4wLIGgJOwmGLwd5VZ5aIEb2v2vykgzn8l2e\nSQKBiQC7CJVToYSUWnDGwCRsF+fY9jUculveAQpVWj03nYBtBdTh2EWcvfoSjjfl\nmpzrraojpQlUhrbUf5MU1fD9+i6swrCCvfjXITG3c1bkkB5AaQW7NiPHvDRMuDpc\nHIQ+vqzdn4iUlt7KB5ChpnZMmgiOdCBM0vQsZlVCbp0ZNLqVYhFASQnWl6V9\n-----END RSA PRIVATE KEY-----\n'
     )
     Device.initialize_own_device()
示例#18
0
文件: middleware.py 项目: louhow/lex
    def process_request(self, request):
        """
        Process requests to set language, redirect to the same URL to continue processing
        without leaving the "set" in the browser history.
        """

        # Set the set of available languages
        if "language_choices" not in request.session:
            request.session["language_choices"] = list(
                LanguagePack.objects.all())
            request.session["language_codes"] = [
                convert_language_code_format(lp.code)
                for lp in request.session["language_choices"]
            ]

        # Set the current language, and redirect (to clean browser history)
        if request.is_admin and request.GET.get("set_default_language"):
            Settings.set("default_language",
                         request.GET["set_default_language"])
            request.session["default_language"] = request.GET[
                "set_default_language"]
            logging.debug("setting default language to %s" %
                          request.GET["set_default_language"])

            request.session["django_language"] = request.GET[
                "set_default_language"]
            logging.debug("setting session language to %s" %
                          request.session["django_language"])
            return HttpResponseRedirect(request.path)

        elif request.GET.get("set_language"):
            request.session["django_language"] = request.GET["set_language"]
            logging.debug("setting session language to %s" %
                          request.session["django_language"])
            return HttpResponseRedirect(request.path)

        # Process the current language
        if "default_language" not in request.session:
            request.session["default_language"] = Settings.get(
                "default_language") or settings.LANGUAGE_CODE
        if "django_language" not in request.session:
            request.session["django_language"] = request.session[
                "default_language"]
            logging.debug("setting session language to %s" %
                          request.session["django_language"])

        request.language = request.session["django_language"]
示例#19
0
文件: misc.py 项目: Eleonore9/ka-lite
    def wrapper_fn(request, *args, **kwargs):
        if kwargs.get("facility_id", None):
            facility = get_object_or_None(Facility, pk=kwargs["facility_id"])
        elif "facility" in request.GET:
            facility = get_object_or_None(Facility, pk=request.GET["facility"])
            if "set_default" in request.GET and request.is_admin and facility:
                Settings.set("default_facility", facility.id)
        elif "facility_user" in request.session:
            facility = request.session["facility_user"].facility
        elif settings.CENTRAL_SERVER:  # following options are distributed-only
            facility = None
        elif Facility.objects.count() == 1:
            facility = Facility.objects.all()[0]
        else:
            facility = get_object_or_None(Facility, pk=Settings.get("default_facility"))

        return handler(request, *args, facility=facility, **kwargs)
示例#20
0
 def wrapper_fn(request, *args, **kwargs):
     if kwargs.get("facility_id",None):
         facility = get_object_or_None(pk=kwargs["facility_id"])
     elif "facility" in request.GET:
         facility = get_object_or_None(Facility, pk=request.GET["facility"])
         if "set_default" in request.GET and request.is_admin and facility:
             Settings.set("default_facility", facility.id)
     elif "facility_user" in request.session:
         facility = request.session["facility_user"].facility
     elif settings.CENTRAL_SERVER:  # following options are distributed-only
         facility = None
     elif Facility.objects.count() == 1:
         facility = Facility.objects.all()[0]
     else:
         facility = get_object_or_None(Facility, pk=Settings.get("default_facility"))
     
     return handler(request, *args, facility=facility, **kwargs)
示例#21
0
def start_subtitle_download(request):
    update_set = simplejson.loads(request.raw_post_data or "{}").get("update_set", "existing")
    language = simplejson.loads(request.raw_post_data or "{}").get("language", "")
    language_list = topicdata.LANGUAGE_LIST
    language_lookup = topicdata.LANGUAGE_LOOKUP

    # Reset the language
    current_language = Settings.get("subtitle_language")
    if language in language_list:
        Settings.set("subtitle_language", language)
    else:
        return JsonResponse({"error": "This language is not currently supported - please update the language list"}, status=500)

    language_name = language_lookup.get(language)
    # Get the json file with all srts
    request_url = "http://%s/static/data/subtitles/languages/%s_available_srts.json" % (settings.CENTRAL_SERVER_HOST, language)
    try:
        r = requests.get(request_url)
        r.raise_for_status() # will return none if 200, otherwise will raise HTTP error
        available_srts = set((r.json)["srt_files"])
    except ConnectionError:
        return JsonResponse({"error": "The central server is currently offline."}, status=500)
    except HTTPError:
        return JsonResponse({"error": "No subtitles available on central server for %s (language code: %s); aborting." % (language_name, language)}, status=500)

    if update_set == "existing":
        videofiles = VideoFile.objects.filter(Q(percent_complete=100) | Q(flagged_for_download=True), subtitles_downloaded=False, youtube_id__in=available_srts)
    else:
        videofiles = VideoFile.objects.filter(Q(percent_complete=100) | Q(flagged_for_download=True), youtube_id__in=available_srts)

    if not videofiles:
        return JsonResponse({"info": "There aren't any subtitles available in %s (language code: %s) for your current videos." % (language_name, language)}, status=200)
    else:   
        for videofile in videofiles:
            videofile.cancel_download = False
            if videofile.subtitle_download_in_progress:
                continue
            videofile.flagged_for_subtitle_download = True
            if update_set == "all":
                videofile.subtitles_downloaded = False
            videofile.save()
        
    force_job("subtitledownload", "Download Subtitles")
    return JsonResponse({})
示例#22
0
文件: misc.py 项目: louhow/lex
    def wrapper_fn(request, *args, **kwargs):
        if kwargs.get("facility_id", None):  # avoid using blank
            # Facility passed in directly
            facility = get_object_or_None(Facility, pk=kwargs["facility_id"])

        elif "facility" in request.GET:
            # Facility from querystring
            facility = get_object_or_None(Facility, pk=request.GET["facility"])
            if "set_default" in request.GET and request.is_admin and facility:
                Settings.set("default_facility", facility.id)

        elif settings.CENTRAL_SERVER:  # following options are distributed-only
            facility = None

        elif "facility_user" in request.session:
            # Facility from currently logged-in facility user
            facility = request.session["facility_user"].facility

        elif request.session["facility_count"] == 1:
            # There's only one facility
            facility = Facility.objects.all()[0]

        elif request.session["facility_count"] > 0:
            if Settings.get("default_facility"):
                # There are multiple facilities--try to grab the default
                facility = get_object_or_None(
                    Facility, pk=Settings.get("default_facility"))

            elif Facility.objects.filter(
                    Q(signed_by__isnull=True)
                    | Q(signed_by=Device.get_own_device())).count() == 1:
                # Default to a locally created facility (if there are multiple, and none are specified)
                facility = Facility.objects.filter(
                    Q(signed_by__isnull=True)
                    | Q(signed_by=Device.get_own_device()))[0]

            else:
                facility = None
        else:
            # There's nothing; don't bother even hitting the DB
            facility = None

        return handler(request, *args, facility=facility, **kwargs)
    def process_request(self, request):
        """
        Process requests to set language, redirect to the same URL to continue processing
        without leaving the "set" in the browser history.
        """

        if "language_choices" not in request.session:
            # Set the set of available languages
            request.session["language_choices"] = list(LanguagePack.objects.all())

        if "set_default_language" in request.GET:
            # Set the current server default language, and redirect (to clean browser history)
            if not request.is_admin:
                raise PermissionDenied(_("You don't have permissions to set the server's default language."))

            lang_code = lcode_to_django_lang(request.GET["set_default_language"])

            self.set_language(request, lang_code)
            Settings.set("default_language", lang_code)
            logging.debug("setting default language to %s" % lang_code)

            redirect_url = request.get_full_path().replace("set_default_language="+request.GET["set_default_language"], "")
            return HttpResponseRedirect(redirect_url)

        elif "set_language" in request.GET:
            # Set the current user's session language, and redirect (to clean browser history)
            lang_code = lcode_to_django_lang(request.GET["set_language"])

            self.set_language(request, lang_code)
            logging.debug("setting session language to %s" % lang_code)

            redirect_url = request.get_full_path().replace("set_language="+request.GET["set_language"], "")
            return HttpResponseRedirect(redirect_url)

        # Set this request's language based on the listed priority
        cur_lang = lcode_to_django_lang( \
            request.GET.get("lang") \
            or request.session.get("django_language") \
            or request.session.get("default_language") \
            or settings.LANGUAGE_CODE \
        )
        self.set_language(request, cur_lang)
示例#24
0
    def wrapper_fn(request, *args, **kwargs):
        if kwargs.get("facility_id", None):  # avoid using blank
            # Facility passed in directly
            facility = get_object_or_None(Facility, pk=kwargs["facility_id"])
            del kwargs["facility_id"]

        elif "facility" in request.GET:
            # Facility from querystring
            facility = get_object_or_None(Facility, pk=request.GET["facility"])
            if "set_default" in request.GET and request.is_admin and facility:
                Settings.set("default_facility", facility.id)

        elif settings.CENTRAL_SERVER:  # following options are distributed-only
            facility = None

        elif "facility_user" in request.session:
            # Facility from currently logged-in facility user
            facility = request.session["facility_user"].facility

        elif request.session["facility_count"] == 1:
            # There's only one facility
            facility = Facility.objects.all()[0]

        elif request.session["facility_count"] > 0:
            if Settings.get("default_facility"):
                # There are multiple facilities--try to grab the default
                facility = get_object_or_None(Facility, pk=Settings.get("default_facility"))

            elif Facility.objects.filter(Q(signed_by__isnull=True) | Q(signed_by=Device.get_own_device())).count() == 1:
                # Default to a locally created facility (if there are multiple, and none are specified)
                facility = Facility.objects.filter(Q(signed_by__isnull=True) | Q(signed_by=Device.get_own_device()))[0]

            else:
                facility = None
        else:
            # There's nothing; don't bother even hitting the DB
            facility = None

        return handler(request, *args, facility=facility, **kwargs)
示例#25
0
def start_subtitle_download(request):
    new_only = simplejson.loads(request.raw_post_data or "{}").get("new_only", False)
    language = simplejson.loads(request.raw_post_data or "{}").get("language", "")
    language_list = topicdata.LANGUAGE_LIST
    current_language = Settings.get("subtitle_language")
    new_only = new_only and (current_language == language)
    if language in language_list:
        Settings.set("subtitle_language", language)
    else:
        return JsonResponse({"error": "This language is not currently supported - please update the language list"}, status=500)
    if new_only:
        videofiles = VideoFile.objects.filter(Q(percent_complete=100) | Q(flagged_for_download=True), subtitles_downloaded=False)
    else:
        videofiles = VideoFile.objects.filter(Q(percent_complete=100) | Q(flagged_for_download=True))
    for videofile in videofiles:
        videofile.cancel_download = False
        if videofile.subtitle_download_in_progress:
            continue
        videofile.flagged_for_subtitle_download = True
        if not new_only:
            videofile.subtitles_downloaded = False
        videofile.save()
    force_job("subtitledownload", "Download Subtitles")
    return JsonResponse({})
示例#26
0
def reset_keys():
    sys.modules[__name__]._own_key = Key()
    Settings.set("private_key", _own_key.get_private_key_string())
    Settings.set("public_key", _own_key.get_public_key_string())
示例#27
0
def set_as_registered():
    force_job("syncmodels", "Secure Sync", "HOURLY")  # now launches asynchronously
    Settings.set("registered", True)
示例#28
0
文件: views.py 项目: dummey/ka-lite
def set_as_registered():
    force_job("syncmodels", "Secure Sync", "HOURLY")
    Settings.set("registered", True)
示例#29
0
def reset_keys():
    sys.modules[__name__]._own_key = Key()
    Settings.set("private_key", _own_key.get_private_key_string())
    Settings.set("public_key", _own_key.get_public_key_string())
示例#30
0
def set_as_registered():
    force_job("syncmodels", "Secure Sync", "HOURLY")
    Settings.set("registered", True)
示例#31
0
def set_as_registered():
    force_job("syncmodels", "Secure Sync",
              "HOURLY")  # now launches asynchronously
    Settings.set("registered", True)