本文整理汇总了Python中fle_utils.config.models.Settings.set方法的典型用法代码示例。如果您正苦于以下问题:Python Settings.set方法的具体用法?Python Settings.set怎么用?Python Settings.set使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类fle_utils.config.models.Settings
的用法示例。
在下文中一共展示了Settings.set方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: set_default_language
# 需要导入模块: from fle_utils.config.models import Settings [as 别名]
# 或者: from fle_utils.config.models.Settings import set [as 别名]
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)
示例2: setUp_fake_device
# 需要导入模块: from fle_utils.config.models import Settings [as 别名]
# 或者: from fle_utils.config.models.Settings import set [as 别名]
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/D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ECcauP4vI6hhsnTsG/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()
示例3: initialize_default_facility
# 需要导入模块: from fle_utils.config.models import Settings [as 别名]
# 或者: from fle_utils.config.models.Settings import set [as 别名]
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)
示例4: setup_fake_device
# 需要导入模块: from fle_utils.config.models import Settings [as 别名]
# 或者: from fle_utils.config.models.Settings import set [as 别名]
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()
示例5: handle
# 需要导入模块: from fle_utils.config.models import Settings [as 别名]
# 或者: from fle_utils.config.models.Settings import set [as 别名]
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()])
示例6: get_current_unit_settings_value
# 需要导入模块: from fle_utils.config.models import Settings [as 别名]
# 或者: from fle_utils.config.models.Settings import set [as 别名]
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
示例7: initialize_default_facility
# 需要导入模块: from fle_utils.config.models import Settings [as 别名]
# 或者: from fle_utils.config.models.Settings import set [as 别名]
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)
示例8: facility_from_request_wrapper_fn
# 需要导入模块: from fle_utils.config.models import Settings [as 别名]
# 或者: from fle_utils.config.models.Settings import set [as 别名]
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)
示例9: set_exam_mode_on
# 需要导入模块: from fle_utils.config.models import Settings [as 别名]
# 或者: from fle_utils.config.models.Settings import set [as 别名]
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)
示例10: set_exam_mode_off
# 需要导入模块: from fle_utils.config.models import Settings [as 别名]
# 或者: from fle_utils.config.models.Settings import set [as 别名]
def set_exam_mode_off():
"""Switch off exam mode if it is on, do nothing if already off"""
current_test_id = get_exam_mode_on()
if not current_test_id:
return
# do the import here to prevent circular import
from .models import Test
test = Test.all().get(current_test_id, None)
if test and test.practice:
exam_unset.send(sender="None", test_id=current_test_id)
Settings.set(SETTINGS_KEY_EXAM_MODE, "")
return
示例11: set_current_unit_settings_value
# 需要导入模块: from fle_utils.config.models import Settings [as 别名]
# 或者: from fle_utils.config.models.Settings import set [as 别名]
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
示例12: register_device
# 需要导入模块: from fle_utils.config.models import Settings [as 别名]
# 或者: from fle_utils.config.models.Settings import set [as 别名]
def register_device(self):
z = Zone.objects.create(name='test_zone')
DeviceZone.objects.create(zone=z, device=Device.get_own_device())
Settings.set("registered", True)
示例13: handle
# 需要导入模块: from fle_utils.config.models import Settings [as 别名]
# 或者: from fle_utils.config.models.Settings import set [as 别名]
def handle(self, *args, **options):
if not options["interactive"]:
options["hostname"] = options["hostname"] or get_host_name()
# blank allows ansible scripts to dump errors cleanly.
logger.info(
" \n"
" _ __ ___ _ _ _ \n"
" | | / / / _ \ | | (_) | \n"
" | |/ / / /_\ \ | | _| |_ ___ \n"
" | \ | _ | | | | | __/ _ \ \n"
" | |\ \| | | | | |___| | || __/ \n"
" \_| \_/\_| |_/ \_____/_|\__\___| \n"
" \n"
"https://learningequality.org/ka-lite/\n"
" \n"
" version {version:s}\n"
" ".format(
version=VERSION
)
)
if sys.version_info < (2, 7):
raise CommandError(
"Support for Python version 2.6 and below had been discontinued, please upgrade.")
elif sys.version_info >= (2, 8):
raise CommandError(
"Your Python version is: %d.%d.%d -- which is not supported. Please use the Python 2.7 series or wait for Learning Equality to release Kolibri.\n" % sys.version_info[:3])
elif sys.version_info < (2, 7, 6):
logger.warning(
"It's recommended that you install Python version 2.7.6. Your version is: %d.%d.%d\n" % sys.version_info[:3])
if options["interactive"]:
logger.info(
"--------------------------------------------------------------------------------\n"
"This script will configure the database and prepare it for use.\n"
"--------------------------------------------------------------------------------\n"
)
raw_input("Press [enter] to continue...")
# Assuming uid '0' is always root
if not is_windows() and hasattr(os, "getuid") and os.getuid() == 0:
logger.info(
"-------------------------------------------------------------------\n"
"WARNING: You are installing KA-Lite as root user!\n"
" Installing as root may cause some permission problems while running\n"
" as a normal user in the future.\n"
"-------------------------------------------------------------------\n"
)
if options["interactive"]:
if not raw_input_yn("Do you wish to continue and install it as root?"):
raise CommandError("Aborting script.\n")
database_kind = settings.DATABASES["default"]["ENGINE"]
if "sqlite" in database_kind:
database_file = settings.DATABASES["default"]["NAME"]
else:
database_file = None
database_exists = database_file and os.path.isfile(database_file)
# An empty file is created automatically even when the database dosn't
# exist. But if it's empty, it's safe to overwrite.
database_exists = database_exists and os.path.getsize(
database_file) > 0
install_clean = not database_exists
if database_file:
if not database_exists:
install_clean = True
else:
# We found an existing database file. By default,
# we will upgrade it; users really need to work hard
# to delete the file (but it's possible, which is nice).
logger.info(
"-------------------------------------------------------------------\n"
"WARNING: Database file already exists!\n"
"-------------------------------------------------------------------"
)
if not options["interactive"] \
or raw_input_yn("Keep database file and upgrade to KA Lite version %s? " % VERSION) \
or not raw_input_yn("Remove database file '%s' now? " % database_file) \
or not raw_input_yn("WARNING: all data will be lost! Are you sure? "):
install_clean = False
logger.info("Upgrading database to KA Lite version %s" % VERSION)
else:
install_clean = True
logger.info("OK. We will run a clean install; ")
# After all, don't delete--just move.
logger.info(
"the database file will be moved to a deletable "
"location."
)
if not install_clean and not database_file:
# Make sure that, for non-sqlite installs, the database exists.
raise Exception(
"For databases not using SQLite, you must set up your database before running setup.")
#.........这里部分代码省略.........
示例14: set_default_language
# 需要导入模块: from fle_utils.config.models import Settings [as 别名]
# 或者: from fle_utils.config.models.Settings import set [as 别名]
def set_default_language(lang_code):
"""Sets the default language"""
Settings.set("default_language", lcode_to_ietf(lang_code))
示例15: reset_keys
# 需要导入模块: from fle_utils.config.models import Settings [as 别名]
# 或者: from fle_utils.config.models.Settings import set [as 别名]
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())