当前位置: 首页>>代码示例>>Python>>正文


Python models.Settings类代码示例

本文整理汇总了Python中fle_utils.config.models.Settings的典型用法代码示例。如果您正苦于以下问题:Python Settings类的具体用法?Python Settings怎么用?Python Settings使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了Settings类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: set_default_language

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)
开发者ID:aronasorman,项目名称:ka-lite-central,代码行数:26,代码来源:middleware.py

示例2: setUp_fake_device

 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/+9UNhetFxemMrB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J5AKiACZmpSskyJgp+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()
开发者ID:aronasorman,项目名称:ka-lite-central,代码行数:8,代码来源:base.py

示例3: load_keys

def load_keys():
    private_key_string = Settings.get("private_key")
    public_key_string = Settings.get("public_key")
    if private_key_string and public_key_string:
        sys.modules[__name__]._own_key = Key(
            public_key_string=public_key_string,
            private_key_string=private_key_string)
    else:
        reset_keys()
开发者ID:SMILEConsortium,项目名称:ka-lite,代码行数:9,代码来源:crypto.py

示例4: initialize_default_facility

    def initialize_default_facility(cls, 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(cls, name=facility_name)
            if not facility:
                facility = Facility(name=facility_name)
                facility.save()
            Settings.set("default_facility", facility.id)
开发者ID:aronasorman,项目名称:ka-lite-central,代码行数:10,代码来源:models.py

示例5: setup_fake_device

    def setup_fake_device(cls, **kwargs):
        fields = FakeDeviceMixin.DEFAULTS.copy()
        fields.update(kwargs)

        Device.own_device = None

        Settings.set("public_key", fields.get('public_key'))
        Settings.set("private_key", fields.get('private_key'))

        Device.initialize_own_device()
开发者ID:2flcastro,项目名称:ka-lite-central,代码行数:10,代码来源:mixins.py

示例6: setup_server_if_needed

    def setup_server_if_needed(self):
        """Run the setup command, if necessary."""

        try: # Ensure that the database has been synced and a Device has been created
            assert Settings.get("private_key") and Device.objects.count()
        except (DatabaseError, AssertionError): # Otherwise, run the setup command
            self.stdout.write("Setting up KA Lite; this may take a few minutes; please wait!\n")
            call_command("setup", interactive=False)
        # Double check that the setup process successfully created a Device
        assert Settings.get("private_key") and Device.objects.count(), "There was an error configuring the server. Please report the output of this command to Learning Equality."
开发者ID:66eli77,项目名称:ka-lite,代码行数:10,代码来源:kaserve.py

示例7: handle

    def handle(self, *args, **options):
        # Eliminate irrelevant settings
        for opt in BaseCommand.option_list:
            del options[opt.dest]

        # Parse the crappy way that runcherrypy takes args,
        #   or the host/port
        for arg in args:
            if "=" in arg:
                (key,val) = arg.split("=")
                options[key] = val
            elif ":" in arg:
                (options["host"], options["port"]) = arg.split(":")
            elif isnumeric(arg):
                options["port"] = arg
            else:
                raise CommandError("Unexpected argument format: %s" % arg)

        # In order to avoid doing this twice when the autoreloader
        #   loads this process again, only execute the initialization
        #   code if autoreloader won't be run (daemonize), or if
        #   RUN_MAIN is set (autoreloader has started)
        if options["daemonize"] or os.environ.get("RUN_MAIN"):
            self.setup_server_if_needed()

            # we do this on every server request,
            # as we don't know what happens when we're not looking.
            self.reinitialize_server()

        # In case any chronograph threads were interrupted the last time
        # the server was stopped, clear their is_running flags to allow
        # them to be started up again as needed.
        Job.objects.update(is_running=False)


        call_command("collectstatic", interactive=False)

        # set the BUILD_HASH to the current time, so assets get refreshed to their newest versions
        build_hash = str(time.mktime(time.gmtime()))
        logging.debug("Writing %s as BUILD_HASH" % build_hash)
        Settings.set('BUILD_HASH', build_hash)

        if options['startuplock']:
            os.unlink(options['startuplock'])
        
        # Now call the proper command
        if not options["production"]:
            call_command("runserver", "%s:%s" % (options["host"], options["port"]))
        else:
            del options["production"]
            sys.stdout.write("To access KA Lite from another connected computer, try the following address(es):\n")
            for addr in get_ip_addresses():
                sys.stdout.write("\thttp://%s:%s/\n" % (addr, settings.USER_FACING_PORT()))
            call_command("runcherrypyserver", *["%s=%s" % (key,val) for key, val in options.iteritems()])
开发者ID:JGOODYEARUCSD,项目名称:ka-lite,代码行数:54,代码来源:kaserve.py

示例8: initialize_default_facility

    def initialize_default_facility(cls, facility_name=None):
        facility_name = facility_name or getattr(settings, "INSTALL_FACILITY_NAME", None) or unicode(_("Default Facility"))

        # Finally, install a facility--would help users get off the ground
        facilities = Facility.objects.filter(name=facility_name)
        if facilities.count() == 0:
            # Create a facility, set it as the default.
            facility = Facility(name=facility_name)
            facility.save()
            Settings.set("default_facility", facility.id)

        elif Settings.get("default_facility") not in [fac.id for fac in facilities.all()]:
            # Use an existing facility as the default, if one of them isn't the default already.
            Settings.set("default_facility", facilities[0].id)
开发者ID:SMILEConsortium,项目名称:ka-lite,代码行数:14,代码来源:models.py

示例9: setup_server_if_needed

    def setup_server_if_needed(self):
        """Run the setup command, if necessary.
            It's necessary if the Settings model doesn't have a "database_version" or if that version doesn't match
            kalite.version.VERSION, indicating the source has been changed. Then setup is run to create/migrate the db.
        """

        try:
            from kalite.version import VERSION
            assert Settings.get("database_version") == VERSION
        except (DatabaseError, AssertionError):
            logging.info("Setting up KA Lite; this may take a few minutes; please wait!\n")
            call_command("setup", interactive=False)
            # Double check the setup process worked ok.
            assert Settings.get("database_version") == VERSION, "There was an error configuring the server. Please report the output of this command to Learning Equality."
开发者ID:xuewenfei,项目名称:ka-lite,代码行数:14,代码来源:initialize_kalite.py

示例10: get_current_unit_settings_value

def get_current_unit_settings_value(facility_id):
    """
    Get value of current unit based on facility id.  If none, defaults to 1 and creates an
    entry on the Settings.
    """
    name = get_current_unit_settings_name(facility_id)
    value = Settings.get(name, UNITS[0])
    if value == 0:
        # This may be the first time this facility`s current unit is queried so
        # make sure it has a value at Settings so we can either change it on
        # the admin page or at front-end code later.
        value = 1
        Settings.set(name, value)
    return value
开发者ID:prpankajsingh,项目名称:ka-lite,代码行数:14,代码来源:utils.py

示例11: handle

 def handle(self, *args, **options):
     if Settings.get("private_key"):
         self.stderr.write("Error: This device already has an encryption key generated for it; aborting.\n")
         return
     self.stdout.write("Generating 2048-bit RSA encryption key (may take a few minutes; please wait)...\n")
     reset_keys()
     self.stdout.write("Done!\n")
开发者ID:2flcastro,项目名称:ka-lite,代码行数:7,代码来源:generatekeys.py

示例12: facility_from_request_wrapper_fn

    def facility_from_request_wrapper_fn(request, *args, **kwargs):
        facility = None

        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"]

        if not facility and "facility" in request.GET:
            # Facility from querystring
            facility = get_object_or_None(Facility, pk=request.GET["facility"])

        if facility:
            pass

        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

        if "set_default" in request.GET and request.is_admin and facility:
            Settings.set("default_facility", facility.id)

        if facility or "facility" not in kwargs:  # this syntax allows passed in facility param to work.
            kwargs["facility"] = facility
        return handler(request, *args, **kwargs)
开发者ID:2flcastro,项目名称:ka-lite,代码行数:47,代码来源:decorators.py

示例13: setup_server_if_needed

    def setup_server_if_needed(self):
        """Run the setup command, if necessary."""

        try: # Ensure that the database has been synced and a Device has been created
            assert Settings.get("private_key") and Device.objects.count()
        except (DatabaseError, AssertionError): # Otherwise, run the setup command
            self.stdout.write("Setting up KA Lite; this may take a few minutes; please wait!\n")
            call_command("setup", interactive=False)
开发者ID:pkimber,项目名称:aliuacademy_org,代码行数:8,代码来源:kaserve.py

示例14: set_exam_mode_on

def set_exam_mode_on(test_object):
    """
    Sets the value of the EXAM_MODE_ON.
    TODO(cpauya): check if user is admin/teacher
    """

    # Figure out what the previous exam was, and then turn off exam mode
    # (to make sure we trigger any exam unsetting events)
    old_test_id = get_exam_mode_on()
    set_exam_mode_off()

    new_test_id = getattr(test_object, "test_id", test_object)

    # only enable exam if it isn't the same one previously enabled
    # (since we for some reason just call the same method to toggle off)
    if old_test_id != new_test_id:
        Settings.set(SETTINGS_KEY_EXAM_MODE, new_test_id)
开发者ID:prpankajsingh,项目名称:ka-lite,代码行数:17,代码来源:utils.py

示例15: set_current_unit_settings_value

def set_current_unit_settings_value(facility_id, value):
    """
    Set the value of the current unit on Settings based on the facility id.
    """
    old_unit = get_current_unit_settings_value(facility_id)
    name = get_current_unit_settings_name(facility_id)
    s = Settings.set(name, value)
    unit_switch.send(sender="None", old_unit=old_unit, new_unit=value, facility_id=facility_id)
    return s
开发者ID:prpankajsingh,项目名称:ka-lite,代码行数:9,代码来源:utils.py


注:本文中的fle_utils.config.models.Settings类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。