def update_limits(limits_dict): '''Add/Update limit in site_config''' limits = get_limits() limits.update(limits_dict) update_site_config("limits", limits, validate=False) disable_users(limits) dataent.local.conf.limits = limits
def scheduler(context, state, site=None): from dataent.installer import update_site_config import dataent.utils.scheduler if not site: site = get_site(context) try: dataent.init(site=site) if state == 'pause': update_site_config('pause_scheduler', 1) elif state == 'resume': update_site_config('pause_scheduler', 0) elif state == 'disable': dataent.connect() dataent.utils.scheduler.disable_scheduler() dataent.db.commit() elif state == 'enable': dataent.connect() dataent.utils.scheduler.enable_scheduler() dataent.db.commit() print('Scheduler {0}d for site {1}'.format(state, site)) finally: dataent.destroy()
def get_encryption_key(): from dataent.installer import update_site_config if 'encryption_key' not in dataent.local.conf: encryption_key = Fernet.generate_key().decode() update_site_config('encryption_key', encryption_key) dataent.local.conf.encryption_key = encryption_key return dataent.local.conf.encryption_key
def clear_limit(key): '''Remove a limit option from site_config''' limits = get_limits() to_clear = [key] if isinstance(key, string_types) else key for key in to_clear: if key in limits: del limits[key] update_site_config("limits", limits, validate=False) dataent.conf.limits = limits
def set_maintenance_mode(context, state, site=None): from dataent.installer import update_site_config if not site: site = get_site(context) try: dataent.init(site=site) update_site_config('maintenance_mode', 1 if (state == 'on') else 0) finally: dataent.destroy()
def reset_enabled_scheduler_events(login_manager): if login_manager.info.user_type == "System User": try: if dataent.db.get_global('enabled_scheduler_events'): # clear restricted events, someone logged in! dataent.db.set_global('enabled_scheduler_events', None) except pymysql.InternalError as e: if e.args[0] == ER.LOCK_WAIT_TIMEOUT: dataent.log_error(dataent.get_traceback(), "Error in reset_enabled_scheduler_events") else: raise else: is_dormant = dataent.conf.get('dormant') if is_dormant: update_site_config('dormant', 'None')
def clear_limits(context, site, limits): """Clears given limit from the site config, and removes limit from site config if its empty""" from dataent.limits import clear_limit as _clear_limit if not limits: return if not site: site = get_site(context) with dataent.init_site(site): _clear_limit(limits) # Remove limits from the site_config, if it's empty limits = get_limits() if not limits: update_site_config('limits', 'None', validate=False)
def set_config(context, key, value, global_=False, as_dict=False): "Insert/Update a value in site_config.json" from dataent.installer import update_site_config import ast if as_dict: value = ast.literal_eval(value) if global_: sites_path = os.getcwd() # big assumption. common_site_config_path = os.path.join(sites_path, 'common_site_config.json') update_site_config(key, value, validate=False, site_config_path=common_site_config_path) else: for site in context.sites: dataent.init(site=site) update_site_config(key, value, validate=False) dataent.destroy()
def restrict_scheduler_events_if_dormant(): if is_dormant(): restrict_scheduler_events() update_site_config('dormant', True)