コード例 #1
0
ファイル: theme.py プロジェクト: philchristensen/modu
	def page_guide(self, pages, url):
		if(url.find('?') == -1):
			url += '?'
		else:
			from cgi import parse_qs
			from urllib import urlencode
			stub, query = url.split('?')
			query = parse_qs(query)
			if('page' in query):
				del query['page']
			url = '%s?%s&' % (stub, urlencode(query, True))
		
		if(pages.has_previous()):
			prev = tags.span()[tags.a(href="%spage=%d" % (url, pages.page - 1))['<< Previous']]
		else:
			prev = tags.span()['<< Previous']
		
		if(pages.has_next()):
			next = tags.span()[tags.a(href="%spage=%d" % (url, pages.page + 1))['Next >>']]
		else:
			next = tags.span()['Next >>']
		
		return tags.div(_class='page-guide')[[
			tags.div()['Items %d – %d of %s shown.' %
				(pages.start_range, pages.end_range, pages.total_results)],
			tags.div()[prev, ' | ', next]
		]]
コード例 #2
0
ファイル: media.py プロジェクト: philchristensen/gigkeeper
	def default_formatter(self, req, results, storable):
		"""
		The default way to format the output of this field.
		"""
		query = {'__init__[item_id]':storable.get_id(),
				 '__init__[item_table]':storable.get_table(),
				}
		new_media_link = tags.a(href=req.get_path(req.prepath, 'detail/media/new?' + urllib.urlencode(query)))['Add Media']
		
		if(len(results) == 0):
			return tags.span()[new_media_link]
		
		def format_type(item):
			filesize = media.formatbytes(item.get('filesize', 0))
			return '%s %s %s (%s)' % (filesize, item['format'], item['type'], item['quality'])
		
		def format_status(item):
			full_path = os.path.join(req.app.upload_path, item['filename'])
			status = []
			try:
				finfo = os.stat(full_path)
				if(finfo.st_size != item['filesize']):
					status.append("wrong filesize")
				
				if(req.postpath[-1] == 'check-md5'):
					filehash = media.get_checksum(full_path, md5_path=req.app.md5_path)
				
					if(filehash != item['md5']):
						status.append("incorrect hash")
			except OSError, e:
				status.append(e.strerror)
			
			if(status):
				return tags.span(_class='error')[str(tags.br()).join(status)]
			else:
				return tags.span(_class='message')['OK']
コード例 #3
0
ファイル: theme.py プロジェクト: philchristensen/modu
	def theme_element(self, form_id, element, rendered_element):
		content = ''
		
		if not(element.attr('basic_element', False)):
			if(element.attr('required', False)):
				asterisk = tags.span(_class="required")['*']
			else:
				asterisk = ''
			
			if(hasattr(element, 'label')):
				content += tags.label(_class="field-label")[[element.label, asterisk]]
			
		prefix = element.attr('prefix', False)
		if(callable(prefix)):
			content += prefix(element)
		elif(prefix):
			content += str(prefix)
		
		content += rendered_element
			
		suffix = element.attr('suffix', False)
		if(callable(suffix)):
			content += suffix(element)
		elif(suffix):
			content += str(suffix)
		
		if not(element.attr('basic_element', False)):
			if(hasattr(element, 'help')):
				content += tags.div(_class='form-help')[element.help]
			
			if(element.has_errors(recurse=False)):
				element_class = 'form-item form-error'
			else:
				element_class = 'form-item'
			
			item_id = 'form-item-%s' % element.name
			if(element.attr('deep_form_ids', False, recurse=True)):
				item_id = 'form-item-%s' % '-'.join(element.get_element_path())
			content = tags.div(_class=element_class, _id=item_id)[content]
		
		return content
コード例 #4
0
ファイル: theme.py プロジェクト: philchristensen/modu
	def theme_label(self, form_id, element):
		attribs = element.attr('attributes', {'class':'label'})
		value = element.attr('value', element.attr('default_value', ''))
		if(value is None):
			value = ''
		return tags.span(**attribs)[value]