コード例 #1
0
ファイル: doctype.py プロジェクト: umairsy/wnframework
	def _update_field_properties(self, doclist):
		"""
			Updates properties like description, depends on from the database based on the timestamp
			of the .txt file. Adds a column _last_updated if not exists in the database and uses
			it to update the file..
			
			This feature is built because description is changed / updated quite often and is tedious to
			write a patch every time. Can be extended to cover more updates
		"""
		
		update_fields = ('description', 'depends_on')

		from webnotes.modules import get_file_timestamp, get_item_file

		doc = doclist[0] # main doc
		file_name = get_item_file(doc.module, 'DocType', doc.name)
		time_stamp = get_file_timestamp(file_name)
		last_update = self._get_last_update(doc.name)
		
		# this is confusing because we are updating the fields of fields
		
		if last_update != time_stamp:

			# there are updates!
			fields = self._get_fields(file_name)
			if fields:
				for d in doclist:
				
					# for each field in teh outgoing doclist
					if d.doctype=='DocField':
						key = d.fieldname or d.label
					
						# if it has a fieldname or label
						if key and key in fields:
						
							# update the values
							for field_to_update in update_fields:
								if field_to_update in fields[key] and fields[key][field_to_update] != d.fields[field_to_update]:
									new_value = fields[key][field_to_update]
							
									# in doclist
									d.fields[field_to_update] = new_value
						
									# in database
									webnotes.conn.sql("update tabDocField set `%s` = %s where parent=%s and `%s`=%s" % \
										(field_to_update, '%s', '%s', (d.fieldname and 'fieldname' or 'label'), '%s'), \
										(new_value, doc.name, key))
					
				webnotes.conn.sql("update tabDocType set _last_update=%s where name=%s", (time_stamp, doc.name))
コード例 #2
0
ファイル: compress.py プロジェクト: cmrajan/wnframework
def get_js_code(fn, extn='js'):
	import webnotes
	from webnotes.modules import scrub, get_file_timestamp

	src_file_name = fn + '.' + extn
	comp_file_name = fn + '.comp.' + extn

	src_timestamp = get_file_timestamp(src_file_name)
	
	# if no source, return
	if not src_timestamp:
		return ''
		
	# if timestamps are not same, compress
	if src_timestamp != get_file_timestamp(comp_file_name):
		compress(src_file_name, comp_file_name)
		
	# get the code
	file = open(comp_file_name, 'r')
	code = file.read()
	file.close()
	
	# return
	return code
コード例 #3
0
ファイル: jstimestamp.py プロジェクト: umairsy/wnframework
	def get_timestamp_dict(jsdir,filelist):
		tsdict={}
		import os
		import webnotes.modules as webmod
		oldcwd = os.getcwd()
		os.chdir(jsdir)
		for filename in generateTimestamp.list_js_files('.'):
			ts = webmod.get_file_timestamp(filename)
			filename = filename.lstrip('./')
			filename = filename.rstrip('.js')
			filename = filename.replace('/','.')
			if generateTimestamp.is_package(filename):
				# Whoa its a package
				# Remove _packagename from the end if file is a package
				filename = generateTimestamp.convert_to_packagename(filename)
			tsdict[filename] = ts
		os.chdir(oldcwd)
		return tsdict