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


Python Setting.save方法代码示例

本文整理汇总了Python中models.Setting.save方法的典型用法代码示例。如果您正苦于以下问题:Python Setting.save方法的具体用法?Python Setting.save怎么用?Python Setting.save使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在models.Setting的用法示例。


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

示例1: __setattr__

# 需要导入模块: from models import Setting [as 别名]
# 或者: from models.Setting import save [as 别名]
 def __setattr__(self, name, value):
     if name in ('_vals', '_name', '_appname', '_verbose_name', '_readonly', '_cache_prefix', '_main'):
         return object.__setattr__(self, name, value)
     if self._readonly:
         raise AttributeError, 'settings group %s is read-only' % self._name
     if not name in self._vals:
         raise AttributeError, 'setting "%s" not found'%name
     if not has_db:
         raise SettingsException, "no database -- settings are immutable"
     self._vals[name].initial = self._vals[name].clean(value)
     try:
         setting = Setting.objects.get(app = self._appname,
                 site = Site.objects.get_current(),
                 class_name = self._name,
                 key = name)
     except Setting.DoesNotExist:
         setting = Setting(site = Site.objects.get_current(),
                 app = self._appname,
                 class_name = self._name,
                 key = name)
     serialized = value
     if hasattr(self._vals[name].widget, '_format_value'):
         serialized = self._vals[name].widget._format_value(value)
     serialized = force_unicode(serialized)
     setting.value = serialized
     setting.save()
     if appsettings.USE_CACHE:
         cache.set(self._cache_prefix+name, value)
     if self._main:
         setattr(django_settings, name, value)
开发者ID:smacker,项目名称:django-appsettings,代码行数:32,代码来源:settingsobj.py

示例2: update_database

# 需要导入模块: from models import Setting [as 别名]
# 或者: from models.Setting import save [as 别名]
def update_database():
	last_data = {'readings':{'temp':0,'humidity':0}, 'parameters':None}
	while 1:
		update_time = timezone.now()
		data = (yield)
		if (round(last_data["readings"]["temp"]) != round(data["readings"]["temp"])) or (round(last_data["readings"]["humidity"]) != round(data["readings"]["humidity"])):
			try:
				reading_record = Reading.objects.get(pk=1)
			except Reading.DoesNotExist:
				reading_record = Reading(time=update_time, temperature=data["readings"]["temp"], humidity=data["readings"]["humidity"])
			else:
				reading_record.time = update_time
				reading_record.temperature = data["readings"]["temp"]
				reading_record.humidity = data["readings"]["humidity"]
			reading_record.save()
		if last_data["parameters"] != data["parameters"]:
			setting_record = Setting(time=update_time, mode=data["parameters"]["mode"], temperature=data["parameters"]["temp"], humidity=data["parameters"]["humidity"])
			setting_record.save()
		last_data = data
开发者ID:daniel2078,项目名称:Climaduino-web-controller,代码行数:21,代码来源:climaduino_controller_mock.py

示例3: update_database

# 需要导入模块: from models import Setting [as 别名]
# 或者: from models.Setting import save [as 别名]
def update_database():
	last_data = {'readings':{'temp':0,'humidity':0}, 'parameters':None}
	while 1:
		update_time = timezone.now()
		data = (yield)
		# Round current temperature and humidity readings
		temperature_rounded = round(data["readings"]["temp"])
		humidity_rounded = round(data["readings"]["humidity"])

		# Compare rounded current readings against the rounded previous readings
		if (round(last_data["readings"]["temp"]) != temperature_rounded) or (round(last_data["readings"]["humidity"]) != humidity_rounded):
			try:
				reading_record = Reading.objects.get(pk=1)
			except Reading.DoesNotExist:
				reading_record = Reading(time=update_time, temperature=temperature_rounded, humidity=humidity_rounded)
			else:
				reading_record.time = update_time
				reading_record.temperature = temperature_rounded
				reading_record.humidity = humidity_rounded
			reading_record.save()
		if last_data["parameters"] != data["parameters"]:
			setting_record = Setting(time=update_time, source=0, mode=data["parameters"]["mode"], temperature=data["parameters"]["temp"], humidity=data["parameters"]["humidity"])
			setting_record.save()
		last_data = data
开发者ID:daniel2078,项目名称:Climaduino-web-controller,代码行数:26,代码来源:climaduino_controller.py

示例4: main

# 需要导入模块: from models import Setting [as 别名]
# 或者: from models.Setting import save [as 别名]
def main(queue, interval_in_seconds=300):
	'''Queue is used to communicate with the climaduino_controller. Interval is
	   how often to check the database for program settings.'''
   # BUG: Does not work when interval wraps around between days. If interval is 5 minutes
   # then times between 23:55 and 00:00 (midnight) do not work properly

   # set process niceness value to lower its priority
	os.nice(1)
	print("Climaduino Programming Sentry Active")
	while 1:
	   	now = datetime.datetime.now()
	   	current_settings = Setting.objects.last()
	   	# find out the day 0 is Monday
	   	current_day = now.weekday()

	   	# find out the time
	   	current_time = now.time()

	   	# calculate the time minus interval_in_seconds
	   	earliest_time = now - datetime.timedelta(seconds=interval_in_seconds)
	   	earliest_time = earliest_time.time()

	   	# query DB with interval_in_seconds "fudge factor"
	   	program_query = Program.objects.filter(mode=current_settings.mode, day=current_day, time__range=(earliest_time, current_time))

	   	# if program exists, find out what should be changed and then change it
	   	for program in program_query:
	   		setting_record = Setting(time=now, source=3, mode=program.mode, temperature=program.temperature, humidity=program.humidity)
	   		setting_record.save()
	   		if program.temperature != current_settings.temperature:
	   			queue.put("%sF" % program.temperature)
	   		if program.humidity != current_settings.humidity:
	   			queue.put("%s%%" % program.humidity)

	   	# sleep for interval_in_seconds so we only check once during that interval
	   	time.sleep(interval_in_seconds)
开发者ID:daniel2078,项目名称:Climaduino-web-controller,代码行数:38,代码来源:climaduino_programming_sentry.py

示例5: update

# 需要导入模块: from models import Setting [as 别名]
# 或者: from models.Setting import save [as 别名]
    def update(self, value):    
        current_value = self.value

        new_value = self.to_python(value)
        if current_value != new_value:        
            db_value = self.get_db_prep_save(value)
            try:
                s = self.setting
                s.value = db_value
                
            except SettingNotSet:
                log.debug('new setting %s.%s', self.group.key, self.key)
                s = Setting(group=self.group.key, key=self.key, value=db_value)

            if self.use_default and self.default == new_value:
                if s.id:
                    log.info("Deleted setting %s.%s", self.group.key, self.key)
                    s.delete()
            else:
                log.info("Updated setting %s.%s = %s", self.group.key, self.key, value)
                s.save()
            
            return True
        return False
开发者ID:davemerwin,项目名称:satchmo,代码行数:26,代码来源:values.py

示例6: load_default_settings

# 需要导入模块: from models import Setting [as 别名]
# 或者: from models.Setting import save [as 别名]
def load_default_settings():
    for key, value in {"SRV_NUM": "73120896", "GSM_NET": "orange"}.items():
        if Setting.filter(slug=key).count() == 0:
            s = Setting(slug=key, value=value)
            s.save()
开发者ID:yeleman,项目名称:nut,代码行数:7,代码来源:database.py


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