Rushabh Mehta | 40182ba | 2012-06-19 14:15:13 +0530 | [diff] [blame] | 1 | def execute(): |
| 2 | import webnotes |
Rushabh Mehta | 40182ba | 2012-06-19 14:15:13 +0530 | [diff] [blame] | 3 | import webnotes.model.sync |
| 4 | |
Anand Doshi | 72c945b | 2012-06-22 20:01:07 +0530 | [diff] [blame] | 5 | # sync web page, blog doctype |
Rushabh Mehta | 40182ba | 2012-06-19 14:15:13 +0530 | [diff] [blame] | 6 | webnotes.model.sync.sync('website', 'web_page') |
Anand Doshi | 72c945b | 2012-06-22 20:01:07 +0530 | [diff] [blame] | 7 | webnotes.model.sync.sync('website', 'blog') |
| 8 | |
| 9 | cleanup() |
| 10 | |
| 11 | save_pages() |
Rushabh Mehta | 40182ba | 2012-06-19 14:15:13 +0530 | [diff] [blame] | 12 | |
Anand Doshi | 72c945b | 2012-06-22 20:01:07 +0530 | [diff] [blame] | 13 | def cleanup(): |
| 14 | import webnotes |
| 15 | |
| 16 | # delete pages from `tabPage` of module Website or of type Webpage |
| 17 | webnotes.conn.sql("""\ |
| 18 | delete from `tabPage` |
| 19 | where module='Website' and ifnull(web_page, 'No') = 'Yes'""") |
| 20 | |
| 21 | def save_pages(): |
| 22 | """save all web pages, blogs to create content""" |
| 23 | import webnotes |
| 24 | from webnotes.model.doclist import DocList |
| 25 | save_list = [ |
| 26 | { |
| 27 | 'doctype': 'Web Page', |
| 28 | 'query': """select name from `tabWeb Page` where docstatus=0""" |
| 29 | }, |
| 30 | { |
| 31 | 'doctype': 'Blog', |
| 32 | 'query': """\ |
| 33 | select name from `tabBlog` |
| 34 | where docstatus = 0 and ifnull(published, 0) = 1""" |
| 35 | }, |
Anand Doshi | 10bcf5e | 2012-06-26 18:54:10 +0530 | [diff] [blame] | 36 | { |
| 37 | 'doctype': 'Item', |
| 38 | 'query': """\ |
| 39 | select name from `tabItem` |
| 40 | where docstatus = 0 and ifnull(show_in_website, 'No') = 'Yes'""" |
| 41 | } |
Anand Doshi | 72c945b | 2012-06-22 20:01:07 +0530 | [diff] [blame] | 42 | ] |
| 43 | |
| 44 | for s in save_list: |
| 45 | for p in webnotes.conn.sql(s['query'], as_dict=1): |
| 46 | DocList(s['doctype'], p['name']).save() |