From 255c8dd90ce78307db9eaca717ff659a68749d37 Mon Sep 17 00:00:00 2001 From: Nabin Hait Date: Mon, 18 Nov 2013 16:51:40 +0530 Subject: [PATCH 1/2] [fix] [minor] pull updates from 1310 branch --- core/page/update_manager/update_manager.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core/page/update_manager/update_manager.py b/core/page/update_manager/update_manager.py index 527b40fedb..0186e38317 100644 --- a/core/page/update_manager/update_manager.py +++ b/core/page/update_manager/update_manager.py @@ -14,7 +14,7 @@ def update_this_app(): return _("This feature is only applicable to self hosted instances") from webnotes.utils import execute_in_shell, cstr, get_base_path - err, out = execute_in_shell("cd %s && exec ssh-agent lib/wnf.py --update origin master" % \ + err, out = execute_in_shell("cd %s && exec ssh-agent lib/wnf.py --update origin 1310" % \ (get_base_path(),)) return "\n".join(filter(None, [cstr(err), cstr(out)])) From fa8d397da73410386969bfb74323420d5c1ffb51 Mon Sep 17 00:00:00 2001 From: Nabin Hait Date: Wed, 20 Nov 2013 13:14:11 +0530 Subject: [PATCH 2/2] [fix] Rename and merge rewrite --- core/doctype/doctype/doctype.py | 12 +++++----- core/doctype/profile/profile.py | 39 +++++++++++++++++---------------- webnotes/__init__.py | 2 +- webnotes/model/rename_doc.py | 14 +++++++----- webnotes/utils/nestedset.py | 15 ++++++------- 5 files changed, 44 insertions(+), 38 deletions(-) diff --git a/core/doctype/doctype/doctype.py b/core/doctype/doctype/doctype.py index 844026c09d..f231a966f0 100644 --- a/core/doctype/doctype/doctype.py +++ b/core/doctype/doctype/doctype.py @@ -4,7 +4,7 @@ from __future__ import unicode_literals import webnotes -from webnotes import msgprint +from webnotes import msgprint, _ import os import MySQLdb @@ -103,11 +103,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)) diff --git a/core/doctype/profile/profile.py b/core/doctype/profile/profile.py index 42593b23cf..dd61e31fc7 100644 --- a/core/doctype/profile/profile.py +++ b/core/doctype/profile/profile.py @@ -234,9 +234,26 @@ Thank you,
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): - self.validate_rename(newdn, olddn) - + def before_rename(self, olddn, newdn, merge=False): + 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) @@ -258,22 +275,6 @@ Thank you,
# 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.msgprint("%s is not a valid email id" % email) - raise Exception def add_roles(self, *roles): for role in roles: diff --git a/webnotes/__init__.py b/webnotes/__init__.py index 0a8e92b031..f9a22c1dd2 100644 --- a/webnotes/__init__.py +++ b/webnotes/__init__.py @@ -378,7 +378,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 diff --git a/webnotes/model/rename_doc.py b/webnotes/model/rename_doc.py index 98f0113a38..7760fea57f 100644 --- a/webnotes/model/rename_doc.py +++ b/webnotes/model/rename_doc.py @@ -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): diff --git a/webnotes/utils/nestedset.py b/webnotes/utils/nestedset.py index 95c1bbd90b..df469b23bc 100644 --- a/webnotes/utils/nestedset.py +++ b/webnotes/utils/nestedset.py @@ -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) @@ -212,5 +212,4 @@ class DocTypeNestedSet(object): if webnotes.conn.sql("""select name from `tab%s` where %s=%s and docstatus!=2""" % (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")) - \ No newline at end of file + _(" can not be marked as a ledger as it has existing child")) \ No newline at end of file