def execute(self): self.section = None # make sure tmp config is unset. Config.unset_tmp_config() Config.reload_config() web = WebContainer.get_web() # read the current config file. # copy config to the path config_path = Config.get_config_path() if not os.path.exists(config_path): print "Installing default config file" dirname = os.path.dirname(config_path) if not os.path.exists(dirname): os.makedirs(dirname) if os.name == 'nt': osname = 'win32' else: osname = 'linux' install_dir = Environment.get_install_dir() install_config_path = "%s/src/install/start/config/tactic_%s-conf.xml" % ( install_dir, osname) shutil.copy(install_config_path, dirname) try: self.configure_db() self.configure_install() self.configure_mail_services() self.configure_gen_services() self.configure_asset_dir() self.configure_palette() self.configure_security() except Exception as e: raise TacticException('Error in [%s]: %s'%(self.section, e.__str__())) # FIXME: if this all fails, then revert back self.save_config() # after saving the config, test the database self.load_bootstrap() # remove the first run file data_dir = Environment.get_data_dir() path = "%s/first_run" % data_dir if os.path.exists(path): os.unlink(path) self.restart_program()
def execute(self): self.section = None # make sure tmp config is unset. Config.unset_tmp_config() Config.reload_config() web = WebContainer.get_web() # read the current config file. # copy config to the path config_path = Config.get_config_path() if not os.path.exists(config_path): print "Installing default config file" dirname = os.path.dirname(config_path) if not os.path.exists(dirname): os.makedirs(dirname) if os.name == 'nt': osname = 'win32' else: osname = 'linux' install_dir = Environment.get_install_dir() install_config_path = "%s/src/install/start/config/tactic_%s-conf.xml" % ( install_dir, osname) shutil.copy(install_config_path, dirname) try: self.configure_db() self.configure_install() self.configure_mail_services() self.configure_gen_services() self.configure_asset_dir() self.configure_palette() self.configure_security() except Exception as e: raise TacticException('Error in [%s]: %s' % (self.section, e.__str__())) # FIXME: if this all fails, then revert back self.save_config() # after saving the config, test the database self.load_bootstrap() # remove the first run file data_dir = Environment.get_data_dir() path = "%s/first_run" % data_dir if os.path.exists(path): os.unlink(path) self.restart_program()
def execute(my): # make sure tmp config is unset. Config.unset_tmp_config() Config.reload_config() web = WebContainer.get_web() # read the current config file. # copy config to the path config_path = Config.get_config_path() if not os.path.exists(config_path): print "Installing default config file" dirname = os.path.dirname(config_path) if not os.path.exists(dirname): os.makedirs(dirname) if os.name == 'nt': osname = 'win32' else: osname = 'linux' install_dir = Environment.get_install_dir() install_config_path = "%s/src/install/start/config/tactic_%s-conf.xml" % ( install_dir, osname) shutil.copy(install_config_path, dirname) my.configure_db() my.configure_install() my.configure_services() my.configure_asset_dir() my.configure_palette() # FIXME: if this all fails, then revert back my.save_config() # after saving the config, test the database my.load_bootstrap() # remove the first run file data_dir = Environment.get_data_dir() path = "%s/first_run" % data_dir if os.path.exists(path): os.unlink(path) my.restart_program()
def execute(my): my.section = None # make sure tmp config is unset. Config.unset_tmp_config() Config.reload_config() web = WebContainer.get_web() # read the current config file. # copy config to the path config_path = Config.get_config_path() if not os.path.exists(config_path): print "Installing default config file" dirname = os.path.dirname(config_path) if not os.path.exists(dirname): os.makedirs(dirname) if os.name == 'nt': osname = 'win32' else: osname = 'linux' install_dir = Environment.get_install_dir() install_config_path = "%s/src/install/start/config/tactic_%s-conf.xml" % ( install_dir, osname) shutil.copy(install_config_path, dirname) try: my.configure_db() my.configure_install() my.configure_mail_services() my.configure_gen_services() my.configure_asset_dir() my.configure_palette() my.configure_security() except Exception, e: raise TacticException('Error in [%s]: %s' % (my.section, e.__str__()))
def execute(my): my.section = None # make sure tmp config is unset. Config.unset_tmp_config() Config.reload_config() web = WebContainer.get_web() # read the current config file. # copy config to the path config_path = Config.get_config_path() if not os.path.exists(config_path): print "Installing default config file" dirname = os.path.dirname(config_path) if not os.path.exists(dirname): os.makedirs(dirname) if os.name == 'nt': osname = 'win32' else: osname = 'linux' install_dir = Environment.get_install_dir() install_config_path = "%s/src/install/start/config/tactic_%s-conf.xml" % ( install_dir, osname) shutil.copy(install_config_path, dirname) try: my.configure_db() my.configure_install() my.configure_mail_services() my.configure_gen_services() my.configure_asset_dir() my.configure_palette() my.configure_security() except Exception, e: raise TacticException('Error in [%s]: %s'%(my.section, e.__str__()))
def copy_start(my): #import pdb; pdb.set_trace() data_dir = Environment.get_data_dir(manual=True) # check to see if the data folder already exists print print "Data Directory [%s]" % data_dir install_dir = Environment.get_install_dir() # find criteria for initializing initialize = False if data_dir and not os.path.exists(data_dir): initialize = True if data_dir and not os.path.exists("%s/config" % data_dir): initialize = True if initialize: # copy the template over. This should exist even if it is not used print "... not found: initializing\n" install_data_path = "%s/src/install/start" % (install_dir) if os.path.exists(install_data_path): dirnames = os.listdir(install_data_path) for dirname in dirnames: to_dir = "%s/%s" % (data_dir, dirname) if os.path.exists(to_dir): print "WARNING: path [%s] exists ... skipping copying" % to_dir continue print "Copying to [%s]" % to_dir from_dir = "%s/%s" % (install_data_path, dirname) shutil.copytree(from_dir, to_dir) else: shutil.copytree(install_data_path, data_dir) #import pdb; pdb.set_trace() # copy the appropriate config file if os.name == 'nt': filename = 'standalone_win32-conf.xml' else: filename = 'standalone_linux-conf.xml' install_config_path = "%s/src/install/config/%s" % (install_dir,filename) to_config_path = "%s/config/tactic-conf.xml" % data_dir if not os.path.exists(to_config_path): dirname = os.path.dirname(to_config_path) if not os.path.exists(dirname): os.makedirs(dirname) shutil.copy(install_config_path, to_config_path) # some backwards compatibility issues old_config_path = "%s/config/tactic_linux-conf.xml" % data_dir if os.path.exists(old_config_path): new_config_path = "%s/config/tactic-conf.xml" % data_dir shutil.move(old_config_path, new_config_path) config_path = Config.get_config_path() config_exists = False if os.path.exists(config_path): config_exists = True #import pdb; pdb.set_trace() asset_dir = Environment.get_asset_dir() print "Asset Directory [%s]" % asset_dir tmp_dir = Environment.get_tmp_dir() print "Temp Directory [%s]" % tmp_dir # check if there is a config path already exists. If it does, # then don't do anything further. This is likely a previous # installation if config_exists: print "Config_path [%s]" % config_path return else: # if there is no config, retrieve data_dir in non-manual mode data_dir = Environment.get_data_dir() f = open("%s/first_run" % data_dir, 'w') f.write("") f.close() return
def get_display(my): top = my.top top.add_class("spt_db_config_top") top.add_style("width: 430px") top.add_style("min-height: 500") top.add_style("padding: 15px") top.add_style("margin-left: auto") top.add_style("margin-right: auto") top.add_color("background", "background", -10) top.add_border() title_wdg = DivWdg() top.add(title_wdg) title_wdg.add("System Configuration Setup") title_wdg.add_style("font-size: 20px") top.add("<hr/>") top.add("<i style='opacity: 0.5'>%s</i><br/>" % Config.get_config_path()) top.add("<br/>") checkin_keys=Config.get_section_values('checkin') checkin_keys=checkin_keys.keys() save_button = my.get_save_button(checkin_keys) top.add(save_button) vendor = Config.get_value("database", "vendor") title_wdg = DivWdg() top.add(title_wdg) title_wdg.add("<b>Database Setup</b>") title_wdg.add_style("margin-bottom: 10px") db_select = SelectWdg("database/vendor") db_select.set_option("labels", "SQLite|PostgreSQL|MySQL|Oracle|SQLServer") db_select.set_option("values", "Sqlite|PostgreSQL|MySQL|Oracle|SQLServer") db_select.set_value(vendor) db_select.add_behavior( { 'type': 'change', 'cbjs_action': ''' var key; if (bvr.src_el.value == 'Sqlite') { key = 'Sqlite'; } else { key = 'Other'; } var top = bvr.src_el.getParent(".spt_db_config_top"); var options_els = top.getElements(".spt_db_options"); for (var i = 0; i < options_els.length; i++) { var vendor = options_els[i].getAttribute("spt_vendor"); if (vendor == key) { spt.show(options_els[i]); } else { spt.hide(options_els[i]); } } ''' } ) option_div = DivWdg() top.add(option_div) option_div.add("Vendor: ") option_div.add(db_select) option_div.add_style("margin: 20px") sqlite_wdg = my.get_sqlite_wdg() option_div.add(sqlite_wdg) otherdb_wdg = my.get_otherdb_wdg() option_div.add(otherdb_wdg) if vendor == 'Sqlite': otherdb_wdg.add_style("display: none") sqlite_wdg.add_style("display", "") else: otherdb_wdg.add_style("display", "") sqlite_wdg.add_style("display: none") test_button = ActionButtonWdg(title="<< Test >>", tip="Test connecting to database") option_div.add(test_button) test_button.add_style("margin-left: auto") test_button.add_style("margin-right: auto") test_button.add_behavior( { 'type': 'click_up', 'cbjs_action': ''' var top = bvr.src_el.getParent(".spt_db_config_top"); var values = spt.api.Utility.get_input_values(top, null, false); var class_name = 'tactic.ui.startup.DbConfigCbk'; var server = TacticServerStub.get(); var kwargs = {}; var ret_val = server.execute_cmd(class_name, kwargs, values); var info = ret_val.info; if (info.error) { spt.error(info.error); } else { spt.info("Connection to database successful"); } ''' } ) # # Install # top.add("<hr/>") top.add("<br/>") title = "Installation" category = "install" options = ['default_project'] if 'tmp_dir' not in options: options.append('tmp_dir') top.add( my.configure_category(title, category, options) ) top.add("<hr/>") top.add("<br/>") top.add("<br/>") title = "Asset Management Setup" category = "checkin" options=checkin_keys[:] my._remove_item_from_list(options,'win32_server_handoff_dir') my._remove_item_from_list(options,'linux_server_handoff_dir') if os.name == "nt": options.append('win32_server_handoff_dir') else: options.append('linux_server_handoff_dir') top.add( my.configure_category(title, category, options) ) top.add("<hr/>") top.add("<br/>") title = "Mail Server " category = "services" options = ['mailserver', 'mail_user', 'mail_password', 'mail_port', 'mail_tls_enabled', 'mail_sender_disabled'] top.add( my.configure_category(title, category, options) ) top.add("<hr/>") title = "Services" category = "services" options = ['process_count', 'process_time_alive', 'thread_count', 'python_path'] top.add( my.configure_category(title, category, options) ) top.add("<hr/>") title = "Look and Feel" category = "look" options = ['palette'] top.add( my.configure_category(title, category, options) ) #wizard_wdg = WizardWdg() #top.add(wizard_wdg) #wizard_wdg.add(DivWdg("cow"), "cow") #wizard_wdg.add(DivWdg("pig"), "pig") #wizard_wdg.add(DivWdg("dog"), "dog") return top
def copy_start(self): data_dir = Environment.get_data_dir(manual=True) # check to see if the data folder already exists print print "Data Directory [%s]" % data_dir install_dir = Environment.get_install_dir() # find criteria for initializing initialize = False if data_dir and not os.path.exists(data_dir): initialize = True if data_dir and not os.path.exists("%s/config" % data_dir): initialize = True if initialize: # copy the template over. This should exist even if it is not used print "... not found: initializing\n" install_data_path = "%s/src/install/start" % (install_dir) if os.path.exists(install_data_path): dirnames = os.listdir(install_data_path) for dirname in dirnames: to_dir = "%s/%s" % (data_dir, dirname) if os.path.exists(to_dir): print "WARNING: path [%s] exists ... skipping copying" % to_dir continue print "Copying to [%s]" % to_dir from_dir = "%s/%s" % (install_data_path, dirname) shutil.copytree(from_dir, to_dir) else: shutil.copytree(install_data_path, data_dir) # create the dist folder to_dir = "%s/dist" % (data_dir) if not os.path.exists(to_dir): os.makedirs(to_dir) # copy the appropriate config file if os.name == 'nt': filename = 'standalone_win32-conf.xml' else: filename = 'standalone_linux-conf.xml' install_config_path = "%s/src/install/config/%s" % (install_dir, filename) to_config_path = "%s/config/tactic-conf.xml" % data_dir if not os.path.exists(to_config_path): dirname = os.path.dirname(to_config_path) if not os.path.exists(dirname): os.makedirs(dirname) shutil.copy(install_config_path, to_config_path) # some backwards compatibility issues old_config_path = "%s/config/tactic_linux-conf.xml" % data_dir if os.path.exists(old_config_path): new_config_path = "%s/config/tactic-conf.xml" % data_dir shutil.move(old_config_path, new_config_path) config_path = Config.get_config_path() config_exists = False if os.path.exists(config_path): config_exists = True # insert the plugin path to run get_asset_dir() plugin_dir = Environment.get_plugin_dir() sys.path.insert(0, plugin_dir) asset_dir = Environment.get_asset_dir() print "Asset Directory [%s]" % asset_dir tmp_dir = Environment.get_tmp_dir() print "Temp Directory [%s]" % tmp_dir # check if there is a config path already exists. If it does, # then don't do anything further. This is likely a previous # installation if config_exists: print "Config path [%s]" % config_path return else: # if there is no config, retrieve data_dir in non-manual mode data_dir = Environment.get_data_dir() f = open("%s/first_run" % data_dir, 'w') f.write("") f.close() return
def ask_questions(my): # set vendor default_vendor = Config.get_value("database", "vendor") print print "Please enter the database vendor (PostgreSQL or Oracle):" print while 1: if not default_vendor: default_vendor = "PostgreSQL" vendor = raw_input("(%s) -> " % default_vendor) if not vendor: vendor = default_vendor print if vendor in ['PostgreSQL', 'Oracle']: break else: print "ERROR: Vendor must one of 'PostgreSQL' or 'Oracle'" print # set server default_server = Config.get_value("database", "server") if not default_server: default_server = "localhost" print print "Please enter database server hostname or IP address:" print server = raw_input("(%s) -> " % default_server) if not server: server = default_server print # set the user default_user = Config.get_value("database", "user") if not default_user: default_user = "******" print print "Please enter user name accessing the database:" if vendor == "Oracle": print " (To access Oracle using schema names, type '__EMPTY__')" print user = raw_input("(%s) -> " % default_user) if not user: user = default_user print # set password from pyasm.search import DbPasswordUtil current_password = DbPasswordUtil.get_password() password = 0 password2 = 1 print print "Please enter database password:"******" (ENTER to keep password, '__EMPTY__' for empty password)" import getpass while password != password2: print password = getpass.getpass("Enter Password -> ") if password: password2 = getpass.getpass("Confirm Password -> ") else: password = current_password password2 = password break print if password == password2: break else: print "ERROR: Passwords do not match" # Summary: print print "Vendor: [%s]" % vendor print "Server: [%s]" % server print "User: [%s]" % user print ok = raw_input("Save to config (N/y) -> ") if ok.lower() != "y": print "Aborted" return # save the info from pyasm.search import DbPasswordUtil DbPasswordUtil.set_password(password) Config.set_value("database", "vendor", vendor) Config.set_value("database", "server", server) if user == "__EMPTY__": user = "" Config.set_value("database", "user", user) Config.save_config() path = Config.get_config_path() print print "Saved new database information to [%s]. Please restart TACTIC for the changes to take effect" % path print '''
def get_display(my): top = my.top top.add_class("spt_db_config_top") top.add_style("width: 430px") top.add_style("min-height: 500") top.add_style("padding: 15px") top.add_style("margin-left: auto") top.add_style("margin-right: auto") top.add_color("background", "background", -10) top.add_border() title_wdg = DivWdg() top.add(title_wdg) title_wdg.add("System Configuration Setup") title_wdg.add_style("font-size: 20px") top.add("<hr/>") top.add("<i style='opacity: 0.5'>%s</i><br/>" % Config.get_config_path()) top.add("<br/>") checkin_keys = Config.get_section_values('checkin') checkin_keys = checkin_keys.keys() save_button = my.get_save_button(checkin_keys) top.add(save_button) vendor = Config.get_value("database", "vendor") title_wdg = DivWdg() top.add(title_wdg) title_wdg.add("<b>Database Setup</b>") title_wdg.add_style("margin-bottom: 10px") db_select = SelectWdg("database/vendor") db_select.set_option("labels", "SQLite|PostgreSQL|MySQL|Oracle|SQLServer") db_select.set_option("values", "Sqlite|PostgreSQL|MySQL|Oracle|SQLServer") db_select.set_value(vendor) db_select.add_behavior({ 'type': 'change', 'cbjs_action': ''' var key; if (bvr.src_el.value == 'Sqlite') { key = 'Sqlite'; } else if (bvr.src_el.value == 'MySQL') { key = 'MySQL'; } else { key = 'Other'; } var top = bvr.src_el.getParent(".spt_db_config_top"); var options_els = top.getElements(".spt_db_options"); for (var i = 0; i < options_els.length; i++) { var vendor = options_els[i].getAttribute("spt_vendor"); if (vendor == key) { spt.show(options_els[i]); } else { spt.hide(options_els[i]); } } ''' }) option_div = DivWdg() top.add(option_div) option_div.add("Vendor: ") option_div.add(db_select) option_div.add_style("margin: 20px") sqlite_wdg = my.get_sqlite_wdg() option_div.add(sqlite_wdg) mysql_wdg = my.get_mysql_wdg() option_div.add(mysql_wdg) otherdb_wdg = my.get_otherdb_wdg() option_div.add(otherdb_wdg) if vendor == 'Sqlite': sqlite_wdg.add_style("display", "") otherdb_wdg.add_style("display: none") mysql_wdg.add_style("display: none") if vendor == 'MySQL': mysql_wdg.add_style("display", "") otherdb_wdg.add_style("display: none") sqlite_wdg.add_style("display: none") else: otherdb_wdg.add_style("display", "") mysql_wdg.add_style("display: none") sqlite_wdg.add_style("display: none") test_button = ActionButtonWdg(title=" Test ", tip="Test connecting to database") option_div.add(test_button) test_button.add_style("margin-left: auto") test_button.add_style("margin-right: auto") test_button.add_behavior({ 'type': 'click_up', 'cbjs_action': ''' var top = bvr.src_el.getParent(".spt_db_config_top"); var values = spt.api.Utility.get_input_values(top, null, false); var class_name = 'tactic.ui.startup.DbConfigCbk'; var server = TacticServerStub.get(); var kwargs = {}; var ret_val = server.execute_cmd(class_name, kwargs, values); var info = ret_val.info; if (info.error) { spt.error(info.error); } else { spt.info("Connection to database successful"); } ''' }) # # Install # top.add("<hr/>") top.add("<br/>") title = "Installation" category = "install" options = ['default_project'] if 'tmp_dir' not in options: options.append('tmp_dir') top.add(my.configure_category(title, category, options)) top.add("<hr/>") top.add("<br/>") top.add("<br/>") title = "Asset Management Setup" category = "checkin" options = checkin_keys[:] my._remove_item_from_list(options, 'win32_server_handoff_dir') my._remove_item_from_list(options, 'linux_server_handoff_dir') if os.name == "nt": options.append('win32_server_handoff_dir') else: options.append('linux_server_handoff_dir') top.add(my.configure_category(title, category, options)) top.add("<hr/>") top.add("<br/>") title = "Mail Server" category = "services" options = [ 'mailserver', 'mail_user', 'mail_password', 'mail_port', 'mail_tls_enabled', 'mail_sender_disabled' ] top.add(my.configure_category(title, category, options)) top.add("<hr/>") title = "Services" category = "services" options = [ 'process_count', 'process_time_alive', 'thread_count', 'python_path' ] top.add(my.configure_category(title, category, options)) top.add("<hr/>") title = "Look and Feel" category = "look" options = ['palette'] top.add(my.configure_category(title, category, options)) #wizard_wdg = WizardWdg() #top.add(wizard_wdg) #wizard_wdg.add(DivWdg("cow"), "cow") #wizard_wdg.add(DivWdg("pig"), "pig") #wizard_wdg.add(DivWdg("dog"), "dog") return top
def get_display(self): web = WebContainer.get_web() palette = web.get_palette() widget = DivWdg() widget.add_style("width: 100%") widget.add_style("text-align: center") from tactic.ui.app import PageHeaderWdg header = PageHeaderWdg(show_project=False) widget.add(header) security = Environment.get_security() search = Search("sthpw/project") search.add_where("\"code\" not in ('sthpw', 'admin', 'unittest')") search.add_where("\"type\" not in ('resource')") # hide template projects if security.check_access("builtin", "view_site_admin", "allow") or security.check_access( "builtin", "view_template_projects", "allow"): pass else: search.add_op("begin") search.add_filter("is_template", True, op='!=') search.add_filter("is_template", 'NULL', quoted=False, op='is') search.add_op("or") search.add_order_by("category") projects = search.get_sobjects() num = len(projects) # sort by project if num < 5: columns = 1 icon_size = 90 width = 500 elif num < 15: columns = 2 icon_size = 60 width = 700 else: columns = 3 icon_size = 45 width = 800 div = DivWdg() div.add_style("margin-left: auto") div.add_style("margin-right: auto") #div.add_style("width: 520px") div.center() widget.add(div) #logo = TacticLogoWdg() #div.add(logo) div.add("<br/>" * 3) bg_color = palette.color("background") #div.add_color("color", "color") from tactic.ui.container import RoundedCornerDivWdg div = RoundedCornerDivWdg(hex_color_code=bg_color, corner_size="10") div.set_dimensions(width_str='%spx' % width, content_height_str='50px') div.add_border() div.add_style("overflow: hidden") div.set_box_shadow() div.add_style("margin-left: auto") div.add_style("margin-right: auto") div.add_style("width: %spx" % width) table = Table() table.set_max_width() table.add_style("margin-left: auto") table.add_style("margin-right: auto") table.add_style("background-color: %s" % bg_color) table.add_color("color", "color") tr, td = table.add_row_cell() logo_div = DivWdg() logo_div.add_gradient("background", "background3", -5, -10) td.add(logo_div) logo = TacticLogoWdg() logo_div.add(logo) logo_div.add_style("margin: -6 -6 6 -6") app_name = WebContainer.get_web().get_app_name() security = Environment.get_security() last_category = None has_category = False index = 0 # if TACTIC has not been set up, show the configuration page # FIXME: what is the requirement for is_installed? config_path = Config.get_config_path() if not os.path.exists(config_path): is_installed = False else: is_installed = True #is_installed = True # filter out projects due to security filtered = [] for i, project in enumerate(projects): from pyasm.security import get_security_version security_version = get_security_version() if security_version >= 2: key = {"code": project.get_code()} key2 = {"code": "*"} keys = [key, key2] default = "deny" if not security.check_access( "project", keys, "allow", default=default): continue else: if not security.check_access( "project", project.get_code(), "view", default="allow"): continue filtered.append(project) projects = filtered if not is_installed: tr, td = table.add_row_cell() #from tactic.ui.startup import DbConfigWdg #td.add(DbConfigWdg()) title_div = DivWdg() td.add(title_div) title_div.add_style("padding: 5px") title_div.add_style("font-weight: bold") title_div.add("Getting Started ...") title_div.add_gradient("background", "background", -10) projects_div = DivWdg() projects_div.add_style("padding: 20px") td.add(projects_div) projects_div.add_style("text-align: center") projects_div.add("Welcome to TACTIC ...<br/>") projects_div.add_style("font-size: 22px") msg_div = DivWdg() td.add(msg_div) msg_div.add( "Configure TACTIC to connect to an external database and set up asset folders.<br/><br/>" ) msg_div.add_style("text-align: center") action = ActionButtonWdg(title='Confgure', size='medium') action.add_style("margin-left: auto") action.add_style("margin-right: auto") td.add(action) action.add_behavior({ 'type': 'click_up', 'cbjs_action': ''' document.location = "/tactic/admin/#/link/configure"; ''' }) msg_div = DivWdg() td.add(msg_div) msg_div.add( "<br/><br/>Or start using TACTIC with default configuration with an internal database.<br/><br/>" ) msg_div.add_style("text-align: center") action = ActionButtonWdg(title='Start >>', size='medium') action.add_style("margin-left: auto") action.add_style("margin-right: auto") td.add(action) action.add_behavior({ 'type': 'click_up', 'cbjs_action': ''' document.location = "/tactic"; ''' }) msg_div = DivWdg() td.add(msg_div) msg_div.add("<br/><br/><br/>") msg_div.add_style("text-align: center") elif projects: num_projets = 0 for i, project in enumerate(projects): category = project.get_value("category") if category is not None and category != last_category: table.add_row() tr, td = table.add_row_cell() category_div = DivWdg() td.add(category_div) if has_category and not category: category_div.add(" ") else: category_div.add(category) category_div.add_style("padding: 8px") category_div.add_style("font-size: 16px") category_div.add_style("font-weight: bold") category_div.add_color("color", "color") category_div.add_gradient("background", "background3", 0, -10) category_div.add_color("color", "color3") #category_div.set_round_corners() if last_category == None: category_div.add_style("margin: -6 -6 6 -6") else: category_div.add_style("margin: 15 -6 0 -6") table.add_row() has_category = True index = 0 index += 1 last_category = category thumb = ThumbWdg() thumb.set_name("snapshot") thumb.set_sobject(project) thumb.set_show_clipboard(False) thumb.set_has_img_link(False) thumb.set_icon_size(icon_size) code = project.get_code() title = project.get_value("title") # Restrict the length of project name if len(title) >= 36: title = title[:36] + "..." if app_name != 'Browser': href = HtmlElement.href(HtmlElement.h2(title), ref='/tactic/%s/%s'\ %(code, app_name)) img_href = HtmlElement.href(thumb, ref='/tactic/%s/%s'\ %(code, app_name)) link = '/tactic/%s/%s' % (code, app_name) else: href = HtmlElement.href(HtmlElement.h2(title), ref="/tactic/%s/" % code) img_href = DivWdg(thumb) img_href.add_behavior({ 'type': 'click_up', 'code': code, 'cbjs_action': ''' document.location = '/tactic/'+bvr.code+'/'; ''' }) link = '/tactic/%s/' % code href = href.get_buffer_display() if (index - 1) % columns == 0: table.add_row() td = table.add_cell() img_div = DivWdg() img_div.add(img_href) img_div.add_style("margin-right: 20px") img_div.add_style("float: left") img_div.add_border() #img_div.set_round_corners() img_div.set_box_shadow("0px 1px 5px") project_div = DivWdg() td.add(project_div) td.add_style("width: 230px") project_div.add_style("font-size: 16px") project_div.add_style("font-weight: bold") project_div.add_style("vertical-align: middle") project_div.add(img_div) #project_div.add(href) project_div.add(title) if project.get_value("is_template") == True: project_div.add( "<br/><i style='opacity: 0.5; font-size: 12px'>(template)</i>" ) project_div.add_style("height: %spx" % (icon_size - 10)) project_div.add_style("padding: 8px 10px 2px 20px") project_div.add_color("background", "background") project_div.add_behavior({ 'type': 'hover', 'add_color_modifier': -3, 'cb_set_prefix': 'spt.mouse.table_layout_hover', }) project_div.set_round_corners() project_div.add_class("hand") project_div.add_behavior({ 'type': 'click_up', 'link': link, 'title': title, 'cbjs_action': ''' document.location = bvr.link; ''' }) elif not security.check_access( "builtin", "view_site_admin", "allow", default="deny") and not security.check_access( "builtin", "create_projects", "allow", default="deny"): tr, td = table.add_row_cell() msg_div = DivWdg() td.add(msg_div) from pyasm.widget import IconWdg icon = IconWdg("WARNING", IconWdg.WARNING) msg_div.add(icon) msg_div.add("You are not permitted to view any projects") msg_div.add_style("font-size: 16px") msg_div.add_style("text-align: center") msg_div.add_style("font-weight: bold") msg_div.add_style("margin: 50px") msg_div.add("<br/>" * 2) msg_div.add("Please click to Sign Out:<br/>") action = ActionButtonWdg(title='Sign Out >>', size='m') msg_div.add(action) action.add_style('margin: 5px auto') action.add_style('text-align: center') web = WebContainer.get_web() action.add_behavior({ 'type': 'click_up', 'login': web.get_user_name(), 'cbjs_action': ''' var server = TacticServerStub.get(); server.execute_cmd("SignOutCmd", {login: bvr.login} ); window.location.href='/'; ''' }) else: tr, td = table.add_row_cell() title_div = DivWdg() td.add(title_div) title_div.add_style("padding: 10px") title_div.add_style("margin: -8px -6px 20px -6px") title_div.add_style("font-weight: bold") title_div.add("Getting Started ...") title_div.add_gradient("background", "background", -10) projects_div = DivWdg() projects_div.add_style("padding: 20px") td.add(projects_div) projects_div.add_style("text-align: center") projects_div.add("No Projects have been created ...<br/><br/>") projects_div.add_style("font-size: 22px") action = ActionButtonWdg(title='Create Project >>', size='large') action.add_style("margin-left: auto") action.add_style("margin-right: auto") projects_div.add(action) action.add_behavior({ 'type': 'click_up', 'cbjs_action': ''' document.location = "/tactic/admin/link/create_project"; ''' }) if security.check_access("builtin", "view_site_admin", "allow"): admin_div = DivWdg() #href = HtmlElement.href(HtmlElement.h2('Admin Site'), ref='/tactic/admin/') #admin_div.add(href) #admin_div.add_border() admin_div.add_style("font-size: 16px") admin_div.add_style("font-weight: bold") admin_div.add_style("height: 30px") link_div = DivWdg() link_div.add_class("hand") admin_div.add(link_div) link_div.add("Go to Admin Site") link_div.add_style("text-align: center") link_div.add_behavior({ 'type': 'click_up', 'cbjs_action': ''' document.location = '/tactic/admin/'; ''' }) tr, td = table.add_row_cell() td.add("<hr/><br/>") td.add(admin_div) div.add(table) widget.add(div) # Note sure what this is for #BaseAppServer.add_onload_script('spt.first_load=false') div.add_behavior({ 'type': 'load', 'cbjs_action': '''spt.first_load=false''' }) return widget
def get_display(self): web = WebContainer.get_web() palette = web.get_palette() widget = DivWdg() widget.add_style("width: 100%") widget.add_style("text-align: center") from tactic.ui.app import PageHeaderWdg header = PageHeaderWdg(show_project=False) widget.add( header ) security = Environment.get_security() search = Search("sthpw/project") search.add_where("\"code\" not in ('sthpw', 'admin', 'unittest')") search.add_where("\"type\" not in ('resource')") # hide template projects if security.check_access("builtin", "view_site_admin", "allow") or security.check_access("builtin", "view_template_projects", "allow"): pass else: search.add_op("begin") search.add_filter("is_template", True, op='!=') search.add_filter("is_template", 'NULL', quoted=False, op='is') search.add_op("or") search.add_order_by("category") projects = search.get_sobjects() num = len(projects) # sort by project if num < 5: columns = 1 icon_size = 90 width = 500 elif num < 15: columns = 2 icon_size = 60 width = 700 else: columns = 3 icon_size = 45 width = 800 div = DivWdg() div.add_style("margin-left: auto") div.add_style("margin-right: auto") #div.add_style("width: 520px") div.center() widget.add(div) #logo = TacticLogoWdg() #div.add(logo) div.add("<br/>"*3) bg_color = palette.color("background") #div.add_color("color", "color") from tactic.ui.container import RoundedCornerDivWdg div = RoundedCornerDivWdg(hex_color_code=bg_color,corner_size="10") div.set_dimensions( width_str='%spx' % width, content_height_str='50px' ) div.add_border() div.add_style("overflow: hidden") div.set_box_shadow() div.add_style("margin-left: auto") div.add_style("margin-right: auto") div.add_style("width: %spx" % width) table = Table() table.set_max_width() table.add_style("margin-left: auto") table.add_style("margin-right: auto") table.add_style("background-color: %s" % bg_color) table.add_color("color", "color") tr, td = table.add_row_cell() logo_div = DivWdg() logo_div.add_gradient("background", "background3", -5, -10) td.add(logo_div) logo = TacticLogoWdg() logo_div.add(logo) logo_div.add_style("margin: -6 -6 6 -6") app_name = WebContainer.get_web().get_app_name() security = Environment.get_security() last_category = None has_category = False index = 0 # if TACTIC has not been set up, show the configuration page # FIXME: what is the requirement for is_installed? config_path = Config.get_config_path() if not os.path.exists(config_path): is_installed = False else: is_installed = True #is_installed = True # filter out projects due to security filtered = [] for i, project in enumerate(projects): from pyasm.security import get_security_version security_version = get_security_version() if security_version >= 2: key = { "code": project.get_code() } key2 = { "code": "*" } keys = [key, key2] default = "deny" if not security.check_access("project", keys, "allow", default=default): continue else: if not security.check_access("project", project.get_code(), "view", default="allow"): continue filtered.append(project) projects = filtered if not is_installed: tr, td = table.add_row_cell() #from tactic.ui.startup import DbConfigWdg #td.add(DbConfigWdg()) title_div = DivWdg() td.add(title_div) title_div.add_style("padding: 5px") title_div.add_style("font-weight: bold") title_div.add("Getting Started ...") title_div.add_gradient("background", "background", -10) projects_div = DivWdg() projects_div.add_style("padding: 20px") td.add(projects_div) projects_div.add_style("text-align: center") projects_div.add("Welcome to TACTIC ...<br/>") projects_div.add_style("font-size: 22px") msg_div = DivWdg() td.add(msg_div) msg_div.add("Configure TACTIC to connect to an external database and set up asset folders.<br/><br/>") msg_div.add_style("text-align: center") action = ActionButtonWdg(title='Confgure', size='medium') action.add_style("margin-left: auto") action.add_style("margin-right: auto") td.add(action) action.add_behavior( { 'type': 'click_up', 'cbjs_action': ''' document.location = "/tactic/admin/#/link/configure"; ''' } ) msg_div = DivWdg() td.add(msg_div) msg_div.add("<br/><br/>Or start using TACTIC with default configuration with an internal database.<br/><br/>") msg_div.add_style("text-align: center") action = ActionButtonWdg(title='Start >>', size='medium') action.add_style("margin-left: auto") action.add_style("margin-right: auto") td.add(action) action.add_behavior( { 'type': 'click_up', 'cbjs_action': ''' document.location = "/tactic"; ''' } ) msg_div = DivWdg() td.add(msg_div) msg_div.add("<br/><br/><br/>") msg_div.add_style("text-align: center") elif projects: num_projets = 0 for i, project in enumerate(projects): category = project.get_value("category") if category is not None and category != last_category: table.add_row() tr, td = table.add_row_cell() category_div = DivWdg() td.add(category_div) if has_category and not category: category_div.add(" ") else: category_div.add(category) category_div.add_style("padding: 8px") category_div.add_style("font-size: 16px") category_div.add_style("font-weight: bold") category_div.add_color("color", "color") category_div.add_gradient("background", "background3",0, -10) category_div.add_color("color", "color3") #category_div.set_round_corners() if last_category == None: category_div.add_style("margin: -6 -6 6 -6") else: category_div.add_style("margin: 15 -6 0 -6") table.add_row() has_category = True index = 0 index += 1 last_category = category thumb = ThumbWdg() thumb.set_name("snapshot") thumb.set_sobject(project) thumb.set_show_clipboard(False) thumb.set_has_img_link(False) thumb.set_icon_size(icon_size) code = project.get_code() title = project.get_value("title") # Restrict the length of project name if len(title) >= 36: title = title[:36] + "..." if app_name != 'Browser': href = HtmlElement.href(HtmlElement.h2(title), ref='/tactic/%s/%s'\ %(code, app_name)) img_href = HtmlElement.href(thumb, ref='/tactic/%s/%s'\ %(code, app_name)) link = '/tactic/%s/%s' % (code, app_name) else: href = HtmlElement.href(HtmlElement.h2(title), ref="/tactic/%s/" % code) img_href = DivWdg(thumb) img_href.add_behavior( { 'type': 'click_up', 'code': code, 'cbjs_action': ''' document.location = '/tactic/'+bvr.code+'/'; ''' } ) link = '/tactic/%s/' % code href = href.get_buffer_display() if (index-1) % columns == 0: table.add_row() td = table.add_cell() img_div = DivWdg() img_div.add(img_href) img_div.add_style("margin-right: 20px") img_div.add_style("float: left") img_div.add_border() #img_div.set_round_corners() img_div.set_box_shadow("0px 1px 5px") project_div = DivWdg() td.add(project_div) td.add_style("width: 230px") project_div.add_style("font-size: 16px") project_div.add_style("font-weight: bold") project_div.add_style("vertical-align: middle") project_div.add(img_div) #project_div.add(href) project_div.add(title) if project.get_value("is_template") == True: project_div.add("<br/><i style='opacity: 0.5; font-size: 12px'>(template)</i>") project_div.add_style("height: %spx" % (icon_size-10)) project_div.add_style("padding: 8px 10px 2px 20px") project_div.add_color("background", "background") project_div.add_behavior( { 'type': 'hover', 'add_color_modifier': -3, 'cb_set_prefix': 'spt.mouse.table_layout_hover', } ) project_div.set_round_corners() project_div.add_class("hand") project_div.add_behavior( { 'type': 'click_up', 'link': link, 'title': title, 'cbjs_action': ''' document.location = bvr.link; ''' } ) elif not security.check_access("builtin", "view_site_admin", "allow", default="deny") and not security.check_access("builtin", "create_projects", "allow", default="deny"): tr, td = table.add_row_cell() msg_div = DivWdg() td.add(msg_div) from pyasm.widget import IconWdg icon = IconWdg("WARNING", IconWdg.WARNING) msg_div.add(icon) msg_div.add("You are not permitted to view any projects") msg_div.add_style("font-size: 16px") msg_div.add_style("text-align: center") msg_div.add_style("font-weight: bold") msg_div.add_style("margin: 50px") msg_div.add("<br/>"*2) msg_div.add("Please click to Sign Out:<br/>") action = ActionButtonWdg(title='Sign Out >>', size='m') msg_div.add(action) action.add_style('margin: 5px auto') action.add_style('text-align: center') web = WebContainer.get_web() action.add_behavior( { 'type': 'click_up', 'login': web.get_user_name(), 'cbjs_action': ''' var server = TacticServerStub.get(); server.execute_cmd("SignOutCmd", {login: bvr.login} ); window.location.href='/'; ''' } ) else: tr, td = table.add_row_cell() title_div = DivWdg() td.add(title_div) title_div.add_style("padding: 10px") title_div.add_style("margin: -8px -6px 20px -6px") title_div.add_style("font-weight: bold") title_div.add("Getting Started ...") title_div.add_gradient("background", "background", -10) projects_div = DivWdg() projects_div.add_style("padding: 20px") td.add(projects_div) projects_div.add_style("text-align: center") projects_div.add("No Projects have been created ...<br/><br/>") projects_div.add_style("font-size: 22px") action = ActionButtonWdg(title='Create Project >>', size='large') action.add_style("margin-left: auto") action.add_style("margin-right: auto") projects_div.add(action) action.add_behavior( { 'type': 'click_up', 'cbjs_action': ''' document.location = "/tactic/admin/link/create_project"; ''' } ) if security.check_access("builtin", "view_site_admin", "allow"): admin_div = DivWdg() #href = HtmlElement.href(HtmlElement.h2('Admin Site'), ref='/tactic/admin/') #admin_div.add(href) #admin_div.add_border() admin_div.add_style("font-size: 16px") admin_div.add_style("font-weight: bold") admin_div.add_style("height: 30px") link_div = DivWdg() link_div.add_class("hand") admin_div.add(link_div) link_div.add("Go to Admin Site") link_div.add_style("text-align: center") link_div.add_behavior( { 'type': 'click_up', 'cbjs_action': ''' document.location = '/tactic/admin/'; ''' } ) tr, td = table.add_row_cell() td.add("<hr/><br/>") td.add(admin_div) div.add(table) widget.add(div) # Note sure what this is for #BaseAppServer.add_onload_script('spt.first_load=false') div.add_behavior( { 'type': 'load', 'cbjs_action': '''spt.first_load=false''' } ) return widget