2013-08-26 11:10:25 +00:00
if __name__ == " __main__ " :
import sys
sys . path . extend ( [ " . " , " lib " , " app " ] )
2013-08-26 10:47:50 +00:00
import webnotes , os
2013-09-01 05:44:32 +00:00
import utilities . demo . make_demo
2013-08-26 10:47:50 +00:00
2013-09-24 11:47:39 +00:00
def make_demo_app ( site = None ) :
2013-09-26 10:26:54 +00:00
webnotes . init ( site = site )
2013-10-10 06:33:11 +00:00
webnotes . flags . mute_emails = 1
2013-09-26 10:26:54 +00:00
2013-09-02 09:28:45 +00:00
utilities . demo . make_demo . make ( reset = True , simulate = False )
# setup demo user etc so that the site it up faster, while the data loads
make_demo_user ( )
make_demo_login_page ( )
make_demo_on_login_script ( )
utilities . demo . make_demo . make ( reset = False , simulate = True )
2013-10-10 10:13:32 +00:00
webnotes . destroy ( )
2013-08-26 10:47:50 +00:00
def make_demo_user ( ) :
2013-09-27 08:38:55 +00:00
from webnotes . auth import _update_password
2013-08-27 10:09:31 +00:00
roles = [ " Accounts Manager " , " Analytics " , " Expense Approver " , " Accounts User " ,
" Leave Approver " , " Blogger " , " Customer " , " Sales Manager " , " Employee " , " Support Manager " ,
" HR Manager " , " HR User " , " Maintenance Manager " , " Maintenance User " , " Material Manager " ,
2013-09-12 11:29:12 +00:00
" Material Master Manager " , " Material User " , " Manufacturing Manager " ,
2013-08-27 10:09:31 +00:00
" Manufacturing User " , " Projects User " , " Purchase Manager " , " Purchase Master Manager " ,
" Purchase User " , " Quality Manager " , " Report Manager " , " Sales Master Manager " ,
" Sales User " , " Supplier " , " Support Team " ]
def add_roles ( bean ) :
for role in roles :
p . doclist . append ( {
" doctype " : " UserRole " ,
" parentfield " : " user_roles " ,
" role " : role
} )
# make demo user
2013-08-26 10:47:50 +00:00
if webnotes . conn . exists ( " Profile " , " demo@erpnext.com " ) :
webnotes . delete_doc ( " Profile " , " demo@erpnext.com " )
p = webnotes . new_bean ( " Profile " )
p . doc . email = " demo@erpnext.com "
p . doc . first_name = " Demo "
p . doc . last_name = " User "
p . doc . enabled = 1
p . doc . user_type = " ERPNext Demo "
p . insert ( )
2013-08-27 10:09:31 +00:00
add_roles ( p )
p . save ( )
2013-09-27 08:38:55 +00:00
_update_password ( " demo@erpnext.com " , " demo " )
2013-08-26 10:47:50 +00:00
2013-08-27 10:09:31 +00:00
# make system manager user
if webnotes . conn . exists ( " Profile " , " admin@erpnext.com " ) :
webnotes . delete_doc ( " Profile " , " admin@erpnext.com " )
p = webnotes . new_bean ( " Profile " )
p . doc . email = " admin@erpnext.com "
p . doc . first_name = " Admin "
p . doc . last_name = " User "
p . doc . enabled = 1
p . doc . user_type = " System User "
p . insert ( )
roles . append ( " System Manager " )
add_roles ( p )
2013-08-26 10:47:50 +00:00
p . save ( )
2013-09-27 08:38:55 +00:00
_update_password ( " admin@erpnext.com " , " admin010123 " )
2013-08-26 13:23:50 +00:00
# only read for newsletter
webnotes . conn . sql ( """ update `tabDocPerm` set `write`=0, `create`=0, `cancel`=0
where parent = ' Newsletter ' """ )
2013-08-27 17:51:19 +00:00
webnotes . conn . sql ( """ update `tabDocPerm` set `write`=0, `create`=0, `cancel`=0
where parent = ' Profile ' and role = ' All ' """ )
2013-08-26 13:23:50 +00:00
2013-08-26 10:47:50 +00:00
webnotes . conn . commit ( )
def make_demo_login_page ( ) :
webnotes . conn . set_value ( " Website Settings " , None , " home_page " , " " )
webnotes . conn . sql ( """ delete from `tabWeb Page` where name= ' demo-login ' """ )
p = webnotes . new_bean ( " Web Page " )
p . doc . title = " Demo Login "
p . doc . published = 1
p . doc . description = " ERPNext Demo Login "
with open ( os . path . join ( os . path . dirname ( __file__ ) , " demo-login.html " ) , " r " ) as dfile :
p . doc . main_section = dfile . read ( )
p . doc . insert_code = 1
with open ( os . path . join ( os . path . dirname ( __file__ ) , " demo-login.js " ) , " r " ) as dfile :
p . doc . javascript = dfile . read ( )
p . doc . insert_style = 1
with open ( os . path . join ( os . path . dirname ( __file__ ) , " demo-login.css " ) , " r " ) as dfile :
p . doc . css = dfile . read ( )
p . insert ( )
2013-09-01 05:44:32 +00:00
website_settings = webnotes . bean ( " Website Settings " , " Website Settings " )
website_settings . doc . home_page = " demo-login "
website_settings . doc . disable_signup = 1
website_settings . save ( )
2013-08-26 10:47:50 +00:00
webnotes . conn . commit ( )
def make_demo_on_login_script ( ) :
2013-10-14 13:29:16 +00:00
import shutil
2013-11-06 08:49:09 +00:00
import webnotes . plugins
custom_script_path = webnotes . plugins . get_path ( " Core " , " DocType " , " Control Panel " )
2013-10-14 13:29:16 +00:00
webnotes . create_folder ( os . path . dirname ( custom_script_path ) )
shutil . copyfile ( os . path . join ( os . path . dirname ( __file__ ) , " demo_control_panel.py " ) , custom_script_path )
2013-08-27 09:19:04 +00:00
cp = webnotes . bean ( " Control Panel " )
cp . doc . custom_startup_code = """ wn.ui.toolbar.show_banner( ' You are using ERPNext Demo. To start your own ERPNext Trial, <a href= " https://erpnext.com/pricing-and-signup " target= " _blank " >click here</a> ' ) """
cp . save ( )
2013-08-26 14:21:24 +00:00
webnotes . conn . commit ( )
2013-08-26 10:47:50 +00:00
if __name__ == " __main__ " :
2013-09-26 10:26:54 +00:00
import sys
site = sys . argv [ 1 : ]
make_demo_app ( site = site and site [ 0 ] or None )