blob: 08174cbb8bc6f434c6afa9b7ef1bcbcea177ee84 [file] [log] [blame]
Rushabh Mehta40182ba2012-06-19 14:15:13 +05301def execute():
2 import webnotes
Rushabh Mehta40182ba2012-06-19 14:15:13 +05303 import webnotes.model.sync
4
Anand Doshi72c945b2012-06-22 20:01:07 +05305 # sync web page, blog doctype
Rushabh Mehta40182ba2012-06-19 14:15:13 +05306 webnotes.model.sync.sync('website', 'web_page')
Anand Doshi72c945b2012-06-22 20:01:07 +05307 webnotes.model.sync.sync('website', 'blog')
8
9 cleanup()
10
11 save_pages()
Rushabh Mehta40182ba2012-06-19 14:15:13 +053012
Anand Doshi72c945b2012-06-22 20:01:07 +053013def 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
Anand Doshie47def82012-07-09 15:56:12 +053021 # change show_in_website value in item table to 0 or 1
22 webnotes.conn.sql("""\
23 update `tabItem`
24 set show_in_website = if(show_in_website = 'Yes', 1, 0)
25 where show_in_website is not null""")
26
Anand Doshi72c945b2012-06-22 20:01:07 +053027def save_pages():
28 """save all web pages, blogs to create content"""
29 import webnotes
30 from webnotes.model.doclist import DocList
31 save_list = [
32 {
33 'doctype': 'Web Page',
34 'query': """select name from `tabWeb Page` where docstatus=0"""
35 },
36 {
37 'doctype': 'Blog',
38 'query': """\
39 select name from `tabBlog`
40 where docstatus = 0 and ifnull(published, 0) = 1"""
41 },
Anand Doshi10bcf5e2012-06-26 18:54:10 +053042 {
43 'doctype': 'Item',
44 'query': """\
45 select name from `tabItem`
46 where docstatus = 0 and ifnull(show_in_website, 'No') = 'Yes'"""
47 }
Anand Doshi72c945b2012-06-22 20:01:07 +053048 ]
49
50 for s in save_list:
51 for p in webnotes.conn.sql(s['query'], as_dict=1):
52 DocList(s['doctype'], p['name']).save()