brotherton-erpnext/patches/may_2013/p06_make_notes.py

45 lines
1.4 KiB
Python
Raw Normal View History

# Copyright (c) 2013, Web Notes Technologies Pvt. Ltd.
# License: GNU General Public License v3. See license.txt
import webnotes, markdown2
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):
2013-05-29 11:07:11 +05:30
if question.question:
2013-07-16 15:14:13 +05:30
try:
name = question.question[:180]
if webnotes.conn.exists("Note", name):
webnotes.delete_doc("Note", name)
2013-08-23 12:21:52 +05:30
similar_questions = webnotes.conn.sql_list("""select name from `tabQuestion`
where question like %s""", "%s%%" % name)
answers = [markdown2.markdown(c) for c in webnotes.conn.sql_list("""
select answer from tabAnswer where question in (%s)""" % \
", ".join(["%s"]*len(similar_questions)), similar_questions)]
webnotes.bean({
2013-07-16 15:14:13 +05:30
"doctype":"Note",
"title": name,
2013-08-23 12:21:52 +05:30
"content": "<hr>".join(answers),
2013-07-16 15:14:13 +05:30
"owner": question.owner,
"creation": question.creation,
"public": 1
}).insert()
2013-08-23 12:21:52 +05:30
2013-07-16 15:14:13 +05:30
except NameError:
pass
2013-08-23 12:21:52 +05:30
except Exception, e:
if e.args[0] != 1062:
raise e
2013-05-29 13:19:27 +05:30
webnotes.delete_doc("DocType", "Question")
webnotes.delete_doc("DocType", "Answer")
2013-05-27 14:47:56 +05:30
webnotes.bean("Style Settings").save()
# update comment delete
webnotes.conn.sql("""update tabDocPerm \
set cancel=1 where parent='Comment' and role='System Manager'""")