Esempio n. 1
0
	def preProcess(self,oldval):
		miscData = None
		if type(oldval) in (list,tuple):
			miscData = oldval[1]
			newval = oldval = oldval[0]
		else:
			newval = oldval
		#assert(type(newval) == str)

		if self.flagSum:
			try: self.sum += oldval
			except: pass

		if self.htype == self.BYTES:
			newval = BytesToText(newval)
		elif self.htype == self.DATE:
			try: newval = newval.strftime('%Y-%m-%d')
			except: newval = 'Never'
		elif self.htype == self.DATETIME:
			try: newval = newval.strftime('%Y-%m-%d %H:%M:%S')
			except: newval = 'Never'
		elif self.htype == self.FLOAT:
			try: newval = '%3.2f' % newval
			except: newval = 'NaN'
		elif self.htype == self.HTML: return (newval,oldval)
		elif self.htype == self.NUMBER:
			try: newval = '%d' % newval
			except: newval = 'NaN'
		elif self.htype == self.TEXT:
			if newval == None: newval = ''
		elif self.htype == self.TIME:
			if isinstance(newval,datetime.timedelta):
				days = newval.days
				newval += datetime.datetime(1900,1,1)
				newval = '%03d:%s' % (days,newval.strftime('%H:%M:%S'))
			else:
				try: newval = newval.strftime('%H:%M:%S')
				except: newval = 'Never'

		if type(newval) == str:
			newval = unicode(newval,'latin1')
		elif type(newval) != unicode:
			newval = str(newval)
		newval = newval.encode('utf8')
		newval = escape(newval)
		if self.postProcess:
			if miscData:
				newval = self.postProcess(newval,miscData)
			else:
				newval = self.postProcess(newval)
		
		if self.spanContent:
			newval = '<span>%s</span>' % newval

		return (newval,oldval)
Esempio n. 2
0
	def __init__(self, req,createContent=True,parent=None):
		self._alerts = []
		self._splitAlerts = 1
		self._extraSheets = []
		self._exportTable = None

		# used in psp
		self.injectedContent = ''
		self.content = None
		self.overrideContent = None
		self.inputHidden = True
		self.inputBox = None

		InputController.__init__(self,req,parent=parent)

		if isinstance(parent,BaseController):
			# safe time and increase consistency
			self.now = self.parent.now
			self.weekago = self.parent.weekago
			self.yesterday = self.parent.yesterday
			self.today = self.parent.today
			self.testAlerts = self.parent.testAlerts
			self.debugAlerts = self.parent.debugAlerts
		else:
			self.now = datetime.datetime.now()
			self.today = datetime.datetime( *self.now.timetuple()[0:3] )
			self.weekago = self.today-datetime.timedelta(days=7)
			self.yesterday = self.today-datetime.timedelta(days=1)
			self.today = self.today
			self.testAlerts = StringToBool(self.getField('testAlerts'))
			self.debugAlerts = StringToBool(self.getField('debugAlerts'))
			BytesToText.setFixed(StringToBool(self.getField('fixedUnit'),default=None,empty=None,none=None))
			BytesToText.setShowUnit(StringToBool(self.getField('showUnit',True),default=True,none=None))
			BytesToText.setBase(self.getField('baseUnit'))
			BytesToText.setPrecision(self.getField('precisionUnit'))
			try: self.testAlerts = int(self.testAlerts)
			except: pass
			homePrefix = self.getHomePrefix()
			baselayout = self.getBaseLayout()
			self.addStyleSheet(homePrefix+'css/outer-baselayout.css','outer','baselayout','screen',active=baselayout=='outer')
			self.addStyleSheet(homePrefix+'css/inner-baselayout.css','inner','baselayout','screen',active=baselayout=='inner')
			self.addStyleSheet(homePrefix+'css/print-baselayout.css','print','baselayout','print')

			self.addStyleSheet(homePrefix+'css/core.css','std','core')

			theme = self.getColorTheme()
			for name,file in _themes:
				self.addStyleSheet(homePrefix+file,name,'color-theme',active=theme==name)

			shadows = self.getShadows()
			if shadows:
				self.addStyleSheet(homePrefix+'css/half-shadows.css','half','shadows',active=shadows=='half')
				self.addStyleSheet(homePrefix+'css/full-shadows.css','full','shadows',active=shadows=='full')
				StandardController._noshadowdops = False
			else:
				StandardController._noshadowdops = True

		if not createContent: return

		self.preCreate()
		self.createContent()
		self.postCreate()
Esempio n. 3
0
	def createContent(self):
		self.byteConf = PopUpMenuController(self.req,'&nbsp;',pop=PU.UP_LEFT)

		def param(var,val):
			from urllib import urlencode
			fields = self.getAllFields()
			fields[var] = val
			return '?%s' % self.escape(urlencode(fields))

		fixed = BytesToText.getFixed()

		fixedUnit = PopUpMenuController(self.req,'Fixed Units',pop=PU.LEFT_UP)
		fixedUnit.addItems(PopUpMenuController(self.req,'Tera',href=param('fixedUnit','T'),toggle=fixed=='T'))
		fixedUnit.addItems(PopUpMenuController(self.req,'Giga',href=param('fixedUnit','G'),toggle=fixed=='G'))
		fixedUnit.addItems(PopUpMenuController(self.req,'Mega',href=param('fixedUnit','M'),toggle=fixed=='M'))
		fixedUnit.addItems(PopUpMenuController(self.req,'Kilo',href=param('fixedUnit','K'),toggle=fixed=='K'))
		fixedUnit.addItems(PopUpMenuController(self.req,'Bytes',href=param('fixedUnit',''),toggle=fixed==True or fixed==''))
		fixedUnit.addItems(PopUpMenuController(self.req,'Off',href=param('fixedUnit','0'),toggle=fixed in (False,None)))

		digits = BytesToText.getPrecision()

		precision = PopUpMenuController(self.req,'Precision',pop=PU.LEFT_UP)
		precision.addItems(PopUpMenuController(self.req,'Default',toggle=digits==None))
		precision.addItems(PopUpMenuController(self.req,'4 Digits',href=param('precisionUnit',4),toggle=digits==4))
		precision.addItems(PopUpMenuController(self.req,'3 Digits',href=param('precisionUnit',3),toggle=digits==3))
		precision.addItems(PopUpMenuController(self.req,'2 Digits',href=param('precisionUnit',2),toggle=digits==2))
		precision.addItems(PopUpMenuController(self.req,'1 Digits',href=param('precisionUnit',1),toggle=digits==1))
		precision.addItems(PopUpMenuController(self.req,'No Digits',href=param('precisionUnit',0),toggle=digits==0))

		base = BytesToText.getBase()

		baseUnit = PopUpMenuController(self.req,'Base System',pop=PU.LEFT_UP)
		baseUnit.addItem(PopUpMenuController(self.req,'1000',href=param('baseUnit',1000),toggle=base==1000))
		baseUnit.addItem(PopUpMenuController(self.req,'1024',href=param('baseUnit',1024),toggle=base==1024))

		show = BytesToText.getShowUnit()

		showUnit = PopUpMenuController(self.req,'Show Unit',pop=PU.LEFT_UP)
		showUnit.addItem(PopUpMenuController(self.req,'On',href=param('showUnit',1),toggle=show==True))
		showUnit.addItem(PopUpMenuController(self.req,'Off',href=param('showUnit',0),toggle=show==False))

		self.byteConf.addItem(baseUnit)
		self.byteConf.addItem(fixedUnit)
		self.byteConf.addItem(precision)
		self.byteConf.addItem(showUnit)

		self.styleConf = PopUpMenuController(self.req,'&nbsp;',pop=PU.UP_LEFT)

		themes = PopUpMenuController(self.req,'Themes',pop=PU.LEFT_UP)
		theme = self.parent.getColorTheme()
		for name,file in _themes:
			themes.addItem(PopUpMenuController(self.req,name.capitalize(),href=param('color-theme-sheet',name),onclick='''toggleList(this);switchStyleSheets('%s','color-theme'); return false;''' % name,toggle=theme==name))

		shadows = PopUpMenuController(self.req,'Shadows',pop=PU.LEFT_UP)
		shadow = self.parent.getShadows()
		shadows.addItem(PopUpMenuController(self.req,'Full',href=param('shadows-sheet','full'),onclick='''toggleList(this);return !switchStyleSheets('full','shadows');''',toggle=shadow=='full'))
		shadows.addItem(PopUpMenuController(self.req,'Half',href=param('shadows-sheet','half'),onclick='''toggleList(this);return !switchStyleSheets('half','shadows'); return false;''',toggle=shadow=='half'))
		shadows.addItem(PopUpMenuController(self.req,'Off',href=param('shadows-sheet','off'), onclick='''toggleList(this);switchStyleSheets( null, 'shadows'); return false;''',toggle=shadow==False))

		layout = PopUpMenuController(self.req,'Base Layout',pop=PU.LEFT_UP)
		baselayout=self.parent.getBaseLayout()
		layout.addItem(PopUpMenuController(self.req,'Inner',href=param('baselayout-sheet','inner'),onclick='''toggleList(this);switchStyleSheets( 'inner', 'baselayout'); return false;''',toggle=baselayout=='inner'))
		layout.addItem(PopUpMenuController(self.req,'Outer',href=param('baselayout-sheet','outer'),onclick='''toggleList(this);switchStyleSheets( 'outer', 'baselayout'); return false;''',toggle=baselayout=='outer'))

		media = PopUpMenuController(self.req,'Media Type',pop=PU.LEFT_UP)
		printLayout = self.parent.getPrintLayout()
		media.addItem(PopUpMenuController(self.req,'Normal',href=param('printLayout',0),onclick='''toggleList(this);displayCSSMediaType(); return false;''',toggle=not printLayout))
		media.addItem(PopUpMenuController(self.req,'Print',href=param('printLayout',1),onclick='''toggleList(this);displayCSSMediaType('print'); return false;''',toggle=printLayout))

		self.styleConf.addItem(layout)
		self.styleConf.addItem(themes)
		self.styleConf.addItem(shadows)
		self.styleConf.addItem(media)