fixes after sync

This commit is contained in:
Anand Doshi 2012-04-06 17:54:10 +05:30
parent 6bd0db8df6
commit 58bb17e02c
4 changed files with 29 additions and 20 deletions

View file

@ -95,6 +95,12 @@ def delete_doc(doctype=None, name=None, doclist = None, force=0):
if hasattr(obj,'on_trash'):
obj.on_trash()
if doctype=='DocType':
webnotes.conn.sql("delete from `tabCustom Field` where dt = %s", name)
webnotes.conn.sql("delete from `tabCustom Script` where dt = %s", name)
webnotes.conn.sql("delete from `tabProperty Setter` where doc_type = %s", name)
webnotes.conn.sql("delete from `tabSearch Criteria` where doc_type = %s", name)
# check if links exist
if not force:
check_if_doc_is_linked(doctype, name)
@ -166,11 +172,11 @@ def rename(dt, old, new, is_doctype = 0):
select_flds = sql("select parent, fieldname from `tabDocField` where parent not like 'old%%' and options like '%%%s%%' and options not like 'link:%%' and fieldtype = 'Select' and parent != '%s'" % (old, new))
update_link_fld_values(select_flds, old, new)
sql("update `tabDocField` set options = replace(options, '%s', '%s') where options like '%%%s%%'" % (old, new, old))
sql("update `tabDocField` set options = replace(options, '%s', '%s') where parent not like 'old%%' and options like '%%%s%%' and options not like 'link:%%' and fieldtype = 'Select' and parent != '%s'" % (old, new, old, new))
# doctype
if is_doctype:
if not is_single_dt(old):
if not is_single_dt(new):
sql("RENAME TABLE `tab%s` TO `tab%s`" % (old, new))
else:
sql("update tabSingles set doctype = %s where doctype = %s", (new, old))
@ -190,7 +196,7 @@ def update_link_fld_values(flds, old, new):
webnotes.conn.sql("update `tab%s` set `%s`='%s' where `%s`='%s'" % (l[0], l[1], new, l[1], old))
def is_single_dt(dt):
is_single = webnotes.conn.sql("select issingle from tabDocType where name = '%s'" % dt)
is_single = webnotes.conn.sql("select issingle from tabDocType where name = %s", dt)
is_single = is_single and webnotes.utils.cint(is_single[0][0]) or 0
return is_single

View file

@ -4,11 +4,12 @@
"""
import webnotes
def sync_all():
sync_core_doctypes()
sync_modules()
def sync_all(force=0):
sync_core_doctypes(force)
sync_modules(force)
webnotes.conn.sql("DELETE FROM __CacheItem")
def sync_core_doctypes():
def sync_core_doctypes(force=0):
import os
import core
module_name = 'core'
@ -17,9 +18,9 @@ def sync_core_doctypes():
for path, folders, files in os.walk(core_path):
for f in files:
if f.endswith(".txt"):
sync(module_name, f[:-4])
sync(module_name, f[:-4], force)
def sync_modules():
def sync_modules(force=0):
import os
import webnotes.defs
for path, folders, files in os.walk(webnotes.defs.modules_path):
@ -32,17 +33,17 @@ def sync_modules():
if (len(path_tuple)==3 and path_tuple[0] in modules_list and
path_tuple[1] == 'doctype'):
#print (path_tuple[0], f[:-4])
sync(path_tuple[0], f[:-4])
sync(path_tuple[0], f[:-4], force)
# docname in small letters with underscores
def sync(module_name, docname):
def sync(module_name, docname, force=0):
with open(get_file_path(module_name, docname), 'r') as f:
from webnotes.model.utils import peval_doclist
doclist = peval_doclist(f.read())
modified = doclist[0]['modified']
if not doclist:
raise Exception('DocList could not be evaluated')
if modified == str(webnotes.conn.get_value('DocType', doclist[0].get('name'), 'modified')):
if modified == str(webnotes.conn.get_value('DocType', doclist[0].get('name'), 'modified')) and not force:
return
webnotes.conn.begin()

View file

@ -30,6 +30,7 @@ dt_map = {
'DocType': {
'DocField': ['fieldname', 'label']
},
'Search Criteria': {},
'Page': {}
}

View file

@ -100,15 +100,15 @@ def notify_assignment(assigned_by, owner, doc_type, doc_name, action='CLOSE', no
if action=='CLOSE':
if owner == webnotes.session.get('user'):
arg = {
'uid': assigned_by,
'comment': "The task %s, that you assigned to %s, has been \
'contact': assigned_by,
'txt': "The task %s, that you assigned to %s, has been \
closed." % (assignment,
user_info.get(owner, {}).get('fullname'))
}
else:
arg = {
'uid': assigned_by,
'comment': "The task %s, that you assigned to %s, \
'contact': assigned_by,
'txt': "The task %s, that you assigned to %s, \
has been closed by %s." % (assignment,
user_info.get(owner, {}).get('fullname'),
user_info.get(webnotes.session.get('user'),
@ -116,11 +116,12 @@ def notify_assignment(assigned_by, owner, doc_type, doc_name, action='CLOSE', no
}
else:
arg = {
'uid': owner,
'comment': "A new task, %s, has been assigned to you by %s." \
'contact': owner,
'txt': "A new task, %s, has been assigned to you by %s." \
% (assignment,
user_info.get(webnotes.session.get('user'), {}).get('fullname')),
'notify': notify
}
from home.page.my_company import my_company
my_company.post_comment(arg)
from utilities.page.messages import messages
import json
messages.post(json.dumps(arg))