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_item_file from webnotes.utils import get_file_timestamp 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))
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_item_file from webnotes.utils import get_file_timestamp 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))
def get_timestamp_dict(jsdir,filelist): tsdict={} import os from webnotes.utils import get_file_timestamp oldcwd = os.getcwd() os.chdir(jsdir) for filename in generateTimestamp.list_js_files('.'): ts = 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
def get_timestamp_dict(jsdir, filelist): tsdict = {} import os from webnotes.utils import get_file_timestamp oldcwd = os.getcwd() os.chdir(jsdir) for filename in generateTimestamp.list_js_files('.'): ts = 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
def get_item_timestamp(module, dt, dn): """ Return ths timestamp of the given item (if exists) """ from webnotes.utils import get_file_timestamp return get_file_timestamp(get_item_file(module, dt, dn))