From 5dfba486a659684920a906e45c7fd12c707b4cbd Mon Sep 17 00:00:00 2001 From: Anand Doshi Date: Mon, 27 May 2013 12:25:28 +0530 Subject: [PATCH] [note] [fix] strip invalid characters from title and set it as the name of the note --- patches/may_2013/p06_make_notes.py | 2 ++ utilities/doctype/note/note.py | 5 +++++ utilities/doctype/note/note.txt | 3 +-- 3 files changed, 8 insertions(+), 2 deletions(-) diff --git a/patches/may_2013/p06_make_notes.py b/patches/may_2013/p06_make_notes.py index e1ea656238..b9dbca1859 100644 --- a/patches/may_2013/p06_make_notes.py +++ b/patches/may_2013/p06_make_notes.py @@ -2,6 +2,8 @@ import webnotes def execute(): webnotes.reload_doc("utilities", "doctype", "note") + webnotes.reload_doc("utilities", "doctype", "note_user") + for question in webnotes.conn.sql("""select * from tabQuestion""", as_dict=True): name = question.question[:180] if webnotes.conn.exists("Note", name): diff --git a/utilities/doctype/note/note.py b/utilities/doctype/note/note.py index beca2416e0..02862de6d9 100644 --- a/utilities/doctype/note/note.py +++ b/utilities/doctype/note/note.py @@ -7,6 +7,11 @@ class DocType: def __init__(self, d, dl): self.doc, self.doclist = d, dl + def autoname(self): + # replace forbidden characters + import re + self.doc.name = re.sub("[%'\"#*?`]", "", self.doc.title.strip()) + def onload(self): if not self.doc.public and webnotes.session.user != self.doc.owner: if webnotes.session.user not in [d.user for d in self.doclist if d.doctype=="Note User"]: diff --git a/utilities/doctype/note/note.txt b/utilities/doctype/note/note.txt index d14ecf7e5d..a6cdf2bf20 100644 --- a/utilities/doctype/note/note.txt +++ b/utilities/doctype/note/note.txt @@ -2,14 +2,13 @@ { "creation": "2013-05-24 13:41:00", "docstatus": 0, - "modified": "2013-05-24 16:47:19", + "modified": "2013-05-27 12:16:46", "modified_by": "Administrator", "owner": "Administrator" }, { "allow_print": 0, "allow_rename": 1, - "autoname": "field:title", "description": "Note is a free page where users can share documents / notes", "doctype": "DocType", "document_type": "Transaction",