[minor] merge conflict fixed

This commit is contained in:
Nabin Hait 2013-11-21 12:33:52 +05:30
commit 57c98db8ea
5 changed files with 43 additions and 37 deletions

View file

@ -4,7 +4,7 @@
from __future__ import unicode_literals
import webnotes
from webnotes import msgprint
from webnotes import msgprint, _
import os
from webnotes.utils import now, cint
@ -100,11 +100,13 @@ class DocType:
webnotes.conn.sql("delete from `tabProperty Setter` where doc_type = %s", self.doc.name)
webnotes.conn.sql("delete from `tabReport` where ref_doctype=%s", self.doc.name)
def on_rename(self, new, old, merge=False):
def before_rename(self, old, new, merge=False):
if merge:
webnotes.throw(_("DocType can not be merged"))
def after_rename(self, old, new, merge=False):
if self.doc.issingle:
webnotes.conn.sql("""\
update tabSingles set doctype=%s
where doctype=%s""", (new, old))
webnotes.conn.sql("""update tabSingles set doctype=%s where doctype=%s""", (new, old))
else:
webnotes.conn.sql("rename table `tab%s` to `tab%s`" % (old, new))

View file

@ -237,11 +237,27 @@ Thank you,<br>
webnotes.conn.sql("""delete from `tabComment` where comment_doctype='Message'
and (comment_docname=%s or owner=%s)""", (self.doc.name, self.doc.name))
def on_rename(self,newdn,olddn, merge=False):
def before_rename(self, olddn, newdn, merge=False):
webnotes.clear_cache(user=olddn)
self.validate_rename(newdn, olddn)
self.validate_rename(olddn, newdn)
def validate_rename(self, olddn, newdn):
# do not allow renaming administrator and guest
if olddn in ["Administrator", "Guest"]:
webnotes.msgprint("""Hey! You are restricted from renaming the user: %s""" % \
(olddn, ), raise_exception=1)
self.validate_email_type(newdn)
def validate_email_type(self, email):
from webnotes.utils import validate_email_add
email = email.strip()
if not validate_email_add(email):
webnotes.msgprint("%s is not a valid email id" % email)
raise Exception
def after_rename(self, olddn, newdn, merge=False):
tables = webnotes.conn.sql("show tables")
for tab in tables:
desc = webnotes.conn.sql("desc `%s`" % tab[0], as_dict=1)
@ -263,21 +279,6 @@ Thank you,<br>
# update __Auth table
if not merge:
webnotes.conn.sql("""update __Auth set user=%s where user=%s""", (newdn, olddn))
def validate_rename(self, newdn, olddn):
# do not allow renaming administrator and guest
if olddn in ["Administrator", "Guest"]:
webnotes.msgprint("""Hey! You are restricted from renaming the user: %s""" % \
(olddn, ), raise_exception=1)
self.validate_email_type(newdn)
def validate_email_type(self, email):
from webnotes.utils import validate_email_add
email = email.strip()
if not validate_email_add(email):
webnotes.throw("%s is not a valid email id" % email)
def add_roles(self, *roles):
for role in roles:

View file

@ -458,7 +458,7 @@ def reload_doc(module, dt=None, dn=None, force=False):
def rename_doc(doctype, old, new, debug=0, force=False, merge=False):
from webnotes.model.rename_doc import rename_doc
rename_doc(doctype, old, new, force=force, merge=merge)
return rename_doc(doctype, old, new, force=force, merge=merge)
def insert(doclist):
import webnotes.model

View file

@ -3,7 +3,6 @@
from __future__ import unicode_literals
import webnotes
from webnotes import _
from webnotes.utils import cint
import webnotes.model.doctype
from webnotes.model.doc import validate_name
@ -23,10 +22,10 @@ def rename_doc(doctype, old, new, force=False, merge=False):
# get doclist of given doctype
doclist = webnotes.model.doctype.get(doctype)
# call on_rename
obj = webnotes.get_obj(doctype, old)
if hasattr(obj, 'on_rename'):
new = obj.on_rename(new, old, merge) or new
# call before_rename
old_obj = webnotes.get_obj(doctype, old)
if hasattr(old_obj, 'before_rename'):
new = old_obj.before_rename(old, new, merge) or new
new = validate_rename(doctype, new, doclist, merge, force)
@ -45,6 +44,11 @@ def rename_doc(doctype, old, new, force=False, merge=False):
if merge:
webnotes.delete_doc(doctype, old)
# call after_rename
new_obj = webnotes.get_obj(doctype, new)
if hasattr(new_obj, 'after_rename'):
new_obj.after_rename(old, new, merge)
return new
def update_attachments(doctype, old, new):

View file

@ -14,8 +14,6 @@ from __future__ import unicode_literals
import webnotes
from webnotes import msgprint, _
from webnotes.model.bean import Bean
from webnotes.model.doc import Document
# called in the on_update method
def update_nsm(doc_obj):
@ -191,13 +189,15 @@ class DocTypeNestedSet(object):
self.doc.fields[self.nsm_parent_field] = ""
update_nsm(self)
def on_rename(self, newdn, olddn, merge=False, group_fname="is_group"):
def before_rename(self, newdn, olddn, merge=False, group_fname="is_group"):
if merge:
is_group = webnotes.conn.get_value(self.doc.doctype, newdn, group_fname)
if self.doc.fields[group_fname] != is_group:
msgprint(_("""Merging is only possible between Group-to-Group or
Ledger-to-Ledger"""), raise_exception=1)
webnotes.throw(_("""Merging is only possible between Group-to-Group or
Ledger-to-Ledger"""))
def after_rename(self, olddn, newdn, merge=False):
if merge:
parent_field = "parent_" + self.doc.doctype.replace(" ", "_").lower()
rebuild_tree(self.doc.doctype, parent_field)
@ -213,4 +213,3 @@ class DocTypeNestedSet(object):
(self.doc.doctype, self.nsm_parent_field, '%s'), (self.doc.name)):
webnotes.throw(self.doc.doctype + ": " + self.doc.name +
_(" can not be marked as a ledger as it has existing child"))