Esempio n. 1
0
	def get_search_value(self, value, req, frm):
		form_data = frm[self.name]
		
		to_value = 0
		from_value = 0
		
		if not(value['to'].get('null')):
			start_year = form_data['to']['date'].start_year
			end_year = form_data['to']['date'].end_year
			date_data = value['to'].get('date', None)
			if(date_data):
				to_value = date.get_dateselect_value(date_data, self.get('style', 'datetime'), start_year, end_year)
				to_value = time.mktime(to_value.timetuple())
		
		if not(value['from'].get('null')):
			start_year = form_data['from']['date'].start_year
			end_year = form_data['from']['date'].end_year
			date_data = value['from'].get('date', None)
			if(date_data):
				from_value = date.get_dateselect_value(date_data, self.get('style', 'datetime'), start_year, end_year)
				from_value = time.mktime(from_value.timetuple())
		
		if(to_value and from_value):
			if(self.get('save_format', 'timestamp') == 'datetime'):
				return sql.RAW('UNIX_TIMESTAMP(%%s) BETWEEN %s AND %s' % (from_value, to_value))
			else:
				return sql.RAW('%%s BETWEEN %s AND %s' % (from_value, to_value))
		elif(to_value):
			return sql.LT(to_value)
		elif(from_value):
			return sql.GT(from_value)
		else:
			return None
Esempio n. 2
0
	def update_storable(self, req, form, storable):
		"""
		@see: L{modu.editable.define.definition.update_storable()}
		"""
		save_format = self.get('save_format', 'timestamp')
		
		if(self.get('read_only')):
			if(self.get('default_now', False) and not storable.get_id()):
				if(save_format == 'timestamp'):
					setattr(storable, self.get_column_name(), int(time.time()))
				else:
					setattr(storable, self.get_column_name(), datetime.datetime.now())
			return True
		
		data = form[self.name]['date']
		
		if(data.attr('null', 0)):
			setattr(storable, self.get_column_name(), None)
			return True
		
		date_data = req.data[form.name][self.name].get('date', None)
		# if it's not a dict, it must be None, or broken
		if(isinstance(date_data, dict)):
			value = date.get_dateselect_value(date_data, self.get('style', 'datetime'))
		else:
			value = None
		
		if(save_format == 'timestamp'):
			setattr(storable, self.get_column_name(), date.convert_to_timestamp(value))
		else:
			setattr(storable, self.get_column_name(), value)
		
		return True