Beispiel #1
0
	def theme_date(self, form_id, element):
		import time
		attribs = element.attr('attributes', {})
		
		months, days = date.get_date_arrays()
		
		value = element.attr('value', None)
		
		if(value is None):
			year = datetime.datetime.now().year
			month, day = (months[0], 1)
		else:
			if(isinstance(value, (int, float))):
				value = datetime.datetime.utcfromtimestamp(value)
			
			month, day, year = date.strftime(value, '%B:%d:%Y').split(':')
		
		arrays = (months, days)
		values = (month, int(day))
		names = ('month', 'day')
		
		monthday = self._generate_datetime_select(element, attribs, arrays, values, names)
		
		yearfield = '%s[year]' % element.get_element_name()
		return str(monthday) + str(tags.input(type='text', size=5, value=year, name=yearfield))
Beispiel #2
0
	def theme_datetime(self, form_id, element):
		import time
		attribs = element.attr('attributes', {})
		
		months, days = date.get_date_arrays()
		hours, minutes = date.get_time_arrays()
		
		#value = date.convert_to_timestamp(element.attr('value', None))
		value = element.attr('value', None)
		
		if(value is None):
			year = datetime.datetime.now().year
			month, day, hour, minute = (months[0], 1, '00', '00')
		else:
			month, day, year, hour, minute = date.strftime(value, '%B:%d:%Y:%H:%M').split(':')
		
		arrays = (months, days, hours, minutes)
		values = (month, int(day), hour, minute)
		names = ('month', 'day', 'hour', 'minute')
		
		dateselect = self._generate_datetime_select(element, attribs, arrays[:2], values[:2], names[:2])
		year_attribs = dict(
		 	name = '%s[year]' % element.get_element_name(),
		 	size = 5,
			value = year,
		)
		yearfield = tags.input(type='text', **year_attribs)
		timeselect = self._generate_datetime_select(element, attribs, arrays[2:], values[2:], names[2:])
		
		return ''.join([str(x) for x in (dateselect, yearfield, timeselect)])
Beispiel #3
0
	def get_element(self, req, style, storable):
		"""
		@see: L{modu.editable.define.definition.get_element()}
		"""
		value = getattr(storable, self.get_column_name(), None)
		if(value):
			output = date.strftime(value, self.get('format_string', '%B %d, %Y at %I:%M%p'))
		else:
			output = ''
		
		if(style == 'search'):
			frm = form.FormNode(self.name)
			return frm
		elif(style == 'listing'):
			frm = form.FormNode(self.name)
			if(self.get('date_in_listing', True)):
				if(output == ''):
					output = '(none)'
				frm(type='label', value=output)
			else:
				frm(type='checkbox', disabled=True, checked=bool(output))
			return frm
		elif(style == 'detail' and self.get('read_only', False)):
			if(output == ''):
				output = '(none)'
			frm = form.FormNode(self.name)
			frm(type='label', value=output)
			return frm
		
		checked = False
		if(storable.get_id() == 0 and self.get('default_checked', False)):
			checked = True
		
		frm = form.FormNode(self.name)(
			type	= 'checkbox',
			# this is only True if default_checked is true and it's a new item
			checked	= checked,
			suffix	= '  ' + tags.small()[output],
		)
		
		if(bool(output)):
			if(self.get('one_time', True)):
				frm(attributes=dict(disabled='disabled'))
		else:
			frm(
				text	= '  ' + tags.small(_class='minor-help')['check to set current date']
			)
		
		return frm
Beispiel #4
0
	"""

class LT(RAW):
	"""
	Allow for use of a less-than.
	
	When sql.LT(value) is included in the constraint array passed
	to a query building function, it will generate the SQL fragment
	'column < value'
	
	@ivar value: The value to be less-than
	"""

string_literal = quoted_string_literal

conversions = {
    int: lambda s,d: str(s),
    long: lambda s,d: str(s),
    float: lambda o,d: '%.15g' % o,
    types.NoneType: lambda s,d: 'NULL',
	list: lambda s,d: '(%s)' % ','.join([escape_item(x, conversions) for x in s]),
	tuple: lambda s,d: '(%s)' % ','.join([escape_item(x, conversions) for x in s]),
    str: lambda o,d: string_literal(o, d), # default
    unicode: lambda s,d: string_literal(s.encode(), d),
    bool: lambda s,d: str(int(s)),
    datetime.date: lambda d,c: string_literal(date.strftime(d, "%Y-%m-%d"), c),
    datetime.datetime: lambda d,c: string_literal(date.strftime(d, "%Y-%m-%d %H:%M:%S"), c),
    datetime.timedelta: lambda v,c: string_literal('%d %d:%d:%d' % (v.days, int(v.seconds / 3600) % 24, int(v.seconds / 60) % 60, int(v.seconds) % 60)),
	RAW: lambda o,d: o.value,
	decimal.Decimal: lambda s,d: str(s),
}
Beispiel #5
0
	def get_element(self, req, style, storable):
		"""
		@see: L{modu.editable.define.definition.get_element()}
		"""
		value = getattr(storable, self.get_column_name(), None)
		if(isinstance(value, (int, long, float))):
			value = datetime.datetime.utcfromtimestamp(value)
		
		if(style == 'search'):
			frm = form.FormNode(self.name)
			frm['from'] = self.get_form_element(req, '_detail', storable)(
				prefix='<div>from date:',
				suffix=tags.br() + '</div>',
			)
			frm['to'] = self.get_form_element(req, '_detail', storable)(
				prefix='<div>to date:',
				suffix='</div>',
			)
			return frm
		elif(style == 'listing' or (style == 'detail' and self.get('read_only', False))):
			if(value):
				output = date.strftime(value, self.get('format_string', '%B %d, %Y at %I:%M%p'))
			else:
				output = ''
			frm = form.FormNode(self.name)
			frm(type='label', value=output)
			return frm
		
		current_year = datetime.datetime.now().year
		if(value is not None):
			current_year = getattr(value, 'year', current_year)
		
		start_year = self.get('start_year', current_year - 2)
		end_year = self.get('end_year', current_year + 5)
		
		months, days = date.get_date_arrays()
		
		frm = form.FormNode(self.name)
		frm(type='fieldset', style='brief')
		
		frm['null'](type='checkbox', text="no value", weight=-1, suffix=tags.br(), 
			attributes=dict(onChange='enableDateField(this);'))
		
		assets.activate_jquery(req)
		req.content.report('header', tags.script(type='text/javascript')["""
			function enableDateField(checkboxField){
				var formItem = $(checkboxField).parent().parent();
				if($(checkboxField).attr('checked')){
					formItem.children(':enabled').attr('disabled', true);
				}
				else{
					formItem.children(':disabled').attr('disabled', false);
				}
			}
		"""])
		
		attribs = {}
		
		if(value is None):
			frm['null'](checked=True)
			#attribs['disabled'] = None
			
			if(self.get('default_now', False)):
				value = datetime.datetime.now()
				frm['null'](checked=False)
		
		frm['date'](
			type		= self.get('style', 'datetime'),
			value		= value,
			attributes	= attribs,
			suffix		= tags.script(type="text/javascript")["""
				enableDateField($('#form-item-%s input'));
			""" % self.name],
		)
		
		frm.validate = self.validate

		return frm