def get_display(self): search_key = self.kwargs.get("search_key") msg = None base_search_type = SearchKey.extract_search_type(search_key) sobject = SearchKey.get_by_search_key(search_key) process_div = DivWdg() process_div.add_style('padding-top: 10px') if base_search_type in ['sthpw/task', 'sthpw/note']: self.process = sobject.get_value('process') self.context = sobject.get_value('context') if not self.process: self.process = '' parent = sobject.get_parent() if parent: search_key = SearchKey.get_by_sobject(parent) else: msg = "Parent for [%s] not found"%search_key else: self.process = self.kwargs.get('process') top = self.top top.add_class('spt_simple_checkin') top.add_color("background", "background") top.add_styles("position: relative") content = DivWdg(msg) top.add(content) #content.add_border() #content.add_color("background", "background3") #content.add_color("color", "background3") content.add_style("width: 600px") content.add_styles("margin-left: auto; margin-right: auto;") content.add_style("height: 200px") from tactic.ui.widget import CheckinWdg content.add_behavior( { 'type': 'load', 'cbjs_action': CheckinWdg.get_onload_js() } ) button_div = DivWdg() content.add(process_div) content.add(button_div) button = IconWdg(title="Check-In", icon=IconWdg.CHECK_IN_3D_LG) title = Common.get_display_title(self.checkin_action) button.add_attr('title', title) button_div.add(button) button_div.set_box_shadow("1px 1px 1px 1px") button_div.add_style("width: 60px") button_div.add_style("height: 60px") button_div.add_style("float: left") button_div.add_style("background: white") button_div.add_class("hand") button_div.add_style("padding: 2px 3px 0 0") button_div.add_style("margin: 20px 60px 20px 200px") button_div.add_style("text-align: center") button_div.add("Check-in") # to be consistent with Check-in New File if self.process: checkin_process = self.process else: # Dont' specify, the user can choose later in check-in widget checkin_process = '' button.add_behavior( { 'type': 'click_up', 'search_key': search_key, 'process': checkin_process, 'context': self.context, 'cbjs_action': ''' var class_name = 'tactic.ui.widget.CheckinWdg'; var applet = spt.Applet.get(); spt.app_busy.show("Choose file(s) to check in") var current_dir = null; var is_sandbox = false; var refresh = false var values = spt.checkin.browse_folder(current_dir, is_sandbox, refresh); if (!values) { spt.app_busy.hide(); return; } var file_paths = values.file_paths; if (file_paths.length == 0) { spt.alert("You need to select files(s) to check in."); spt.app_busy.hide(); return; } spt.app_busy.hide(); var args = { 'search_key': bvr.search_key, 'show_links': false, 'show_history': false, 'close_on_publish': true } if (bvr.process) args.process = bvr.process; if (bvr.context) args.context = bvr.context; var kwargs = {}; kwargs.values = values; spt.panel.load_popup("Check-in", class_name, args, kwargs); /* var options= { title: "Check-in Widget", class_name: 'tactic.ui.widget.CheckinWdg', popup_id: 'checkin_widget' }; var bvr2 = {}; bvr2.options = options; bvr2.values = values; bvr2.args = args; spt.popup.get_widget({}, bvr2) */ ''' } ) button_div = DivWdg() content.add(button_div) button = IconWdg(title="Check-Out", icon=IconWdg.CHECK_OUT_3D_LG) button_div.add(button) button_div.set_box_shadow("1px 1px 1px 1px") button_div.add_style("width: 60px") button_div.add_style("height: 60px") button_div.add_style("float: left") button_div.add_style("margin: 20px") button_div.add_style("padding: 2px 3px 0 0") button_div.add_style("background: white") button_div.add_class("hand") button_div.add_style("text-align: center") button_div.add("Check-out") sobject = SearchKey.get_by_search_key(search_key) # snapshot is retrieved for getting the process informatoin, they are not being used # for loading as real_time snapshot query option is used. search = Search("sthpw/snapshot") search.add_sobject_filter(sobject) if self.process: search.add_filter("process", self.process) search.add_filter("is_latest", True) snapshot = search.get_sobject() if not self.process and snapshot: self.process = snapshot.get_value('process') # for old process-less snapshots if not self.process: self.process = snapshot.get_value('context') process_wdg = DivWdg(HtmlElement.b(checkin_process)) if checkin_process: width = len(checkin_process)*10 else: width = 10 process_wdg.add_styles('margin-left: auto; margin-right: auto; text-align: center; width: %s'%width) process_div.add(process_wdg) # DO NOT pass in snapshot_code, get it in real time snapshot_codes = [] show_status = True if self.checkout_action == 'latest': cbjs_action = CheckinSandboxListWdg.get_checkout_cbjs_action(self.process, show_status) bvr = {'snapshot_codes': snapshot_codes, 'real_time': True, 'file_types': ['main'], 'filename_mode': 'repo', 'cbjs_action': cbjs_action} elif self.checkout_action == 'latest (version_omitted)': cbjs_action = CheckinSandboxListWdg.get_checkout_cbjs_action(self.process, show_status) bvr = {'snapshot_codes':snapshot_codes, 'real_time': True, 'file_types': ['main'], 'filename_mode': 'versionless', 'cbjs_action': cbjs_action} elif self.checkout_action == 'latest versionless': cbjs_action = CheckinSandboxListWdg.get_checkout_cbjs_action(self.process, show_status) bvr = {'snapshot_codes':snapshot_codes, 'real_time': True, 'versionless': True, 'file_types': ['main'], 'filename_mode': 'versionless', 'cbjs_action': cbjs_action} elif self.checkout_action == 'open file browser': bvr = { 'cbjs_action': ''' var class_name = 'tactic.ui.checkin.SObjectDirListWdg'; var kwargs = { search_keys: [bvr.search_key], process: '%s' }; spt.panel.load_popup("Check-out", class_name, kwargs); '''%self.process } bvr.update({ 'type': 'click_up', 'search_key': search_key}) button.add_behavior(bvr) title = Common.get_display_title(self.checkout_action) button.add_attr('title', title) #TODO: remove these margin-top which is used to compensate all the ButtonNewWdg top extra white space content.add("<br clear='all'/>") status_div = DivWdg() status_div.add_style('margin: 20px 0 0 10px') status_div.add_style('width: 100%') text_info = FloatDivWdg() text_info.add_styles('padding: 4px; width: 500px') text_info.add_style('margin-top: 8px') text_info.add_attr('title','Displays the last checked out file path') text_info.add_border() text_info.set_round_corners() text_content = DivWdg() text_content.add(' ') text_content.add_class('spt_status_area') text_info.add(text_content) label = FloatDivWdg('path:') label.add_style('margin: 12px 6px 0 6px') # button button = ButtonNewWdg(title="Explore", icon=IconWdg.FOLDER_GO) button.add_style('padding-bottom: 15px') button.add_behavior( { 'type': 'click_up', 'cbjs_action': ''' var applet = spt.Applet.get(); var status_div = bvr.src_el.getParent('.spt_simple_checkin').getElement('.spt_status_area'); var value = status_div.get('text'); var dir_name = spt.path.get_dirname(value); if (dir_name) applet.open_explorer(dir_name); ''' } ) status_div.add(label) status_div.add(text_info) content.add(status_div) content.add(button) content.add_behavior({'type':'load', 'cbjs_action': ''' if (!spt.Applet.applet) { spt.api.app_busy_show('Initializing Java', 'Please wait...'); var exec = function() {var applet = spt.Applet.get()}; spt.api.app_busy_hide(exec); }'''}) return top
def dump_tactic_inserts(my, path, mode='sql'): assert my.db_resource assert my.table database = my.db_resource.get_database() assert mode in ['sql', 'sobject'] if path: import os dirname = os.path.dirname(path) if not os.path.exists(dirname): os.makedirs(dirname) #f = open(path, 'w') #f = codecs.open(path, 'a', 'utf-8') UTF8Writer = codecs.getwriter('utf8') f = UTF8Writer(open(path, 'ab')) else: import sys f = sys.stdout from pyasm.search import Insert, Select, DbContainer, Search, Sql # get the data if not my.sobjects: search = Search("sthpw/search_object") search.add_filter("table_name", my.table) search.add_order_by("id") my.search_type_obj = search.get_sobject() if not my.search_type_obj: if my.no_exception == False: raise Exception( "Table [%s] does not have a corresponding search_type" % my.table) else: return search_type = my.search_type_obj.get_base_key() search = Search(search_type) search.set_show_retired(True) my.sobjects = search.get_sobjects() # get the info for the table from pyasm.search import SearchType, Sql column_info = SearchType.get_column_info(my.search_type) for sobject in my.sobjects: f.write("%s\n" % my.delimiter) if mode == 'sobject': search_type = sobject.get_base_search_type() f.write("insert = SearchType.create('%s')\n" % search_type) if my.skip_invalid_column: f.write("insert.skip_invalid_column()\n") else: f.write("insert.set_table('%s')\n" % my.table) data = sobject.get_data() for name, value in data.items(): if my.replace_dict: for column, replace_args in my.replace_dict.items(): if name == column: replace_str = replace_args[0] regex = replace_args[1] if regex: #if not re.match(regex,value): # raise TacticException("%s does not conform to standard format. Expected format must match %s"%(column,regex)) value = re.sub(regex, replace_str, value) else: value = replace_str if name in my.ignore_columns: continue if name == '_tmp_spt_rownum': continue if not my.include_id and name == "id": #insert.set_value("id", '"%s_id_seq".nextval' % table, quoted=False) pass elif value == None: continue else: # This is not strong enough #if value.startswith("{") and value.endswith("}"): # f.write("insert.set_expr_value('%s', \"\"\"%s\"\"\")\n" % (name, value)) if type(value) == types.IntType or \ type(value) == types.FloatType or \ type(value) == types.BooleanType or \ type(value) == types.LongType: f.write("insert.set_value('%s', %s)\n" % (name, value)) else: # if the value contains triple double quotes, convert to # triple quotes if isinstance(value, datetime.datetime): value = str(value) elif isinstance(value, unicode): #value = str(value) value = value.encode("UTF-8") # this fixes a problem with non-ascii characters if isinstance(value, basestring): quoted = value.startswith('"') and value.endswith( '"') value = repr(value) quoted2 = value.startswith('"') and value.endswith( '"') if not quoted and quoted2: value = value.strip('"') # repr puts single quotes at the start and end if value.startswith("'") and value.endswith("'"): value = value[1:-1] # and it puts a slash in front value = value.replace(r"\'", "'") # replace literal \n with newline (comes from repr) value = value.replace(r"\n", "\n") value = value.replace('"""', "'''") #value = value.replace("\\", "\\\\") # handle the case where the value starts with a quote if value.startswith('"'): value = '\\%s' % value # handle the case where the value ends starts with a quote if value.endswith('"'): value = '%s\\"' % value[:-1] f.write("insert.set_value('%s', \"\"\"%s\"\"\")\n" % (name, value)) # Disable commit for now #if mode == 'sobject': # f.write("insert.commit()\n") f.write("%s\n" % my.end_delimiter) f.write("\n") if path: f.close()
def get_display(my): 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") 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 handle_layout_behaviors(my, layout): # Basic button behaviors layout.add_relay_behavior( { 'type': 'mouseover', 'bvr_match_class': 'spt_button_hit_wdg', 'cbjs_action': ''' var top = bvr.src_el.getParent(".spt_button_top") var over = top.getElement(".spt_button_over"); var click = top.getElement(".spt_button_click"); click.setStyle("display", "none"); ''' } ) layout.add_relay_behavior( { 'type': 'mouseout', 'bvr_match_class': 'spt_button_hit_wdg', 'cbjs_action': ''' var top = bvr.src_el.getParent(".spt_button_top") var over = top.getElement(".spt_button_over"); var click = top.getElement(".spt_button_click"); click.setStyle("display", "none"); ''' } ) layout.add_relay_behavior( { 'type': 'mousedown', 'bvr_match_class': 'spt_button_hit_wdg', 'cbjs_action': ''' var top = src_el.getParent(".spt_button_top") var over = top.getElement(".spt_button_over"); var click = top.getElement(".spt_button_click"); click.setStyle("display", ""); ''' } ) layout.add_relay_behavior( { 'type': 'mouseup', 'bvr_match_class': 'spt_button_hit_wdg', 'cbjs_action': ''' var top = bvr.src_el.getParent(".spt_button_top") var over = top.getElement(".spt_button_over"); var click = top.getElement(".spt_button_click"); click.setStyle("display", "none"); ''' } ) # handle custom behavior for button script_code = my.get_option("script_code") # deprecated if not script_code: script_code = my.get_option("script") path = my.get_option("path") if not path: path = my.get_option("script_path") inline = my.get_option("cbjs_action") if script_code: search = Search("config/custom_script") search.add_filter("code", script_code) my.script_obj = search.get_sobject() elif path: parts = path.split("/") folder = "/".join( parts[:-1]) title = parts[-1] search = Search("config/custom_script") search.add_filter("folder", folder) search.add_filter("title", title) my.script_obj = search.get_sobject() elif inline: my.script = inline # NOTE: my.behavior can contain a lot of goodies which are # ignored here. ie: CheckinButtonElementWdg if my.behavior.get('cbjs_action'): my.script = my.behavior.get('cbjs_action') #behavior = {} behavior = my.behavior behavior['type'] = 'mouseup' #my.behavior['search_key'] = search_key behavior['bvr_match_class'] = "spt_button_%s" % my.name if my.script: behavior['cbjs_action'] = ''' var layout = bvr.src_el.getParent(".spt_layout"); var sk; if (layout.getAttribute("spt_version") == "2") { var row = bvr.src_el.getParent('.spt_table_row'); sk = row.getAttribute('spt_search_key'); } else { var td = bvr.src_el.getParent('td'); sk = td.getAttribute('search_key'); } bvr.search_key = sk; %s'''% my.script elif my.script_obj: behavior['cbjs_action'] = ''' var layout = bvr.src_el.getParent(".spt_layout"); var sk; if (layout.getAttribute("spt_version") == "2") { var row = bvr.src_el.getParent('.spt_table_row'); sk = row.getAttribute('spt_search_key'); } else { var td = bvr.src_el.getParent('td'); sk = td.getAttribute('search_key'); } bvr.search_key = sk; spt.CustomProject.custom_script(evt,bvr); ''' script_code = my.script_obj.get_code() behavior['script_code'] = script_code else: behavior['cbjs_action'] = '''spt.alert("No script defined for this button");''' layout.add_relay_behavior(behavior)
def get(cls, reset_cache=False, project_code=None): if not project_code: from project import Project project_code = Project.get_project_code() if not reset_cache: schema = Container.get("Schema:%s" % project_code) if schema: return schema # the predefined ones cannot be overriden if project_code in ['unittest']: schema = cls.get_predefined_schema(project_code) schema.init() sthpw_schema = cls.get_predefined_schema("admin") sthpw_schema.init() schema.sthpw_schema = sthpw_schema #return schema elif project_code in ['sthpw', 'admin']: sthpw_schema = cls.get_predefined_schema("admin") sthpw_schema.init() return sthpw_schema # by default the code of the schema is the project code #schema = cls.get_by_project_code(project_code) # find using explicit search ... too much nested caching going # on here. It is confusing when changing schema search = Search("sthpw/schema") search.add_op("begin") if project_code not in ['unittest']: search.add_filter("code", project_code) search.add_filter("project_code", project_code) search.add_op("or") schemas = search.get_sobjects() if project_code in ['unittest']: schemas.insert(0, schema) if len(schemas) > 1: schema = SearchType.create("sthpw/schema") schema.set_value("code", project_code) schema.set_value("project_code", project_code) new_xml = [] new_xml.append("<schema>\n") for schema in schemas: xml = schema.get_xml_value("schema") nodes = xml.get_nodes("schema/*") for node in nodes: new_xml.append(xml.to_string(node)) new_xml.append("</schema>\n") new_xml = "".join(new_xml) #print new_xml schema.set_value("schema", new_xml) elif schemas: schema = schemas[0] else: schema = None # if the project schema does not exist, then create an empty one if not schema: schema = Schema("sthpw/schema", dependencies=False) schema.set_value("schema", "<schema/>") schema.set_value("code", project_code) schema.init() schema.add_dependencies() Container.put("Schema:%s" % project_code, schema) return schema
def get_display(my): search = Search(Project) search.add_where("\"code\" not in ('sthpw','admin')") my.set_search_for_options(search, 'code', 'code') my.set_option('default', Project.get_project_code()) return super(MultiProjectSelectWdg, my).get_display()
def get_display(self): top = DivWdg() top.add_border() top.add_style("padding: 10px") top.add_color("color", "color") top.add_color("background", "background") #top.add_style("height: 550px") top.add_class("spt_reports_top") title = DivWdg() title.add("Searchable Lists") title.add_style("font-size: 18px") title.add_style("font-weight: bold") title.add_style("text-align: center") title.add_style("padding: 10px") title.add_style("margin: -10px -10px 0px -10px") top.add(title) title.add_gradient("background", "background3", 5, -10) top.add("<br/>") button_div = DivWdg() top.add(button_div) button = SingleButtonWdg(title="Collapse", icon=IconWdg.ARROW_UP) button_div.add(button) top.add(button_div) button.add_behavior({ 'type': 'click_up', 'cbjs_action': ''' var top = bvr.src_el.getParent(".spt_reports_top"); var element = top.getElement(".spt_reports_list"); spt.toggle_show_hide(element) ''' }) #desc = DivWdg() #top.add(desc) #desc.add("Dashboard") #desc.add_style("width: 600px") reports = [] # read the config file """ from pyasm.widget import WidgetConfig tmp_path = __file__ dir_name = os.path.dirname(tmp_path) file_path="%s/../config/reports-conf.xml" % (dir_name) config = WidgetConfig.get(file_path=file_path, view="definition") element_names = config.get_element_names() for element_name in element_names: print "element_name: ", element_name attrs = config.get_element_attributes(element_name) report_data = {} kwargs = config.get_display_options(element_name) class_name = kwargs.get('class_name') report_data['class_name'] = class_name report_data['kwargs'] = kwargs report_data['title'] = attrs.get("title") report_data['description'] = attrs.get("description") reports.append(report_data) """ project = Project.get() project_code = project.get_code() search_type_objs = project.get_search_types() filtered = [] for search_type_obj in search_type_objs: search_type = search_type_obj.get_value("search_type") # FIXME: this code is also present from pyasm.security import get_security_version security_version = get_security_version() if security_version >= 2 and not search_type.startswith( "sthpw/") and not search_type.startswith("config/"): security = Environment.get_security() table = search_type_obj.get_value("table_name") default = "deny" key = {"element": "%s_list" % table} key2 = {"element": "%s_list" % table, "project": project_code} key3 = {"element": "*"} key4 = {"element": "*", "project": project_code} keys = [key, key2, key3, key4] if not security.check_access( "link", keys, "view", default=default): continue key = {"code": search_type} key2 = {"code": "*"} keys = [key, key2] if not security.check_access( "search_type", keys, "view", default=default): continue filtered.append(search_type_obj) search_type_objs = filtered for search_type_sobj in search_type_objs: description = search_type_sobj.get_value("description") search_type = search_type_sobj.get_value("search_type") search = Search(search_type) count = search.get_count() title_div = DivWdg() items_div = DivWdg() title_div.add(items_div) items_div.add_style("font-size: 9px") items_div.add_style("font-weight: italic") items_div.add_style("float: right") items_div.add("%s item/s" % count) title_div.add(search_type_sobj.get_title()) description_div = DivWdg() description_div.add(description) description_div.add_style("padding: 5px") if not description: description_div.add("<br/>(No description)") description_div.add_style("font-style: italic") description_div.add_style("opacity: 0.3") report_data = { 'title': search_type_sobj.get_title(), 'title_wdg': title_div, 'class_name': 'tactic.ui.panel.ViewPanelWdg', 'kwargs': { 'search_type': search_type, 'view': 'table', 'simple_search_view': 'simple_search' }, 'description': description_div, 'search_type': search_type_sobj } reports.append(report_data) # create a bunch of panels list_div = DivWdg() top.add(list_div) list_div.add_class("spt_reports_list") table = Table() list_div.add(table) table.add_color("color", "color") table.add_style("margin-bottom: 5px") table.center() top.add("<br clear='all'/>") for i, report in enumerate(reports): if i == 0 or i % 4 == 0: tr = table.add_row() td = table.add_cell() td.add_style("vertical-align: top") td.add_style("padding: 3px") class_name = report.get("class_name") kwargs = report.get("kwargs") title = report.get("title") description = report.get("description") #image = "<img src='/context/images/getting_started_schema.png'/>" image = "<img src='/context/images/getting_started_pipeline.png'/>" thumb_div = DivWdg() image = thumb_div thumb_div.add_border() thumb_div.set_box_shadow("1px 1px 1px 1px") thumb = ThumbWdg() thumb_div.add(thumb) thumb.set_sobject(report.get("search_type")) thumb.set_icon_size(60) behavior = { 'type': 'click_up', 'title': title, 'class_name': class_name, 'kwargs': kwargs, 'cbjs_action': ''' var top = bvr.src_el.getParent(".spt_reports_top"); //spt.tab.set_main_body_tab(); spt.tab.set_tab_top(top); var kwargs = {}; spt.tab.add_new(bvr.title, bvr.title, bvr.class_name, bvr.kwargs); ''' } title_wdg = report.get("title_wdg") schema_wdg = self.get_section_wdg(title_wdg, description, image, behavior) td.add(schema_wdg) from tactic.ui.container import TabWdg tab = TabWdg(show_add=False) top.add(tab) return top
def get_display(self): top = self.top top.add_style("margin: 10px") search = Search("config/widget_config") search.add_column("view") search.add_filter("category", "CustomLayoutWdg") search.add_filter("view", "pages.%", op="like") sobjects = search.get_sobjects() self.pages = SObject.get_values(sobjects, "view") top.add("<div style='font-size: 16px'>Select page to load</div>") top.add("<hr/>") pages_div = DivWdg() top.add(pages_div) pages_div.add_style("margin: 20px") pages_div.add_relay_behavior({ 'type': 'click', 'bvr_match_class': "spt_user_page_item", 'cbjs_action': ''' var popup = bvr.src_el.getParent(".spt_popup"); var activator = popup.activator; var page = bvr.src_el.getAttribute("spt_page"); var top = activator.getParent(".spt_panel_top"); var content = top.getElement(".spt_panel_content"); var class_name = 'tactic.ui.panel.CustomLayoutWdg'; var kwargs = { view: page, } spt.panel.load(content, class_name, kwargs); spt.popup.close(popup); ''' }) if self.pages: last_parts = self.pages[0].split(".")[:-1] self.pages.sort() last_parts = [] for count, page in enumerate(self.pages): page = page.replace(".", "/") page_div = DivWdg() pages_div.add(page_div) page_div.add_class("spt_user_page_item") page_div.add_style("padding: 3px") page_div.add_class("tactic_hover") page_div.add_attr("spt_page", page) page_div.add_class("hand") page_div.add_style("min-width: 400px") new_parts = [] parts = page.split("/") parts = parts[1:] index = 0 for part in parts: if index < len(last_parts): last_part = last_parts[index] if part == last_part: part = "<i style='opacity: 0.0'>%s</i>" % part index += 1 new_parts.append(part) last_parts = parts #parts = ["<b>%s</b>" % x for x in parts] display_path = " <i style='opacity: 1.0'>/</i> ".join( new_parts) page_div.add( "<div style='margin-right: 10px;display: inline-block; width: 20px; text-align: right'>%s: </div>" % count) page_div.add(display_path) return top
def execute(self): print "kwargs: ", self.kwargs options = {} class_name = "tactic.ui.panel.CustomLayoutWdg" widget_key = "" for key, value in self.kwargs.items(): if value == '': continue if key.startswith("xxx_option"): parts = key.split("|") option_key = parts[1] if option_key == "display_class": class_name = value elif option_key == "widget_key": widget_key = value else: options[option_key] = value elif key.startswith("option|"): parts = key.split("|") option_key = parts[1] options[option_key] = value print "options: ", options name = self.kwargs.get("name") description = self.kwargs.get("description") or " " if not name: raise Exception("No name provided") name = Common.clean_filesystem_name(name) login = Environment.get_user_name() view = "pages.%s.%s" % (login, name) # find if this user page already exists search = Search("config/widget_config") search.add_filter("category", "CustomLayoutWg") search.add_filter("view", view) config = search.get_sobject() if config: raise Exception("Page with name [%s] already exists" % name) option_xml = [] for key, value in options.items(): option_xml.append("<%s>%s</%s>" % (key, value, key)) option_str = "\n".join(option_xml) if widget_key: display_line = '''<display widget="%s">''' % widget_key else: display_line = '''<display class="%s">''' % class_name # all pages are custom layouts config_xml = '''<config> <%s> <html> <div style="margin: 20px"> <div style="font-size: 25px">%s</div> <div>%s</div> <hr/> <element> %s %s </display> </element> </div> </html> </%s> </config> ''' % (view, name, description, display_line, option_str, view) print "config_xml: ", config_xml xml = Xml() xml.read_string(config_xml) config_xml = xml.to_string() config = SearchType.create("config/widget_config") config.set_value("category", "CustomLayoutWdg") config.set_value("view", view) config.set_value("config", config_xml) config.commit()
def get_display(my): query = my.get_option("query") depend_col = my.get_option("dependency") # for example # FIXME: this has to be fleshed out ... it's a little too complicated # at the moment!!! query = "MMS/product_type|id|product_name" depend_col = "discipline_id" depend_element = 'discipline' top = DivWdg() top.add_class("spt_input_top") top.add_attr( "spt_cbjs_get_input_key", "var value=spt.dg_table.get_element_value(cell_to_edit, '%s');return value" % depend_element) top.add_style("background: black") # get all of the sobjects search_type, value_col, label_col = query.split("|") search = Search(search_type) sobjects = search.get_sobjects() # arrange the sobjects according to keys selections = {} for sobject in sobjects: depend_value = sobject.get_value(depend_col) selection_list = selections.get(depend_value) if not selection_list: selection_list = [] selections[depend_value] = selection_list selection_list.append(sobject) # put in a default default_div = DivWdg() default_div.add_class("spt_input_option") default_div.add_attr("spt_input_key", "default") default_div.add("No options for selected [%s]" % depend_element) top.add(default_div) # add list of possible select statements for key, selection_list in selections.items(): div = DivWdg() div.add_class("spt_input_option") div.add_attr("spt_input_key", key) values = [] labels = [] for sobject in selection_list: values.append(sobject.get_value(value_col)) labels.append(sobject.get_value(label_col)) select = SelectWdg(my.get_input_name()) select.add_empty_option('-- Select --') select.set_option("values", values) select.set_option("labels", labels) div.add(select) from tactic.ui.panel import CellEditWdg CellEditWdg.add_edit_behavior(select) top.add(div) return top
def get_display(self): top = self.top top.add_class("spt_panel_layout_top") self.set_as_panel(top) inner = DivWdg() top.add(inner) self.view = self.kwargs.get("view") # Define some views that are pages. Pages are views that are self # contained and do not require arguments. They are often created # by users search = Search("config/widget_config") search.add_column("view") search.add_filter("category", "CustomLayoutWdg") search.add_filter("view", "pages.%", op="like") sobjects = search.get_sobjects() self.pages = SObject.get_values(sobjects, "view") config = None is_test = False if self.view: search = Search("config/widget_config") search.add_filter("category", "PanelLayoutWdg") search.add_filter("view", self.view) config = search.get_sobject() elif is_test: config_xml = ''' <config> <elements> <element name="a"> <display class="tactic.ui.panel.CustomLayoutWdg"> <view>pages.test1</view> </display> </element> <element name="b"> <display class="tactic.ui.panel.StaticTableLayoutWdg"> <search_type>sthpw/login_group</search_type> <element_names>login_group</element_names> <show_shelf>false</show_shelf> </display> </element> <element name="c"> <display class="tactic.ui.panel.CustomLayoutWdg"> <view>test.search</view> </display> </element> <element name="d"> <display class="tactic.ui.panel.StaticTableLayoutWdg"> <search_type>sthpw/login_group</search_type> <element_names>login_group</element_names> <show_shelf>false</show_shelf> </display> </element> </elements> </config> ''' config = WidgetConfig.get(view="elements", xml=config_xml) if not config: config_xml = ''' <config> <elements> </elements> </config> ''' config = WidgetConfig.get(view="elements", xml=config_xml) grid = self.kwargs.get("grid") if not grid: grid = config.get_view_attribute("grid") if grid: if isinstance(grid, basestring): grid = [int(x) for x in grid.split("x")] else: grid = (3, 1) is_owner = True table = DivWdg() inner.add(table) table.add_style("margin: 20px") table.add_style("box-sizing: border-box") if is_owner: menu = self.get_action_menu() #SmartMenu.add_smart_menu_set( top, { 'BUTTON_MENU': menu } ) element_names = config.get_element_names() index = 0 for y in range(grid[1]): row = DivWdg() table.add(row) row.add_class("row") row.add_style("box-sizing: border-box") num_cols = grid[0] size = 12 / num_cols for x in range(grid[0]): col = DivWdg() row.add(col) col.add_class("col-sm-%s" % size) col.add_style("box-sizing: border-box") col.add_style("overflow: auto") col.add_class("spt_panel_top") if is_owner: header = DivWdg() col.add(header) menu_wdg = DivWdg() header.add(menu_wdg) menu_wdg.add_style("float: right") menu_wdg.add("<i class='fa fa-bars'> </i>") menu_wdg.add_class("hand") SmartMenu.add_smart_menu_set(menu_wdg, {'BUTTON_MENU': menu}) SmartMenu.assign_as_local_activator( menu_wdg, "BUTTON_MENU", True) element = None title = None if index < len(element_names): element_name = element_names[index] #element_name = "%s,%s" % (x,y) element = config.get_display_widget(element_name) title = config.get_element_title(element_name) if not title: title = Common.get_display_title(element_name) if not element: element = DivWdg() element.add("No content") element.add_style("height: 100%") element.add_style("width: 100%") element.add_style("text-align: center") element.add_border() else: try: element = element.get_buffer_display() except: element = DivWdg() element.add("No content") element.add_style("height: 100%") element.add_style("width: 100%") element.add_style("text-align: center") element.add_border() if is_owner: if title: header.add(title) else: header.add("Panel: %s,%s" % (x, y)) col.add("<hr/>") content = DivWdg() col.add(content) content.add_class("spt_panel_content") content.add_style("min-height: 200px;") content.add(element) index += 1 if self.kwargs.get("is_refresh"): return inner else: return top
def preprocess(my): '''determine if this is for EditWdg or EDIT ROW of a table''' # get the number of task pipelines needed for EditWdg, which is one # for the EDIT ROW , there could be more than 1 my.task_mapping = None from tactic.ui.panel import EditWdg if hasattr(my, 'parent_wdg') and isinstance(my.get_parent_wdg(), EditWdg): task = my.get_current_sobject() task_pipe_code = task.get_value('pipeline_code') # if the current task has no pipeline, then search for # any task pipeline if not task_pipe_code: # just use the default task_pipe_code = 'task' pipeline = Pipeline.get_by_code(task_pipe_code) if not pipeline: pipeline = Pipeline.get_by_code('task') my.task_pipelines = [pipeline] else: # get all of the pipelines for tasks search = Search('sthpw/pipeline') search.add_regex_filter('search_type', 'sthpw/task') my.task_pipelines = search.get_sobjects() # get all of the pipelines for the current search_type search_type = my.state.get("search_type") search = Search('sthpw/pipeline') if search_type: search.add_filter('search_type', search_type) my.sobject_pipelines = search.get_sobjects() # insert the default task pipeline if not overridden in the db default_task_found = False pipeline_codes = SObject.get_values(my.task_pipelines, 'code') if 'task' in pipeline_codes: default_task_found = True if not default_task_found: default_pipe = Pipeline.get_by_code('task') my.task_pipelines.append(default_pipe) my.task_mapping = {} # the following works for insert but on edit, it should read from pipeline_code attribute for pipeline in my.sobject_pipelines: processes = pipeline.get_process_names() for process in processes: attrs = pipeline.get_process_attrs(process) task_pipeline = attrs.get('task_pipeline') if task_pipeline: key = '%s|%s' % (pipeline.get_code(), process) my.task_mapping[key] = task_pipeline #my.task_mapping = "|".join(my.task_mapping) my.is_preprocess = True
def init(my): search_type = "prod/shot" widget = Widget() search = Search(search_type) div = DivWdg(css="filter_box") filter = SequenceFilterWdg() div.add(filter) #context_filter = ContextFilterWdg(label="Context: ", search_type=) #context_filter.set_search_type(search_type) #div.add(context_filter) context_wdg = TextWdg("context") context_wdg.set_persistence() span = SpanWdg(css="med") span.add("Context: ") span.add(context_wdg) div.add(span) my.context = context_wdg.get_value() if not my.context: my.context = None mode = "latest" filter.alter_search(search) sobjects = search.get_sobjects() widget.add(div) table = Table(css="table") table.add_style("width: 100%") for sobject in sobjects: table.add_row() thumb = ThumbWdg() thumb.set_sobject(sobject) table.add_cell(thumb) table.add_cell( sobject.get_code() ) td = table.add_cell( WikiUtil().convert(sobject.get_value("description") )) td.add_style("width: 300px") if mode == "latest": snapshot = Snapshot.get_latest_by_sobject(sobject, my.context) else: snapshot = Snapshot.get_current_by_sobject(sobject, my.context) if not snapshot: table.add_cell("<i>No snapshot found</i>") continue dependency = DependencyWdg() dependency.set_show_title(False) dependency.set_sobject(snapshot) table.add_cell(dependency) widget.add(table) my.add(widget)
def init(my): thumb_cache = {} div = DivWdg() # get all of the shots filter_div = DivWdg(css='filter_box') unit = 'an Episode' filter = shot_container = None search_columns = [] # pick the navigator depending on what project type if Project.get().get_type() == 'flash': # these navigators will have their empty option removed # and should have a different name so that if the user # comees from a tab with the same navigator, it won't # use the previous empty value if chosen filter = EpisodeFilterWdg('unique_episode_code') # set a default value which is used if there is nothing # stored in wdg_settings filter.set_option('default', SelectWdg.NONE_MODE) episode_code = filter.get_value() episode = Episode.get_by_code(episode_code) shot_container = episode search_columns = ['code', 'description', 'episode_code'] elif Project.get().get_type() == 'prod': filter = SequenceFilterWdg('unique_sequence_code') filter.set_option('default', SelectWdg.NONE_MODE) epi_code, seq_code = filter.get_value() seq = Sequence.get_by_code(seq_code) shot_container = seq unit = 'a Sequence' search_columns = ['code', 'description', 'sequence_code'] # name the empty option properly at least filter.get_navigator().get_select().add_empty_option(\ '-- Select %s --' % unit) #filter.remove_empty_option() #filter.add_none_option() filter_div.add(filter) search_filter = SearchFilterWdg(columns=search_columns) search_filter_value = search_filter.get_value() filter_div.add(search_filter) div.add(filter_div) my.add(div) if not shot_container and not search_filter_value: return search = Search(Shot.SEARCH_TYPE) if shot_container: key = shot_container.get_foreign_key() code = shot_container.get_code() search.add_filter(key,code) if search_filter_value: search_filter.alter_search(search) shots = search.get_sobjects() table = TableWdg(Shot.SEARCH_TYPE, 'layout_summary') table.set_sobjects(shots) my.add(table)
def _execute(self): '''if mode is normal, this runs both the main startup (init) logic plus monitor''' from pyasm.security import Batch Batch(login_code="admin") os.environ["TACTIC_MONITOR"] = "true" if not self.num_processes: self.num_processes = Config.get_value("services", "process_count") if self.num_processes: self.num_processes = int(self.num_processes) else: self.num_processes = 3 start_port = Config.get_value("services", "start_port") ports_str = os.environ.get("TACTIC_PORTS") if not ports_str: ports_str = Config.get_value("services", "ports") if ports_str: ports = ports_str.split("|") ports = [int(x) for x in ports] else: if start_port: start_port = int(start_port) else: start_port = 8081 ports = [] for i in range(0, self.num_processes): ports.append(start_port + i) tactic_threads = [] #start_tactic = Config.get_value("services", "tactic") #start_job_queue = Config.get_value("services", "job_queue") #start_watch_folder = Config.get_value("services", "watch_folder") start_tactic = False start_job_queue = False start_watch_folder = False start_async = False services = Config.get_value("services", "enable") custom_services = [] if services: #services = services.split("|") services = re.split("[|,]", services) for service in services: if service == 'tactic': start_tactic = True elif service == 'job_queue': start_job_queue = True elif service == 'watch_folder': start_watch_folder = True elif service == 'async': start_async = True else: custom_services.append(service) else: start_tactic = True # create a number of processes if start_tactic: self.remove_monitor_pid() #for i in range(0, self.num_processes): for port in ports: # start cherrypy tactic_thread = TacticThread(port) tactic_thread.set_dev(self.dev_mode) tactic_thread.start() tactic_threads.append(tactic_thread) time.sleep(1) #port += 1 # aSync Queue services if start_async: num_processes = Config.get_value("async", "process_count") if not num_processes: num_processes = 1 else: num_processes = int(num_processes) for i in range(0, num_processes): job_thread = ASyncThread() job_thread.start() tactic_threads.append(job_thread) # Job Queue services if start_job_queue: num_processes = Config.get_value("services", "queue_process_count") if not num_processes: num_processes = 1 else: num_processes = int(num_processes) for i in range(0, num_processes): job_thread = JobQueueThread(i) job_thread.start() tactic_threads.append(job_thread) # Watch Folder services if start_watch_folder: search = Search("sthpw/watch_folder") watch_folders = search.get_sobjects() for watch_folder in watch_folders: project_code = watch_folder.get("project_code") base_dir = watch_folder.get("base_dir") search_type = watch_folder.get("search_type") process = watch_folder.get("process") script_path = watch_folder.get("script_path") watch_folder_code = watch_folder.get("code") if not project_code: print("Watch Folder missing project_code ... skipping") continue if not base_dir: print("Watch Folder missing base_dir ... skipping") continue if not search_type: print("Watch Folder missing search_type ... skipping") continue self.watch_folder_cleanup(base_dir) watch_thread = WatchFolderThread( project_code=project_code, base_dir=base_dir, search_type=search_type, process=process, script_path=script_path, watch_folder_code=watch_folder_code) watch_thread.start() tactic_threads.append(watch_thread) # set up custom services for service in custom_services: kwargs = Config.get_section_values(service) custom_thread = CustomPythonProcessThread(**kwargs) custom_thread.start() tactic_threads.append(custom_thread) if len(tactic_threads) == 0: print("\n") print("No services started ...") print("\n") return # create a separate thread for timed processes # DEPRECATED tactic_timed_thread = TacticTimedThread() tactic_timed_thread.start() tactic_threads.append(tactic_timed_thread) # create a separate thread for scheduler processes start_scheduler = Config.get_value("services", "scheduler") if start_scheduler == 'true' or True: tactic_scheduler_thread = TacticSchedulerThread() tactic_scheduler_thread.set_dev(self.dev_mode) tactic_scheduler_thread.start() tactic_threads.append(tactic_scheduler_thread) DbContainer.close_thread_sql() self.tactic_threads = tactic_threads if self.mode == "normal": self.monitor()
def handle_search(self): search_type = self.kwargs.get("search_type") self.search = Search(search_type) self.alter_search(self.search) return self.search
def get_display(my): search = Search(Login) my.set_search_for_options(search, 'login', 'login') if my.kwargs.get('default_user') == 'true': my.set_option('default', Environment.get_user_name()) return super(MultiUserSelectWdg, my).get_display()
def get_count(self, status): search = Search(self.search_type) search.add_filter("project_code", self.project_code) search.add_filter(self.column, status) count = search.get_count() return count
def init(my): search = Search(CommandSObj) search.add_column('notification_code') search.add_group_by('notification_code') my.set_search_for_options(search, 'notification_code', 'notification_code')
def get_display(self): self.search_type = self.kwargs.get("search_type") if not self.search_type: self.search_type = 'sthpw/task' self.column = self.kwargs.get("column") if not self.column: self.column = 'status' self.project_code = self.kwargs.get("project_code") if not self.project_code: self.project_code = Project.get_project_code() self.bar_width = self.kwargs.get("bar_width") if not self.bar_width: self.bar_width = 200 values = self.kwargs.get("values") if values: values = values.split("|") else: pipeline_code = self.kwargs.get("pipeline_code") if pipeline_code: pipeline = Pipeline.get_by_code(pipeline_code) values = pipeline.get_process_names() else: search = Search(self.search_type) search.add_filter("project_code", self.project_code) search.add_column(self.column, distinct=True) xx = search.get_sobjects() values = [x.get_value(self.column) for x in xx] search = Search(self.search_type) search.add_filter("project_code", self.project_code) search.add_filters(self.column, values) total = search.get_count() colors = [ '#900', '#090', '#009', '#990', '#099', '#909', '#900', '#090', '#009', '#990' ] while len(values) > len(colors): colors.extend(colors) top = DivWdg() top.add_color("background", "background") date = "@FORMAT(@STRING($TODAY),'Dec 31, 1999')" date = Search.eval(date, single=True) title = "Tasks Status Chart" title_wdg = DivWdg() top.add(title_wdg) title_wdg.add(title) title_wdg.add(" [%s]" % date) title_wdg.add_style("font-size: 14") title_wdg.add_color("background", "background3") title_wdg.add_color("color", "color3") title_wdg.add_style("padding: 10px") title_wdg.add_style("font-weight: bold") title_wdg.add_style("text-align: center") inner = DivWdg() top.add(inner) inner.center() inner.add_style("width: 500px") inner.add_style("padding: 30px") for i, status in enumerate(values): if not status: continue count = self.get_count(status) div = self.get_div(status, count, total, colors[i]) inner.add(div.get_buffer_display()) inner.add("<br clear='all'/>") inner.add("<hr/>") div = self.get_div("Total", total, total, "gray") inner.add(div.get_buffer_display()) inner.add("<br clear='all'/>") return top
def get_display(self): div = DivWdg() sobject = self.get_sobject_from_kwargs() if not sobject: div.add("SObject not found") return div search_type_obj = sobject.get_search_type_obj() title = search_type_obj.get_title() title_wdg = DivWdg() title_wdg.add_style("font-size: 1.8em") title_wdg.add("%s: %s" % (title, sobject.get_code())) div.add(title_wdg) div.add(HtmlElement.hr()) table = Table() table.set_max_width() col1 = table.add_col() col1.add_style('width: 200px') col2 = table.add_col() col2.add_style('width: 320px') col3 = table.add_col() col3.add_style('width: 400px') table.add_row() from pyasm.widget import ThumbWdg, DiscussionWdg, SObjectTaskTableElement td = table.add_cell() td.add_style("vertical-align: top") td.add_style("border-right: solid 1px") title = DivWdg() title.add_class("maq_search_bar") #x = DivWdg("[?] [x]") #x.add_style("float: right") #title.add(x) title.add("Info") td.add(title) thumb = ThumbWdg() thumb.set_sobject(sobject) thumb.set_option("detail", "false") td.add(thumb) from pyasm.prod.web import AssetInfoWdg info = AssetInfoWdg() info.thumb = thumb info.set_sobject(sobject) td.add(info) # tasks td = table.add_cell() td.add_style("vertical-align: top") td.add_style("padding-left: 5px") td.add_style("border-right: solid 1px") title = DivWdg() title.add_class("maq_search_bar") #x = DivWdg("[x]") #x.add_style("float: right") #title.add(x) title.add("Tasks") td.add(title) task_wdg = SObjectTaskTableElement() task_wdg.set_sobject(sobject) td.add(task_wdg) td.add_style('cell-padding', '10') # discussion td = table.add_cell() #td.add_style("min-width: 300px") #td.add_style("width: 600px") td.add_style("vertical-align: top") td.add_style("padding-left: 5px") td.add_style("border-right: solid 1px") title = DivWdg() title.add_class("maq_search_bar") #x = DivWdg("[x]") #x.add_style("float: right") #title.add(x) title.add("Notes") td.add(title) discussion_wdg = DiscussionWdg() discussion_wdg.preprocess() discussion_wdg.set_sobject(sobject) td.add(discussion_wdg) note_panel = discussion_wdg.get_note_menu() td.add(note_panel) div.add(table) div.add(HtmlElement.hr()) div.add(HtmlElement.br(clear="all")) title_wdg = DivWdg() title_wdg.add_class("maq_search_bar") #x = DivWdg("[x]") #x.add_style("float: right") #title_wdg.add(x) #title_wdg.add_style("font-size: 1.5em") title_wdg.add("Detail") div.add(title_wdg) div.add(HtmlElement.br()) # TEST getting schema search_type = sobject.get_base_search_type() schema = Schema.get_by_sobject(sobject) child_types = schema.get_child_types(search_type) # add a second table table = Table() table.set_max_width() # show the snapshots for this sobject search_type = "sthpw/snapshot" search = Search(search_type) search.add_sobject_filter(sobject) search.set_limit(25) sobjects = search.get_sobjects() table.add_row() nav_td = table.add_cell() nav_td.add_style("width: 100px") nav_td.add_style("vertical-align: top") section_wdg = self.get_section_wdg(sobject) nav_td.add(section_wdg) parent_key = SearchKey.get_by_sobject(sobject) content_wdg = ViewPanelWdg(search_type=search_type, element_name='Snapshots', \ title='Snapshots', view='table', parent_key=parent_key, do_search=True) #content_wdg.set_sobjects(sobjects) content_td = table.add_cell() content_td.set_id("sobject_relation") content_td.add_style("display: table-cell") content_td.add_style("vertical-align: top") content_td.add_style("padding-left: 10px") content_td.add(content_wdg) div.add(table) return div
def init(my): link = my.kwargs.get('link') hash = my.kwargs.get('hash') my.widget = None if link: from tactic.ui.panel import SideBarBookmarkMenuWdg personal = False if '.' in link: personal = True config = SideBarBookmarkMenuWdg.get_config("SideBarWdg", link, personal=personal) options = config.get_display_options(link) # this is vital for view saving element_name = link attr_dict = config.get_element_attributes(link) title = attr_dict.get('title') hash = "/tab/%s" % link config = ''' <config> <application> <element name="left_nav"> <display class="tactic.ui.panel.SideBarPanelWdg"> </display> </element> <element name="main_body"> <display class="tactic.ui.panel.HashPanelWdg"> <hash>%s</hash> <element_name>%s</element_name> <title>%s</title> </display> <web/> </element> </application> </config> ''' % (hash, element_name, title) elif hash: from tactic.ui.panel import HashPanelWdg my.widget = HashPanelWdg.get_widget_from_hash(hash, force_no_index=True) config = None else: security = Environment.get_security() start_link = security.get_start_link() if start_link: my.kwargs['link'] = start_link return my.init() # search for a defined welcome view search = Search("config/widget_config") search.add_filter("category", "top_layout") search.add_filter("view", "welcome") config_sobj = search.get_sobject() if config_sobj: config = config_sobj.get_value("config") else: config = WidgetSettings.get_value_by_key("top_layout") if not config: config = my.get_default_config() my.config_xml = Xml() my.config_xml.read_string(config)
def get_display(self): top = self.top top.add_style("padding: 20px") top.add_color("background", "background") top.add_color("color", "color") top.add_style("width", "500px") top.add_class("spt_db_register_top") self.set_as_panel(top) inner = DivWdg() top.add(inner) # db resource db_resource = self.get_value("db_resource") db_resource_wdg = DivWdg() inner.add(db_resource_wdg) db_resource_wdg.add("Database Resource: ") search = Search("sthpw/db_resource") db_resources = search.get_sobjects() codes = [x.get_code() for x in db_resources] select = SelectWdg("db_resource") db_resource_wdg.add(select) select.set_option("values", codes) if db_resource: select.set_value(db_resource) select.add_behavior({ 'type': 'change', 'cbjs_action': ''' var top = bvr.src_el.getParent(".spt_db_register_top"); spt.panel.refresh(top); ''' }) if db_resource: info_wdg = DivWdg() db_resource_wdg.add(info_wdg) info_wdg.add_border() info_wdg.add_style("padding: 20px") info_wdg.add_style("margin: 20px") inner.add("<br/>") # list of databases database_wdg = DivWdg() inner.add(database_wdg) database_wdg.add("Available Databases: ") databases = ['test', 'test1', 'test2'] select = SelectWdg("databases") database_wdg.add(select) select.set_option("values", databases) # list of projects if self.kwargs.get('is_refresh') == 'true': return inner else: return top
def get_display(my): my.aspect = my.get_option('aspect') if not my.aspect: my.aspect = "width" search_key = my.get_option('search_key') if search_key: sobject = Search.get_by_search_key(search_key) my.set_sobject(sobject) if not my.is_preprocess_run: my.preprocess() # get the set size icon_size = my.get_option("icon_size") if icon_size: my.set_icon_size(icon_size) # get the real size icon_size = my.get_icon_size() min_size = my.get_option("min_icon_size") if not min_size: min_size = 45 sobject = my.get_current_sobject() # get it from the web container if not sobject: web = WebContainer.get_web() search_type = web.get_form_value("search_type") search_code = web.get_form_value("search_code") search_id = web.get_form_value("search_id") icon_size = web.get_form_value("icon_size") if icon_size: my.icon_size = icon_size if search_type and search_code: sobject = Search.get_by_code(search_type, search_code) my.set_sobject(sobject) elif search_type and search_id: sobject = Search.get_by_id(search_type, search_id) my.set_sobject(sobject) else: return my.get_no_icon_wdg() elif sobject.get_id() == -1: div = DivWdg() div.add(" ") div.add_style("text-align: center") return div # if there is a redirect to the sobject (a relation), use that redirect = my.get_option("redirect") redirect_expr = my.get_option("redirect_expr") parser = ExpressionParser() if redirect and sobject: if redirect == "true": # use search_type and search_id pair # FIXME: go up a maximum of 2 .. this is not so stable as # the parent may have a similar relationship for i in range(0,2): if not sobject: return my.get_no_icon_wdg() if sobject.has_value("search_type"): search_type = sobject.get_value("search_type") # if search_type does not exist, just break out if not search_type: break search_code = sobject.get_value("search_code", no_exception=True) if search_code: sobject = Search.get_by_code(search_type, search_code) else: search_id = sobject.get_value("search_id", no_exception=True) sobject = Search.get_by_id(search_type, search_id) if sobject: break elif redirect.count("|") == 2: search_type, col1, col2 = redirect.split("|") search = Search(search_type) search.add_filter(col1, sobject.get_value(col2) ) sobject = search.get_sobject() if not sobject: return my.get_no_icon_wdg() elif redirect_expr and sobject: redirect_sobject = parser.eval(redirect_expr, sobjects=[sobject], single=True) if redirect_sobject: sobject = redirect_sobject else: return my.get_no_icon_wdg() # get the icon context from the sobject icon_context = my.get_option("icon_context") if not icon_context: icon_context = sobject.get_icon_context(my.context) # try to get an icon first if isinstance(sobject, Snapshot): snapshot = sobject # check if the sobject actually exists try: snapshot.get_sobject() except SObjectNotFoundException, e: return IconWdg('sobject n/a for snapshot code[%s]' %snapshot.get_code(), icon=IconWdg.ERROR) except SearchException, e: return IconWdg('parent for snapshot [%s] not found' %snapshot.get_code(), icon=IconWdg.ERROR)
def execute(my): assert my.db_resource assert my.table database = my.db_resource.get_database() from pyasm.search import Insert, Select, DbContainer, Search, Sql # get the data if not my.sobjects: search = Search("sthpw/search_object") # BAD assumption #search.add_filter("table", my.table) # create a search_type. This is bad assumption cuz it assumes project-specific search_type # should call set_search_type() if not my.search_type: my.search_type = "%s/%s" % (my.database, my.table) search.add_filter("search_type", my.search_type) my.search_type_obj = search.get_sobject() if not my.search_type_obj: if my.no_exception == False: raise SqlException( "Table [%s] does not have a corresponding search_type" % my.table) else: return search_type = my.search_type_obj.get_base_key() search = Search(my.search_type) search.set_show_retired(True) my.sobjects = search.get_sobjects() # get the info for the table column_info = SearchType.get_column_info(my.search_type) for sobject in my.sobjects: print my.delimiter insert = Insert() insert.set_database(my.database) insert.set_table(my.table) data = sobject.data for name, value in data.items(): if name in my.ignore_columns: continue if not my.include_id and name == "id": insert.set_value("id", '"%s_id_seq".nextval' % table, quoted=False) #insert.set_value(name, value, quoted=False) elif value == None: continue else: # replace all of the \ with double \\ insert.set_value(name, value) print "%s" % insert.get_statement() print my.end_delimiter print
def run(self): import time time.sleep(6) #print("Starting Timed Trigger") # checks are done every 60 seconds chunk = 60 # FIXME: not sure why we have to do a batch here from pyasm.security import Batch Batch(login_code="admin") # get the all of the timed triggers #search = Search("sthpw/timed_trigger") #search.add_filter("type", "timed") search = Search("sthpw/trigger") search.add_filter("event", "timed") timed_trigger_sobjs = search.get_sobjects() timed_triggers = [] for trigger_sobj in timed_trigger_sobjs: trigger_class = trigger_sobj.get_value("class_name") try: timed_trigger = Common.create_from_class_path(trigger_class) except ImportError: raise Exception("WARNING: [%s] does not exist" % trigger_class) timed_triggers.append(timed_trigger) while 1: time.sleep(chunk) #print("Running timer") date = Date() #print("utc: ", date.get_display_time()) # go through each trigger for timed_trigger in timed_triggers: if not timed_trigger.is_ready(): continue if timed_trigger.is_in_separate_thread(): class xxx(threading.Thread): def run(self): try: Batch() timed_trigger._do_execute() finally: DbContainer.close_thread_sql() xxx().start() else: timed_trigger._do_execute() DbContainer.close_thread_sql() if self.end: #print("Stopping timed thread") break
def execute_mms_oracle_dump(my): assert my.db_resource assert my.table database = my.db_resource.get_database() if not my.sql_out_fp or not my.pl_sql_var_out_fp or not my.pl_sql_ins_out_fp: raise Exception( "SQL and PL-SQL file pointers are required for generating output." ) from pyasm.search import Insert, Select, DbContainer, Search, Sql # get the data if not my.sobjects: search = Search("sthpw/search_object") search.add_filter("table_name", my.table) my.search_type_obj = search.get_sobject() if not my.search_type_obj: if my.no_exception == False: raise Exception( "Table [%s] does not have a corresponding search_type" % my.table) else: return search_type = my.search_type_obj.get_base_key() search = Search(search_type) search.set_show_retired(True) my.sobjects = search.get_sobjects() # get the info for the table column_info = my.search_type_obj.get_column_info() for sobject in my.sobjects: column_list = [] value_list = [] update_col_list = [] update_map = {} timestamp_regex = re.compile( "^(\d{4})-(\d{2})-(\d{2}) (\d{2}):(\d{2}):(\d{2})") data = sobject.data sobject_id = data.get("id") do_pl_sql = False for name, value in data.items(): if value == None: continue else: col_name = '"%s"' % name column_list.append(col_name) if isinstance(value, types.StringTypes): if timestamp_regex.match(value): value_list.append( "TO_TIMESTAMP('%s','RR-MM-DD HH24:MI:SS')" % str(value).split('.')[0][2:]) else: new_value = my.get_oracle_friendly_string_value( value) if len(new_value) > 3800: #{ do_pl_sql = True var_name = "%s_%s_%s__var" % \ ( my.table, col_name.replace('"',''), str(sobject_id).zfill(5) ) my.pl_sql_var_out_fp.write( "\n%s VARCHAR2(%s) := %s ;\n" % (var_name, len(new_value), new_value)) new_value = var_name #} value_list.append(new_value) # elif type(value) == datetime.datetime: # value_list.append( "TO_TIMESTAMP('%s','RR-MM-DD HH24:MI:SS.FF')" % # str(value).split('.')[0][2:] ) else: value_list.append("%s" % value) if do_pl_sql: my.pl_sql_ins_out_fp.write('\n') from sql import Sql if database_type == "SQLServer": my.pl_sql_ins_out_fp.write( 'INSERT INTO "%s" (%s) VALUES (%s);\n' % (my.database, my.table, ','.join(column_list), ','.join(value_list))) else: my.pl_sql_ins_out_fp.write( 'INSERT INTO "%s" (%s) VALUES (%s);\n' % (my.table, ','.join(column_list), ','.join(value_list))) else: my.sql_out_fp.write('\n') from sql import Sql if database_type == "SQLServer": my.sql_out_fp.write( 'INSERT INTO "%s" (%s) VALUES (%s);\n' % (my.database, my.table, ','.join(column_list), ','.join(value_list))) else: my.sql_out_fp.write( 'INSERT INTO "%s" (%s) VALUES (%s);\n' % (my.table, ','.join(column_list), ','.join(value_list)))
def run(self): import time time.sleep(3) #print("Starting Scheduler ....") # NOTE: not sure why we have to do a batch here from pyasm.security import Batch Batch(login_code="admin") timed_triggers = [] from pyasm.biz import Project search = Search("sthpw/project") # only requires the admin project search.add_filter('code', 'sthpw', op='!=') projects = search.get_sobjects() # get the all of the timed triggers #search = Search("sthpw/timed_trigger") #search.add_filter("type", "timed") timed_trigger_sobjs = [] for project in projects: project_code = project.get_code() try: search = Search("config/trigger?project=%s" % project_code) search.add_filter("event", "schedule") items = search.get_sobjects() if items: timed_trigger_sobjs.extend(items) except Exception as e: #print("WARNING: ", e) continue # example """ if project_code == 'broadcast2': tt = SearchType.create("config/trigger") tt.set_value("class_name", "tactic.command.PythonTrigger") # data = timed_trigges.get("data") tt.set_value("data", '''{ "type": "interval", "interval": 5, "delay": 5, "mode": "threaded", "script_path": "trigger/scheduled" } ''') timed_trigger_sobjs.append(tt) """ has_triggers = False for trigger_sobj in timed_trigger_sobjs: trigger_class = trigger_sobj.get_value("class_name") if not trigger_class and trigger_sobj.get_value("script_path"): trigger_class = 'tactic.command.PythonTrigger' data = trigger_sobj.get_json_value("data") data['project_code'] = trigger_sobj.get_project_code() try: timed_trigger = Common.create_from_class_path( trigger_class, [], data) timed_trigger.set_input(data) has_triggers = True except ImportError: raise Exception("WARNING: [%s] does not exist" % trigger_class) timed_triggers.append(timed_trigger) if has_triggers and self.dev_mode: print("Found [%s] scheduled triggers in project [%s]..." % (len(timed_triggers), project_code)) from tactic.command import Scheduler, SchedulerTask scheduler = Scheduler.get() scheduler.start_thread() class TimedTask(SchedulerTask): def __init__(self, **kwargs): super(TimedTask, self).__init__(**kwargs) self.index = kwargs.get("index") self.project_code = kwargs.get("project_code") def execute(self): try: #Batch() #Command.execute_cmd(timed_trigger) Project.set_project(self.project_code) timed_triggers[self.index].execute() except Exception as e: raise finally: DbContainer.close_thread_sql() DbContainer.commit_thread_sql() DbContainer.close_all() for idx, timed_trigger in enumerate(timed_triggers): data = timed_trigger.get_input() if not data: continue """ data = { 'type': 'interval', 'interval': 10, 'delay': 0, 'mode': 'threaded' } """ project_code = data.get("project_code") task = TimedTask(index=idx, project_code=project_code) args = {} if data.get("mode"): args['mode'] = data.get("mode") trigger_type = data.get("type") if trigger_type == 'interval': interval = data.get("interval") delay = data.get("delay") if not interval: continue if not delay: delay = 3 args = { 'interval': interval, 'delay': delay, } scheduler.add_interval_task(task, **args) elif trigger_type == "daily": from dateutil import parser args['time'] = parser.parse(data.get("time")) if data.get("weekdays"): args['weekdays'] = eval(data.get("weekdays")) scheduler.add_daily_task(task, **args) #scheduler.add_daily_task(task, time, mode="threaded", weekdays=range(1,7)) elif trigger_type == "weekly": #scheduler.add_weekly_task(task, weekday, time, mode='threaded'): args['time'] = parser.parse(data.get("time")) if data.get("weekday"): args['weekday'] = eval(data.get("weekday")) scheduler.add_weekly_task(task, **args)
def add_xml_rules(my, xml, project_code=None): '''xml should be an XML object with the data in the form of <rules> <group type='sobject' default='<default>'> <rule key='<key>' access='<access>'/> </group> </rules> ''' from pyasm.search import SObject if isinstance(xml, SObject): sobject = xml xml = sobject.get_xml_value("access_rules") if not project_code: project_code = sobject.get_value("project_code") project_override = project_code if isinstance(xml, basestring): xmlx = Xml() xmlx.read_string(xml) xml = xmlx my.xml = xml # parse shorthand rules rule_nodes = xml.get_nodes("rules/rule") if not rule_nodes: return # store all of the project codes (this will only run once) if my.project_codes == None: search = Search('sthpw/project') projects = search.get_sobjects() my.project_codes = [x.get_code() for x in projects] my.project_codes.append('*') for rule_node in rule_nodes: # initiate the project_code here for each loop project_code = '*' group_type = Xml.get_attribute(rule_node, "group") if not group_type: # category is the preferred name over group now # TODO: phase out the use of group completely group_type = Xml.get_attribute(rule_node, "category") # get an existing rule set or create a new one if my.groups.has_key(group_type): rules = my.groups[group_type] else: rules = {} my.groups[group_type] = rules # set the default, if specified group_default = xml.get_attribute(rule_node, "default") if group_default: rules['__DEFAULT__'] = group_default continue # generate the rule key #rule_key = xml.get_attribute(rule_node, 'key') attrs = xml.get_attributes(rule_node) attrs2 = {} count = 0 for name, value in attrs.items(): if name in ['access', 'group', 'category', 'project']: continue # have to turn everything into strings attrs2[str(name)] = str(value) count += 1 if count == 1 and attrs2.has_key('key'): # backwards compatibility rule_key = attrs2['key'] else: #rule_key = str(attrs2) rule_key = str(Common.get_dict_list(attrs2)) if project_override: rule_project = project_override else: rule_project = xml.get_attribute(rule_node, 'project') if rule_project: project_code = rule_project # special treatment for search_filter to enable # project-specific search if group_type == 'search_filter': attrs2['project'] = rule_project # if there is a value, then combine it with the key rule_value = xml.get_attribute(rule_node, 'value') if rule_value: rule_key = "%s||%s" % (rule_key, rule_value) # add a project code qualifier rule_keys = [] # project rule is special if group_type == 'project': key = str(rule_key) rule_keys.append(key) elif project_code == '*' and group_type != 'search_filter': for code in my.project_codes: key = "%s?project=%s" % (rule_key, code) rule_keys.append(key) else: key = "%s?project=%s" % (rule_key, project_code) #key = str(key) # may need to stringify unicode string rule_keys.append(key) #key= "%s?project=*" % (rule_key) #rule_keys.append(key) rule_access = xml.get_attribute(rule_node, 'access') #if rule_access == "": # raise AccessException("Cannot have empty 'access':\n%s" \ # % xml.to_string(rule_node) ) # if no key is specified, it is considered a DEFAULT if not rule_keys and not rule_value: rule_keys = ['__DEFAULT__'] for rule_key in rule_keys: # check if rule_access exists first, which doesn't for search_filter, # but it has to go into the rules regardless # if the rule already exists, take the highest one if rule_access and rules.has_key(rule_key): curr_access, cur_attrs = rules[rule_key] try: access_enum = my._get_access_enum(rule_access) if my._get_access_enum(curr_access) > access_enum: continue except: if group_type == "builtin": continue else: raise rules[rule_key] = rule_access, attrs2 # FIXME: this one doesn't support the multi-attr structure # convert this to a python data structure group_nodes = xml.get_nodes("rules/group") for group_node in group_nodes: group_type = Xml.get_attribute(group_node, "type") # get an existing rule set or create a new one if my.groups.has_key(group_type): rules = my.groups[group_type] else: rules = {} my.groups[group_type] = rules # set the default, if specified group_default = xml.get_attribute(group_node, "default") if group_default != "": rules['__DEFAULT__'] = group_default # get all of the rule nodes rule_nodes = Xml.get_children(group_node) for rule_node in rule_nodes: project_code = '*' if Xml.get_node_name(rule_node) != 'rule': continue rule_key = xml.get_attribute(rule_node, 'key') rule_access = xml.get_attribute(rule_node, 'access') if project_override: rule_project = project_override else: rule_project = xml.get_attribute(rule_node, 'project') if rule_project: project_code = rule_project if rule_access == "": raise AccessException("Cannot have empty 'access':\n%s" \ % xml.to_string(rule_node) ) rule_keys = [] attrs2 = {'key': rule_key} # add a project code qualifier if project_code == '*' and group_type != 'search_filter': for code in my.project_codes: key = "%s?project=%s" % (rule_key, code) rule_keys.append(key) else: key = "%s?project=%s" % (rule_key, project_code) rule_keys.append(key) for rule_key in rule_keys: rules[rule_key] = rule_access, attrs2
def get_pipeline(self, pipeline_xml, add_tasks=False): pipeline = SearchType.create("sthpw/pipeline") pipeline.set_pipeline(pipeline_xml) pipeline_id = random.randint(0, 10000000) #pipeline.set_value("code", "test%s" % pipeline_id) #pipeline.set_id(pipeline_id) #pipeline.set_value("id", pipeline_id) pipeline.set_value("pipeline", pipeline_xml) pipeline.commit() process_names = pipeline.get_process_names() # delete the processes search = Search("config/process") search.add_filters("process", process_names) processes = search.get_sobjects() for process in processes: process.delete() # create new processes processes_dict = {} for process_name in process_names: # define the process nodes process = SearchType.create("config/process") process.set_value("process", process_name) process.set_value("pipeline_code", pipeline.get_code()) process.set_json_value( "workflow", { 'on_pending': ''' sobject.set_value('%s', "pending") ''' % process_name, 'on_complete': ''' sobject.set_value('%s', "complete") ''' % process_name, 'on_approved': ''' sobject.set_value('%s', "approved") ''' % process_name, 'on_revise': ''' sobject.set_value('%s', "revise") ''' % process_name, 'on_reject': ''' sobject.set_value('%s', "reject") ''' % process_name, 'on_custom': ''' sobject.set_value('%s', input.get("status")) ''' % process_name, }) process.commit() processes_dict[process_name] = process # Note: we don't have an sobject yet if add_tasks: task = SaerchType.create("sthpw/task") task.set_parent(sobject) task.set_value("process", process_name) task.commit() return pipeline, processes_dict