From ffecc715febeae7ef2d076c41729c2b77940c2be Mon Sep 17 00:00:00 2001 From: Ravi Dey Date: Thu, 7 Jul 2011 13:51:46 +0530 Subject: [PATCH 1/8] update_feed fix --- home/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/home/__init__.py b/home/__init__.py index 36dbacfa80e..3d1f0360596 100644 --- a/home/__init__.py +++ b/home/__init__.py @@ -91,7 +91,7 @@ def update_feed1(doc): subject = subject % doc.fields make_feed(doc, subject, color) -def update_feed(doc, method): +def update_feed(doc, method=None): "adds a new feed" if method=='validate': return From 7a6211d67c4aaa50e8c9bea7b6c2b25aba96a5d0 Mon Sep 17 00:00:00 2001 From: Ravi Dey Date: Thu, 7 Jul 2011 15:49:24 +0530 Subject: [PATCH 2/8] profile settings fix --- patches/patch.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/patches/patch.py b/patches/patch.py index 8c839e13d01..446bdfffbcf 100644 --- a/patches/patch.py +++ b/patches/patch.py @@ -1,7 +1,7 @@ # REMEMBER to update this # ======================== -last_patch = 315 +last_patch = 316 #------------------------------------------- @@ -1271,3 +1271,5 @@ def execute(patch_no): m.parenttype = 'Module Def' m.parentfield = 'roles' m.save(1) + elif patch_no == 316: + sql("update `tabPage` set name = 'page-settings' where page_name = 'Profile Settings'") From 898227264533569f12cfb0c6693ef0ded35e345e Mon Sep 17 00:00:00 2001 From: Ravi Dey Date: Thu, 7 Jul 2011 15:52:35 +0530 Subject: [PATCH 3/8] profile settings fix --- patches/patch.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/patches/patch.py b/patches/patch.py index 446bdfffbcf..fb66a47e6c6 100644 --- a/patches/patch.py +++ b/patches/patch.py @@ -1,7 +1,7 @@ # REMEMBER to update this # ======================== -last_patch = 316 +last_patch = 317 #------------------------------------------- @@ -1272,4 +1272,7 @@ def execute(patch_no): m.parentfield = 'roles' m.save(1) elif patch_no == 316: - sql("update `tabPage` set name = 'page-settings' where page_name = 'Profile Settings'") + pass + elif patch_no == 317: + sql("update `tabPage` set name = 'profile-settings' where page_name = 'Profile Settings'") + From 8cfa84a6465876716bb1ce5852ce4f7b81eaeb20 Mon Sep 17 00:00:00 2001 From: Ravi Dey Date: Thu, 7 Jul 2011 16:37:03 +0530 Subject: [PATCH 4/8] bulk rename --- .../doctype/bulk_rename_tool/__init__.py | 0 .../bulk_rename_tool/bulk_rename_tool.py | 84 ++++++++++++++++ .../bulk_rename_tool/bulk_rename_tool.txt | 99 +++++++++++++++++++ 3 files changed, 183 insertions(+) create mode 100644 utilities/doctype/bulk_rename_tool/__init__.py create mode 100644 utilities/doctype/bulk_rename_tool/bulk_rename_tool.py create mode 100644 utilities/doctype/bulk_rename_tool/bulk_rename_tool.txt diff --git a/utilities/doctype/bulk_rename_tool/__init__.py b/utilities/doctype/bulk_rename_tool/__init__.py new file mode 100644 index 00000000000..e69de29bb2d diff --git a/utilities/doctype/bulk_rename_tool/bulk_rename_tool.py b/utilities/doctype/bulk_rename_tool/bulk_rename_tool.py new file mode 100644 index 00000000000..b8818f44076 --- /dev/null +++ b/utilities/doctype/bulk_rename_tool/bulk_rename_tool.py @@ -0,0 +1,84 @@ +# Please edit this list and import only required elements +import webnotes + +from webnotes.utils import add_days, add_months, add_years, cint, cstr, date_diff, default_fields, flt, fmt_money, formatdate, generate_hash, getTraceback, get_defaults, get_first_day, get_last_day, getdate, has_common, month_name, now, nowdate, replace_newlines, sendmail, set_default, str_esc_quote, user_format, validate_email_add +from webnotes.model import db_exists +from webnotes.model.doc import Document, addchild, removechild, getchildren, make_autoname, SuperDocType +from webnotes.model.doclist import getlist, copy_doclist +from webnotes.model.code import get_obj, get_server_obj, run_server_obj, updatedb, check_syntax +from webnotes import session, form, is_testing, msgprint, errprint + +set = webnotes.conn.set +sql = webnotes.conn.sql +get_value = webnotes.conn.get_value +in_transaction = webnotes.conn.in_transaction +convert_to_lists = webnotes.conn.convert_to_lists + +# ----------------------------------------------------------------------------------------- + +class DocType: + def __init__(self, d, dl): + self.doc, self.doclist = d, dl + + # bulk rename + def do_rename(self): + import csv + data = csv.reader(self.get_csv_data().splitlines()) + + updated = 0 + + msgprint(self.doc.rename_doctype) + + if self.doc.rename_doctype == 'Account': + for line in data: + if len(line)==2: + rec = sql("select tc.abbr, ta.name from `tabAccount` ta, `tabCompany` tc where ta.company = tc.name and ta.account_name = %s", line[0], as_dict=1) + if rec: + new_name = line[1] + ' - ' + rec[0]['abbr'] + + webnotes.conn.begin() + webnotes.model.rename(self.doc.rename_doctype, rec[0]['name'], new_name) + sql("update `tabAccount` set account_name = '%s' where name = '%s'" %(line[1],new_name)) + msgprint(new_name) + webnotes.conn.commit() + + updated += 1 + else: + msgprint("[Ignored] Incorrect format: %s" % str(line)) + else: + for line in data: + if len(line)==2: + + # call on_rename method if exists + obj = get_obj(self.doc.rename_doctype, line[0]) + if hasattr(obj, 'on_rename'): + obj.on_rename(line[1],line[0]) + + # rename the document + webnotes.model.rename(self.doc.rename_doctype, line[0], line[1]) + + sql("commit") + sql("start transaction") + + updated += 1 + else: + msgprint("[Ignored] Incorrect format: %s" % str(line)) + + + msgprint("%s items updated" % updated) + + # Update CSV data + def get_csv_data(self): + if not self.doc.file_list: + msgprint("File not attached!") + raise Exception + + fid = self.doc.file_list.split(',')[1] + + from webnotes.utils import file_manager + fn, content = file_manager.get_file(fid) + + if not type(content) == str: + content = content.tostring() + + return content diff --git a/utilities/doctype/bulk_rename_tool/bulk_rename_tool.txt b/utilities/doctype/bulk_rename_tool/bulk_rename_tool.txt new file mode 100644 index 00000000000..afb7005a9f9 --- /dev/null +++ b/utilities/doctype/bulk_rename_tool/bulk_rename_tool.txt @@ -0,0 +1,99 @@ +# DocType, Bulk Rename Tool +[ + + # These values are common in all dictionaries + { + 'creation': '2011-07-07 16:14:45', + 'docstatus': 0, + 'modified': '2011-07-07 16:16:16', + 'modified_by': 'Administrator', + 'owner': 'Administrator' + }, + + # These values are common for all DocType + { + '_last_update': '1310035501', + 'allow_attach': 1, + 'autoname': 'field:rename_doctype', + 'colour': 'White:FFF', + 'doctype': 'DocType', + 'module': 'Utilities', + 'name': '__common__', + 'section_style': 'Simple', + 'show_in_menu': 0, + 'version': 4 + }, + + # These values are common for all DocField + { + 'doctype': 'DocField', + 'name': '__common__', + 'parent': 'Bulk Rename Tool', + 'parentfield': 'fields', + 'parenttype': 'DocType', + 'permlevel': 0 + }, + + # These values are common for all DocPerm + { + 'doctype': 'DocPerm', + 'name': '__common__', + 'parent': 'Bulk Rename Tool', + 'parentfield': 'permissions', + 'parenttype': 'DocType', + 'read': 1, + 'role': 'System Manager' + }, + + # DocType, Bulk Rename Tool + { + 'doctype': 'DocType', + 'name': 'Bulk Rename Tool' + }, + + # DocPerm + { + 'create': 1, + 'doctype': 'DocPerm', + 'idx': 1, + 'permlevel': 0, + 'submit': 1, + 'write': 1 + }, + + # DocPerm + { + 'doctype': 'DocPerm', + 'idx': 2, + 'permlevel': 1 + }, + + # DocField + { + 'doctype': 'DocField', + 'fieldname': 'rename_doctype', + 'fieldtype': 'Data', + 'idx': 1, + 'label': 'Rename DocType', + 'options': 'Suggest', + 'reqd': 1 + }, + + # DocField + { + 'doctype': 'DocField', + 'fieldname': 'file_list', + 'fieldtype': 'Text', + 'idx': 2, + 'label': 'File List' + }, + + # DocField + { + 'doctype': 'DocField', + 'fieldtype': 'Button', + 'idx': 3, + 'label': 'Rename', + 'options': 'do_rename' + } +] \ No newline at end of file From f96fa9a87b512e4e96b4cf5ca722add353d423aa Mon Sep 17 00:00:00 2001 From: Ravi Dey Date: Thu, 7 Jul 2011 16:43:56 +0530 Subject: [PATCH 5/8] bulk rename py --- .../doctype/bulk_rename_tool/bulk_rename_tool.py | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/utilities/doctype/bulk_rename_tool/bulk_rename_tool.py b/utilities/doctype/bulk_rename_tool/bulk_rename_tool.py index b8818f44076..19cf07f6c18 100644 --- a/utilities/doctype/bulk_rename_tool/bulk_rename_tool.py +++ b/utilities/doctype/bulk_rename_tool/bulk_rename_tool.py @@ -38,8 +38,7 @@ class DocType: webnotes.conn.begin() webnotes.model.rename(self.doc.rename_doctype, rec[0]['name'], new_name) - sql("update `tabAccount` set account_name = '%s' where name = '%s'" %(line[1],new_name)) - msgprint(new_name) + sql("update `tabAccount` set account_name = '%s' where name = '%s'" %(line[1],new_name)) webnotes.conn.commit() updated += 1 @@ -49,16 +48,15 @@ class DocType: for line in data: if len(line)==2: - # call on_rename method if exists + webnotes.conn.begin() + obj = get_obj(self.doc.rename_doctype, line[0]) if hasattr(obj, 'on_rename'): - obj.on_rename(line[1],line[0]) - - # rename the document + obj.on_rename(line[1],line[0]) + webnotes.model.rename(self.doc.rename_doctype, line[0], line[1]) - sql("commit") - sql("start transaction") + webnotes.conn.commit() updated += 1 else: From cfc5dff4b4d2a17fee0a3441aa907bb42ed1ec58 Mon Sep 17 00:00:00 2001 From: Ravi Dey Date: Thu, 7 Jul 2011 16:48:54 +0530 Subject: [PATCH 6/8] reload doc --- patches/patch.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/patches/patch.py b/patches/patch.py index fb66a47e6c6..fa5ef497538 100644 --- a/patches/patch.py +++ b/patches/patch.py @@ -1,7 +1,7 @@ # REMEMBER to update this # ======================== -last_patch = 317 +last_patch = 318 #------------------------------------------- @@ -1275,4 +1275,5 @@ def execute(patch_no): pass elif patch_no == 317: sql("update `tabPage` set name = 'profile-settings' where page_name = 'Profile Settings'") - + elif patch_no == 318: + reload_doc('utilities', 'doctype', 'bulk_rename_tool') From 56ab7e4bb3888fe24f7429290d9cc6a0a4a336ab Mon Sep 17 00:00:00 2001 From: Anand Doshi Date: Thu, 7 Jul 2011 18:37:58 +0530 Subject: [PATCH 7/8] Added patch to remove feed entries starting with "New" --- patches/patch.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/patches/patch.py b/patches/patch.py index fb66a47e6c6..7f023e2e5b7 100644 --- a/patches/patch.py +++ b/patches/patch.py @@ -1,7 +1,7 @@ # REMEMBER to update this # ======================== -last_patch = 317 +last_patch = 318 #------------------------------------------- @@ -1275,4 +1275,7 @@ def execute(patch_no): pass elif patch_no == 317: sql("update `tabPage` set name = 'profile-settings' where page_name = 'Profile Settings'") + elif patch_no == 318: + sql("delete from tabFeed where doc_name like 'New %'") + From f3a5b778b937767e9147142e8c7fe30d899c73fd Mon Sep 17 00:00:00 2001 From: Ravi Dey Date: Thu, 7 Jul 2011 18:44:32 +0530 Subject: [PATCH 8/8] bulk rename --- utilities/doctype/bulk_rename_tool/bulk_rename_tool.txt | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/utilities/doctype/bulk_rename_tool/bulk_rename_tool.txt b/utilities/doctype/bulk_rename_tool/bulk_rename_tool.txt index afb7005a9f9..a5eb82cc482 100644 --- a/utilities/doctype/bulk_rename_tool/bulk_rename_tool.txt +++ b/utilities/doctype/bulk_rename_tool/bulk_rename_tool.txt @@ -3,11 +3,11 @@ # These values are common in all dictionaries { - 'creation': '2011-07-07 16:14:45', + 'creation': '2011-07-07 18:05:53', 'docstatus': 0, - 'modified': '2011-07-07 16:16:16', - 'modified_by': 'Administrator', - 'owner': 'Administrator' + 'modified': '2011-07-07 18:05:53', + 'modified_by': 'Guest', + 'owner': 'Guest' }, # These values are common for all DocType