def get_display(my): #project = Project.get() schema = Schema.get() # no hierarchy to prevent all sthpw and parent sTypes search_type_names = schema.get_search_types(hierarchy=False) search = Search('sthpw/search_object') search.add_filters('search_type', search_type_names) search_types = search.get_sobjects() task_search_type = SearchType.get("sthpw/task") search_types.append(task_search_type) values = [x.get_value("search_type") for x in search_types] labels = [] for x in search_types: label = "%s (%s)" % (x.get_value("title"), x.get_value("search_type")) labels.append(label) sobject = my.get_current_sobject() if not sobject: value = "" else: value = sobject.get_value(my.get_name()) my.set_option("values", values) my.set_option("labels", labels) my.add_empty_option("-- Select --") if value: my.set_value(value) return super(SearchTypeInputWdg, my).get_display()
def get_display(self): #project = Project.get() schema = Schema.get() # no hierarchy to prevent all sthpw and parent sTypes search_type_names = schema.get_search_types(hierarchy=False) search = Search('sthpw/search_object') search.add_filters('search_type', search_type_names) search_types = search.get_sobjects() task_search_type = SearchType.get("sthpw/task") search_types.append(task_search_type) values = [ x.get_value("search_type") for x in search_types] labels = [] for x in search_types: label = "%s (%s)" % (x.get_value("title"), x.get_value("search_type")) labels.append(label) sobject = self.get_current_sobject() if not sobject: value = "" else: value = sobject.get_value(self.get_name() ) self.set_option("values", values) self.set_option("labels", labels) self.add_empty_option("-- Select --") if value: self.set_value(value) return super(SearchTypeInputWdg, self).get_display()
def get_related_types(my, search_type): # find all the relationships schema = Schema.get() related_types = schema.get_related_search_types(search_type) parent_type = schema.get_parent_type(search_type) child_types = schema.get_child_types(search_type) # some special considerations # FIXME: this needs to be more automatic. Should only be # deletable children (however, that will be defined) if search_type in ['sthpw/task', 'sthpw/note', 'sthpw/snapshot']: if "sthpw/project" in related_types: related_types.remove("sthpw/project") if "sthpw/login" in related_types: related_types.remove("sthpw/login") if "config/process" in related_types: related_types.remove("config/process") if parent_type in related_types: related_types.remove(parent_type) related_types.append('sthpw/note') related_types.append('sthpw/task') related_types.append('sthpw/snapshot') related_types.append('sthpw/work_hour') related_types.append('sthpw/pipeline') related_types.append('sthpw/sobject_list') return related_types
def get_related_types(self, search_type): # find all the relationships schema = Schema.get() related_types = schema.get_related_search_types(search_type) parent_type = schema.get_parent_type(search_type) child_types = schema.get_child_types(search_type) # some special considerations # FIXME: this needs to be more automatic. Should only be # deletable children (however, that will be defined) if search_type in ['sthpw/task','sthpw/note', 'sthpw/snapshot']: if "sthpw/project" in related_types: related_types.remove("sthpw/project") if "sthpw/login" in related_types: related_types.remove("sthpw/login") if "config/process" in related_types: related_types.remove("config/process") if parent_type in related_types: related_types.remove(parent_type) related_types.append('sthpw/note') related_types.append('sthpw/task') related_types.append('sthpw/snapshot') related_types.append('sthpw/work_hour') related_types.append('sthpw/pipeline') related_types.append('sthpw/sobject_list') return related_types
def get_hier_sel(my, search_type): sel = SelectWdg(my.RELATED_SEARCH_TYPE, label='Related Search Type: ') sel.add_empty_option() schema = Schema.get() search_type_list = [search_type] if schema: parent_search_type = schema.get_parent_type(search_type) if parent_search_type: search_type_list.append(parent_search_type) child_types = schema.get_child_types(search_type) search_type_list.extend(child_types) sel.set_option('values', search_type_list) sel.set_value(my.related_search_type) return sel
def get_hier_sel(self, search_type): sel = SelectWdg(self.RELATED_SEARCH_TYPE, label='Related Search Type: ') sel.add_empty_option() schema = Schema.get() search_type_list = [search_type] if schema: parent_search_type = schema.get_parent_type(search_type) if parent_search_type: search_type_list.append(parent_search_type) child_types = schema.get_child_types(search_type) search_type_list.extend(child_types) sel.set_option('values', search_type_list) sel.set_value(self.related_search_type) return sel
def init(my): my.schema = Schema.get() if not my.schema: my.parent_type = None my.select = None return web = WebContainer.get_web() my.search_type = web.get_form_value("filter|search_type") if not my.search_type: search_type = my.options.get("search_type") my.parent_type = my.schema.get_parent_type(my.search_type) if not my.parent_type: my.select = None else: my.select = FilterSelectWdg("filter|%s" % my.parent_type)
def init(self): self.schema = Schema.get() if not self.schema: self.parent_type = None self.select = None return web = WebContainer.get_web() self.search_type = web.get_form_value("filter|search_type") if not self.search_type: search_type = self.options.get("search_type") self.parent_type = self.schema.get_parent_type(self.search_type) if not self.parent_type: self.select = None else: self.select = FilterSelectWdg("filter|%s" % self.parent_type)
def _test_relationship(my): search_type = "table/posts?project=mongodb" search_type2 = "table/posts2?project=mongodb" from pyasm.biz import Schema schema = Schema.get() relationship = schema.get_relationship(search_type, search_type2) my.assertEquals(None, relationship) search_type2 = "sthpw/task" relationship = schema.get_relationship(search_type, search_type2) my.assertEquals("search_id", relationship) attrs = schema.get_relationship_attrs(search_type, search_type2) my.assertEquals("*", attrs.get("to")) my.assertEquals("search_type", attrs.get("relationship"))
def _test_relationship(my): search_type = "table/posts?project=mongodb" search_type2 = "table/posts2?project=mongodb" from pyasm.biz import Schema schema = Schema.get() relationship = schema.get_relationship(search_type, search_type2) my.assertEquals(None, relationship) search_type2 = "sthpw/task" relationship = schema.get_relationship(search_type, search_type2) my.assertEquals("search_id", relationship) attrs = schema.get_relationship_attrs(search_type, search_type2) my.assertEquals("*", attrs.get("to") ) my.assertEquals("search_type", attrs.get("relationship") )
def get_display(my): #project = Project.get() schema = Schema.get() # no hierarchy to prevent all sthpw and parent sTypes search_type_names = schema.get_search_types(hierarchy=False) search = Search('sthpw/search_object') search.add_filters('search_type', search_type_names) search_types = search.get_sobjects() task_search_type = SearchType.get("sthpw/task") search_types.append(task_search_type) values = [ x.get_value("search_type") for x in search_types] filtered = [] labels = [] for x in search_types: base_type = x.get_base_key() exists = SearchType.column_exists(base_type, "pipeline_code") if not exists: continue label = "%s (%s)" % (x.get_value("title"), x.get_value("search_type")) labels.append(label) filtered.append(base_type) values = filtered sobject = my.get_current_sobject() if not sobject: value = "" else: value = sobject.get_value(my.get_name() ) my.set_option("values", values) my.set_option("labels", labels) my.add_empty_option("-- Select --") if value: my.set_value(value) return super(SearchTypeWithPipelineInputWdg, my).get_display()
def get_display(self): #project = Project.get() schema = Schema.get() # no hierarchy to prevent all sthpw and parent sTypes search_type_names = schema.get_search_types(hierarchy=False) search = Search('sthpw/search_object') search.add_filters('search_type', search_type_names) search_types = search.get_sobjects() task_search_type = SearchType.get("sthpw/task") search_types.append(task_search_type) values = [x.get_value("search_type") for x in search_types] filtered = [] labels = [] for x in search_types: base_type = x.get_base_key() exists = SearchType.column_exists(base_type, "pipeline_code") if not exists: continue label = "%s (%s)" % (x.get_value("title"), x.get_value("search_type")) labels.append(label) filtered.append(base_type) values = filtered sobject = self.get_current_sobject() if not sobject: value = "" else: value = sobject.get_value(self.get_name()) self.set_option("values", values) self.set_option("labels", labels) self.add_empty_option("-- Select --") if value: self.set_value(value) return super(SearchTypeWithPipelineInputWdg, self).get_display()
def execute(my): # if a single sobject is passed in sobject = my.kwargs.get("sobject") if not sobject: search_key = my.kwargs.get("search_key") sobject = Search.get_by_search_key(search_key) if sobject: sobjects = [sobject] else: search_keys = my.kwargs.get("search_keys") sobjects = Search.get_by_search_keys(search_keys) if not sobjects: return # find all the relationships my.schema = Schema.get() for sobject in sobjects: my.delete_sobject(sobject)
def execute(self): # if a single sobject is passed in sobject = self.kwargs.get("sobject") if not sobject: search_key = self.kwargs.get("search_key") sobject = Search.get_by_search_key(search_key) if sobject: sobjects = [sobject] else: search_keys = self.kwargs.get("search_keys") sobjects = Search.get_by_search_keys(search_keys) if not sobjects: return # find all the relationships self.schema = Schema.get() for sobject in sobjects: self.delete_sobject(sobject)
def import_manifest(my, nodes): paths_read = [] for node in nodes: node_name = my.xml.get_node_name(node) if node_name == 'search_type': search_type = my.xml.get_attribute(node, 'code') # implicitly add the entry to the schema table. # Reset the cache every time to ensure that any updates to # the scehma are reflected here. schema = Schema.get(reset_cache=True) xml = schema.get_xml() schema_node = xml.get_node("schema/search_type[@name='%s']" % search_type) parent = xml.get_node("schema") if schema_node == None: schema_node = xml.create_element("search_type") xml.set_attribute(schema_node, "name", search_type) #parent = xml.get_parent(node) xml.append_child(parent, schema_node) schema.set_value('schema', xml.to_string() ) schema.commit() # TODO: connections? path = my.xml.get_attribute(node, "path") if not path: path = "%s.spt" % search_type.replace("/", "_") path = "%s/%s" % (my.plugin_dir, path) if path in paths_read: continue if my.verbose: print "Reading search_type: ", path # NOTE: priviledged knowledge of the order or return values jobs = my.import_data(path, commit=True) paths_read.append(path) if not jobs: continue search_type_obj = jobs[0] if len(jobs) == 1: # only the search type was defined table = None else: table = jobs[1] try: # check to see if the search type already exists search_type_chk = SearchType.get(search_type) if search_type_chk: if my.verbose: print 'WARNING: Search Type [%s] is already registered' % search_type_chk.get_value("search_type") else: search_type_obj.commit() except SearchException, e: if e.__str__().find('not registered') != -1: search_type_obj.commit() # check if table exists has_table = False if has_table: if my.verbose: print 'WARNING: Table [%s] already exists' elif table: #print table.get_statement() if table: database = table.get_database() table_name = table.get_table() TableUndo.log(search_type, database, table_name) elif node_name == 'sobject': path = my.xml.get_attribute(node, "path") search_type = my.xml.get_attribute(node, "search_type") seq_max = my.xml.get_attribute(node, "seq_max") try: if seq_max: seq_max = int(seq_max) except ValueError: seq_max = 0 if not path: if search_type: path = "%s.spt" % search_type.replace("/","_") if not path: raise TacticException("No path specified") path = "%s/%s" % (my.plugin_dir, path) if path in paths_read: continue unique = my.xml.get_attribute(node, "unique") if unique == 'true': unique = True else: unique = False if my.verbose: print "Reading: ", path # jobs doesn't matter for sobject node jobs = my.import_data(path, unique=unique) # compare sequence st_obj = SearchType.get(search_type) SearchType.sequence_nextval(search_type) cur_seq_id = SearchType.sequence_currval(search_type) sql = DbContainer.get("sthpw") if seq_max > 0 and seq_max > cur_seq_id: # TODO: SQL Server - Reseed the sequences instead of passing. if sql.get_database_type() == 'SQLServer': pass else: SearchType.sequence_setval(search_type, seq_max) else: cur_seq_id -= 1 # TODO: SQL Server - Reseed the sequences instead of passing. if sql.get_database_type() == 'SQLServer': pass else: # this is a db requirement if cur_seq_id > 0: SearchType.sequence_setval(search_type, cur_seq_id) paths_read.append(path)
class PluginUninstaller(PluginBase): # NOTE: this is still a work in progress. It will remove entries added # by the plugin, but it is not clear that this is what we want to do. def execute(my): # uninstall the plugin nodes = my.xml.get_nodes("manifest/*") nodes.reverse() my.handle_nodes(nodes) my.add_description('Remove plugin [%s]' %my.code) def handle_nodes(my, nodes): for node in nodes: node_name = my.xml.get_node_name(node) if node_name == 'search_type': my.remove_search_type(node) elif node_name == 'sobject': my.remove_sobjects(node) elif node_name == 'include': my.handle_include(node) elif node_name == 'python': my.handle_python(node) # remove plugin contents search = Search("config/plugin_content") search.add_filter("plugin_code", my.code) plugin_contents = search.get_sobjects() for plugin_content in plugin_contents: plugin_content.delete() # deregister the plugin plugin = Search.eval("@SOBJECT(config/plugin['code','%s'])" % my.code, single=True) if plugin: plugin.delete() def remove_search_type(my, node): search_type = my.xml.get_attribute(node, 'code') # get sobject entry search = Search("sthpw/search_object") search.add_filter("search_type", search_type) search_type_sobj = search.get_sobject() if not search_type_sobj: print "WARNING: Search type [%s] does not exist" % search_type else: # dump the table first ??? # get the table and remove it ??? from pyasm.search import DropTable try: table_drop = DropTable(search_type) table_drop.commit() # NOTE: do we need to log the undo for this? except Exception, e: print "Error: ", e.message # NOTE: it is not clear that unloading a plugin should delete # the search type ... this search type (at present) can be # shared amongst multiple projects and this will break it return # remove entry from schema schema = Schema.get() xml = schema.get_xml() node = xml.get_node("schema/search_type[@name='%s']" % search_type) if node != None: parent = xml.get_parent(node) xml.remove_child(parent, node) schema.set_value('schema', xml.to_string() ) schema.commit() # remove search type entry if search_type.startswith("config/") or search_type.startswith("sthpw/"): print "WARNING: A plugin cannot deregister a search type from the 'sthpw' or 'config' namespace'" else: search = Search("sthpw/search_object") search.add_filter("search_type", search_type) search_type_sobj = search.get_sobject() if search_type_sobj: search_type_sobj.delete()
def get_display(my): top = my.top my.set_as_panel(top) top.add_class("spt_delete_top") top.add_color("background", "background") top.add_color("color", "color") top.add_border() top.add_style("width: 300px") top.add_border() search_key = my.kwargs.get("search_key") search_keys = my.kwargs.get("search_keys") if search_key: sobject = Search.get_by_search_key(search_key) sobjects = [sobject] search_keys = [search_key] elif search_keys: sobjects = Search.get_by_search_keys(search_keys) sobject = sobjects[0] if not sobjects: msg = "%s not found" %search_key return msg search_type = sobject.get_base_search_type() if search_type in ['sthpw/project', 'sthpw/search_object']: msg = 'You cannot delete these items with this tool' return msg my.search_keys = search_keys title = DivWdg() top.add(title) title.add_color("background", "background", -10) if my.search_keys: title.add("Delete %s Items" % len(my.search_keys)) else: title.add("Delete Item [%s]" % (sobject.get_code())) title.add_style("font-size: 14px") title.add_style("font-weight: bold") title.add_style("padding: 10px") content = DivWdg() top.add(content) content.add_style("padding: 10px") content.add("The item to be deleted has a number of dependencies as described below:<br/>", 'heading') # find all the relationships schema = Schema.get() related_types = schema.get_related_search_types(search_type, direction="children") parent_type = schema.get_parent_type(search_type) child_types = schema.get_child_types(search_type) # some special considerations # FIXME: this needs to be more automatic. Should only be # deletable children (however, that will be defined) if search_type in ['sthpw/task','sthpw/note', 'sthpw/snapshot']: if "sthpw/project" in related_types: related_types.remove("sthpw/project") if "sthpw/login" in related_types: related_types.remove("sthpw/login") if "config/process" in related_types: related_types.remove("config/process") if parent_type in related_types: related_types.remove(parent_type) related_types.append('sthpw/note') related_types.append('sthpw/task') related_types.append('sthpw/snapshot') if 'sthpw/work_hour' not in related_types: related_types.append('sthpw/work_hour') items_div = DivWdg() content.add( items_div ) items_div.add_style("padding: 10px") valid_related_ctr = 0 for related_type in related_types: if related_type == "*": print "WARNING: related_type is *" continue if related_type == search_type: continue if related_type in ['sthpw/search_object','sthpw/search_type']: continue item_div = my.get_item_div(sobjects, related_type) if item_div: items_div.add(item_div) valid_related_ctr += 1 if valid_related_ctr > 0: icon = IconWdg("WARNING", IconWdg.WARNING) icon.add_style("float: left") content.add( icon ) content.add("<div><b>WARNING: By selecting the related items above, you can delete them as well when deleting this sObject.</b></div>") content.add("<br/>"*2) else: # changed the heading to say no dependencies content.add("The item to be deleted has no dependencies.<br/>", 'heading') content.add("There are %s items to be deleted" % len(my.search_keys)) content.add("<br/>"*2) content.add("Do you wish to continue deleting?") content.add("<br/>"*2) button_div = DivWdg() button_div.add_styles('width: 300px; height: 50px') button = ActionButtonWdg(title="Delete") button_div.add(button) content.add(button_div) button.add_style("float: left") button.add_behavior( { 'type': 'click_up', 'search_keys': my.search_keys, 'cbjs_action': ''' spt.app_busy.show("Deleting"); var top = bvr.src_el.getParent(".spt_delete_top"); var values = spt.api.Utility.get_input_values(top); var class_name = "tactic.ui.tools.DeleteCmd"; var kwargs = { 'search_keys': bvr.search_keys, 'values': values }; var server = TacticServerStub.get(); try { server.start({'title': 'Delete sObject', 'description': 'Delete sObject [' + bvr.search_keys + ']'}); server.execute_cmd(class_name, kwargs); server.finish(); // run the post delete and destroy the popup var popup = bvr.src_el.getParent(".spt_popup"); if (popup.spt_on_post_delete) { popup.spt_on_post_delete(); } spt.popup.destroy(popup); } catch(e) { spt.alert(spt.exception.handler(e)); } spt.app_busy.hide(); ''' } ) button = ActionButtonWdg(title="Cancel") button.add_style("float: left") button_div.add(button) button.add_behavior( { 'type': 'click_up', 'cbjs_action': ''' var top = bvr.src_el.getParent(".spt_popup"); top.destroy(); ''' } ) content.add("<br clear='all'/>") return top
def get_by_sobjects(sobjects, process=None, order=True): if not sobjects: return [] # quickly go through the sobjects to determine if their search types # are the same multi_stypes = False for sobject in sobjects: if sobject.get_search_type() != sobjects[0].get_search_type(): multi_stypes = True break search = Search( Task.SEARCH_TYPE ) if multi_stypes: # sort this into a dictionary and make multiple calls to # search.add_relationship_filters # use the first sobject as a sample sobjects_dict = {} for sobject in sobjects: st = sobject.get_search_type() sobj_list = sobjects_dict.get(st) if sobj_list == None: sobjects_dict[st] = [sobject] else: sobj_list.append(sobject) search.add_op('begin') for key, sobj_list in sobjects_dict.items(): search.add_op('begin') search.add_relationship_filters(sobj_list) search.add_op('and') search.add_op('or') else: from pyasm.biz import Schema schema = Schema.get() # FIXME: why doesn't the ops work here? filters = [] search.add_relationship_filters(sobjects) """ for sobject in sobjects: search_type = sobject.get_search_type() attrs = schema.get_relationship_attrs("sthpw/task", search_type) attrs = schema.resolve_relationship_attrs(attrs, "sthpw/task", search_type) search_code = sobject.get_value(attrs.get("to_col")) #search_code = sobject.get_value("code") #search.add_filter('search_type', search_type) #search.add_filter('search_id', search_id, quoted=False) #search.add_op("and") if attrs.get("from_col") == "search_code": filters.append("search_type = '%s' and search_code = '%s'" % (search_type, search_code)) else: filters.append("search_type = '%s' and search_id = %s" % (search_type, search_code)) search.add_where(" or ".join(filters)) """ search.add_order_by("search_type") search.add_order_by("search_code") search.add_order_by("search_id") # get the pipeline of the sobject pipeline = Pipeline.get_by_sobject(sobject) if order: if pipeline: process_names = pipeline.get_process_names(True) search.add_enum_order_by("process", process_names) else: search.add_order_by("process") search.add_order_by("id") if process: if isinstance(process, basestring): search.add_filter("process", process) else: search.add_filters("process", process) tasks = search.get_sobjects() return tasks
def init(my): my.is_refresh = my.kwargs.get("refresh") my.search_key = my.kwargs.get("search_key") my.ticket_key = my.kwargs.get("ticket") my.parent_key = my.kwargs.get("parent_key") my.expression = my.kwargs.get("expression") # This assumed parent can cause errors as it tries to find a # relationship between to stypes that don't exist ... or worse, # try to bind them when one stype does not have the sufficent columns # ie: pipeline_code #if not my.parent_key: # project = Project.get() # my.parent_key = project.get_search_key() my.code = my.kwargs.get("code") sobject = None if my.search_key: sobject = Search.get_by_search_key(my.search_key) my.search_id = sobject.get_id() my.search_type = sobject.get_base_search_type() if sobject.is_insert(): my.mode = 'insert' else: my.mode = 'edit' elif my.expression: sobject = Search.eval(my.expression, single=True) my.search_id = sobject.get_id() my.search_type = sobject.get_base_search_type() my.mode = 'edit' elif my.ticket_key: from pyasm.security import Ticket, Login ticket = Ticket.get_by_valid_key(my.ticket_key) if not ticket: raise TacticException("No valid ticket") login_code = ticket.get_value("login") login = Login.get_by_code(login_code) my.search_type = "sthpw/login" my.search_id = login.get_id() my.mode = 'edit' elif my.code: my.search_type = my.kwargs.get("search_type") search = Search(my.search_type) search.add_filter("code", my.code) sobject = search.get_sobject() my.search_id = sobject.get_id() my.search_type = sobject.get_base_search_type() my.mode = 'edit' else: my.search_type = my.kwargs.get("search_type") my.search_id = my.kwargs.get("search_id") if not my.search_id: my.search_id = -1 my.search_id = int(my.search_id) if my.search_id != -1: my.mode = "edit" else: my.mode = "insert" # explicit override if my.kwargs.get("mode"): my.mode = my.kwargs.get("mode") my.view = my.kwargs.get("view") if not my.view: my.view = my.kwargs.get("config_base") if not my.view: my.view = "edit" default_data = my.kwargs.get('default') if not default_data: default_data = {} elif isinstance(default_data, basestring): try: default_data = jsonloads(default_data) except: #may be it's regular dictionary try: default_data = eval(default_data) except: print "Warning: Cannot evaluate [%s]" % default_data default_data = {} if sobject: my.set_sobjects([sobject], None) else: my.do_search() # TODO: get_config() is going the right direction (less features) but the more complicated method is biased # towards edit and insert view.. and so it needs improvement as well if my.view not in ["insert", "edit"]: # try a new smaller way to get config only when an explicit view # is set my.config = my.get_config() else: my.config = WidgetConfigView.get_by_search_type(my.search_type, my.view, use_cache=False) # for inline config definitions config_xml = my.kwargs.get("config_xml") if config_xml: #from pyasm.common import Xml #xml = Xml() #xml.read_string(config_xml) #node = xml.get_node("config/%s" % my.view) #xml.set_attribute(node, "class", "tactic.ui.panel.EditWdg") #config = WidgetConfig.get(view=my.view, xml=xml) config_xml = config_xml.replace("&", "&") config = WidgetConfig.get(view="tab", xml=config_xml) my.config.insert_config(0, config) my.skipped_element_names = [] # if there is a layout view, then find the element names using that layout_view = my.kwargs.get("layout_view") if layout_view: layout_view = layout_view.replace("/", ".") search = Search("config/widget_config") search.add_filter("view", layout_view) layout_config = search.get_sobject() xml = layout_config.get_xml_value("config") my.element_names = xml.get_values("config//html//element/@name") else: my.element_names = my.config.get_element_names() override_element_names = my.kwargs.get("element_names") if override_element_names: element_names = override_element_names ignore = my.kwargs.get("ignore") if isinstance(ignore, basestring): ignore = ignore.split("|") if not ignore: ignore = [] my.element_titles = [] my.element_descriptions = [] for element_name in my.element_names: my.element_titles.append(my.config.get_element_title(element_name)) my.element_descriptions.append( my.config.get_element_description(element_name)) #my.element_titles = my.config.get_element_titles() #my.element_descriptions = my.config.get_element_descriptions() # MongoDb # Default columns if not my.element_names: impl = SearchType.get_database_impl_by_search_type(my.search_type) if impl.get_database_type() == "MongoDb": my.element_names = impl.get_default_columns() my.element_titles = ['Code', 'Name', 'Description'] my.element_descriptions = ['Code', 'Name', 'Description'] my.input_prefix = my.kwargs.get('input_prefix') if not my.input_prefix: my.input_prefix = 'edit' security = Environment.get_security() default_access = "edit" project_code = Project.get_project_code() if my.parent_key: from pyasm.biz import Schema schema = Schema.get() parent_stype = SearchKey.extract_base_search_type(my.parent_key) relationship = schema.get_relationship_attrs(parent_stype, my.search_type, type="hierarchy") for element_name in my.element_names: # If parent_key is available, data associated with the parent table does not need # to be specified by the user, and their widgets can be excluded from the edit widget if element_name == relationship.get("from_col"): ignore.append(element_name) for i, element_name in enumerate(my.element_names): if element_name in ignore: my.skipped_element_names.append(element_name) continue # check security access access_key2 = { 'search_type': my.search_type, 'project': project_code } access_key1 = { 'search_type': my.search_type, 'key': element_name, 'project': project_code } access_keys = [access_key1, access_key2] is_editable = security.check_access('element', access_keys, "edit", default=default_access) if not is_editable: my.skipped_element_names.append(element_name) continue widget = my.config.get_display_widget(element_name, kbd_handler=False) # some element could be disabled due to its data_type e.g. sql_timestamp if not widget: my.skipped_element_names.append(element_name) continue widget.set_sobject(my.sobjects[0]) default_value = default_data.get(element_name) if default_value: widget.set_value(default_value) attrs = my.config.get_element_attributes(element_name) editable = widget.is_editable() if editable: editable = attrs.get("edit") editable = editable != "false" if not editable: my.skipped_element_names.append(element_name) continue # set parent widget.set_parent_wdg(my) # set parent_key in insert mode for now if my.mode == 'insert' and my.parent_key: widget.set_option('parent_key', my.parent_key) title = my.element_titles[i] if title: widget.set_title(title) my.widgets.append(widget) description = my.element_descriptions[i] widget.add_attr("title", description)
def get_display(my): sobject = my.get_current_sobject() sobj_name = sobject.get_name() search_type = sobject.get_search_type_obj() stype_title = search_type.get_title() from pyasm.biz import Schema schema = Schema.get() related_types = schema.get_related_search_types( search_type.get_base_key()) related_types = ",".join(related_types) name = my.get_name() top = DivWdg() top.add_attr("spt_related_types", related_types) top.add_style("min-width: 250px") if sobject.is_insert(): top.add_style("opacity: 0.3") else: # this gives the swap it's behaviors, so will be disabled # on insert top.add_class("spt_hidden_row_%s" % name) my.set_option("label", "{}%s" % (sobj_name)) label = my.get_option("label") if label: label = Search.eval(label, sobject) else: label = None if not label: label = sobject.get_code() icon = my.get_option("icon") icon = "DETAILS" #from pyasm.widget import ThumbWdg #thumb_div = DivWdg() #thumb = ThumbWdg() #thumb_div.add(thumb) #thumb.set_sobject(search_type) #thumb.set_option("icon_size", "16") #thumb_div.add_style("float: left") #thumb_div.add_style("width: 22px") title = DivWdg() #title.add(thumb_div) title.add(label) stype_div = SpanWdg(" (%s)" % stype_title) title.add(stype_div) stype_div.add_style("opacity: 0.3") stype_div.add_style("font-syle: italic") stype_div.add_style("font-size: 9px") #swap = SwapDisplayWdg(title=label, icon=icon) swap = SwapDisplayWdg(title=title, icon=icon) swap.set_behavior_top(my.layout) swap.add_style("float: left") swap.add_class("spt_level_listen") top.add(swap) return top
def get_display(my): sobject = my.get_current_sobject() sobj_name = sobject.get_name() search_type = sobject.get_search_type_obj() stype_title = search_type.get_title() from pyasm.biz import Schema schema = Schema.get() related_types = schema.get_related_search_types(search_type.get_base_key()) related_types = ",".join(related_types) name = my.get_name() top = DivWdg() top.add_attr("spt_related_types", related_types) top.add_style("min-width: 250px") if sobject.is_insert(): top.add_style("opacity: 0.3") else: # this gives the swap it's behaviors, so will be disabled # on insert top.add_class("spt_hidden_row_%s" % name) my.set_option("label", "{}%s" % (sobj_name)) label = my.get_option("label") if label: label = Search.eval(label, sobject) else: label = None if not label: label = sobject.get_code() icon = my.get_option("icon") icon = "DETAILS" #from pyasm.widget import ThumbWdg #thumb_div = DivWdg() #thumb = ThumbWdg() #thumb_div.add(thumb) #thumb.set_sobject(search_type) #thumb.set_option("icon_size", "16") #thumb_div.add_style("float: left") #thumb_div.add_style("width: 22px") title = DivWdg() #title.add(thumb_div) title.add(label) stype_div = SpanWdg(" (%s)" % stype_title) title.add(stype_div) stype_div.add_style("opacity: 0.3") stype_div.add_style("font-syle: italic") stype_div.add_style("font-size: 9px") #swap = SwapDisplayWdg(title=label, icon=icon) swap = SwapDisplayWdg(title=title, icon=icon) swap.set_behavior_top(my.layout) swap.add_style("float: left") swap.add_class("spt_level_listen") top.add(swap) return top
def import_manifest(my, nodes): paths_read = [] for node in nodes: node_name = my.xml.get_node_name(node) if node_name == 'search_type': search_type = my.xml.get_attribute(node, 'code') # implicitly add the entry to the schema table. # Reset the cache every time to ensure that any updates to # the scehma are reflected here. schema = Schema.get(reset_cache=True) xml = schema.get_xml() schema_node = xml.get_node("schema/search_type[@name='%s']" % search_type) parent = xml.get_node("schema") if schema_node == None: schema_node = xml.create_element("search_type") xml.set_attribute(schema_node, "name", search_type) #parent = xml.get_parent(node) xml.append_child(parent, schema_node) schema.set_value('schema', xml.to_string() ) schema.commit() # TODO: connections? path = my.xml.get_attribute(node, "path") if not path: path = "%s.spt" % search_type.replace("/", "_") path = "%s/%s" % (my.plugin_dir, path) if path in paths_read: continue if my.verbose: print "Reading search_type: ", path # NOTE: priviledged knowledge of the order or return values jobs = my.import_data(path, commit=True) paths_read.append(path) if not jobs: continue search_type_obj = jobs[0] if len(jobs) == 1: # only the search type was defined table = None else: table = jobs[1] try: # check to see if the search type already exists search_type_chk = SearchType.get(search_type) if search_type_chk: if my.verbose: print 'WARNING: Search Type [%s] is already registered' % search_type_chk.get_value("search_type") else: search_type_obj.commit() except SearchException, e: if e.__str__().find('not registered') != -1: search_type_obj.commit() # check if table exists has_table = False if has_table: if my.verbose: print 'WARNING: Table [%s] already exists' elif table: #print table.get_statement() if table: database = table.get_database() table_name = table.get_table() TableUndo.log(search_type, database, table_name) elif node_name == 'sobject': path = my.xml.get_attribute(node, "path") search_type = my.xml.get_attribute(node, "search_type") seq_max = my.xml.get_attribute(node, "seq_max") try: if seq_max: seq_max = int(seq_max) except ValueError: seq_max = 0 if not path: if search_type: path = "%s.spt" % search_type.replace("/","_") if not path: raise TacticException("No path specified") path = "%s/%s" % (my.plugin_dir, path) if path in paths_read: continue unique = my.xml.get_attribute(node, "unique") if unique == 'true': unique = True else: unique = False if my.verbose: print "Reading: ", path # jobs doesn't matter for sobject node jobs = my.import_data(path, unique=unique) # reset it in case it needs to execute a PYTHON tag right after Schema.get(reset_cache=True) # compare sequence st_obj = SearchType.get(search_type) SearchType.sequence_nextval(search_type) cur_seq_id = SearchType.sequence_currval(search_type) sql = DbContainer.get("sthpw") if seq_max > 0 and seq_max > cur_seq_id: # TODO: SQL Server - Reseed the sequences instead of passing. if sql.get_database_type() == 'SQLServer': pass else: SearchType.sequence_setval(search_type, seq_max) else: cur_seq_id -= 1 # TODO: SQL Server - Reseed the sequences instead of passing. if sql.get_database_type() == 'SQLServer': pass else: # this is a db requirement if cur_seq_id > 0: SearchType.sequence_setval(search_type, cur_seq_id) paths_read.append(path)
def init(my): my.is_refresh = my.kwargs.get("refresh") my.search_key = my.kwargs.get("search_key") my.ticket_key = my.kwargs.get("ticket") my.parent_key = my.kwargs.get("parent_key") my.expression = my.kwargs.get("expression") # This assumed parent can cause errors as it tries to find a # relationship between to stypes that don't exist ... or worse, # try to bind them when one stype does not have the sufficent columns # ie: pipeline_code #if not my.parent_key: # project = Project.get() # my.parent_key = project.get_search_key() my.code = my.kwargs.get("code") sobject = None if my.search_key: sobject = Search.get_by_search_key(my.search_key) my.search_id = sobject.get_id() my.search_type = sobject.get_base_search_type() if sobject.is_insert(): my.mode = 'insert' else: my.mode = 'edit' elif my.expression: sobject = Search.eval(my.expression, single=True) my.search_id = sobject.get_id() my.search_type = sobject.get_base_search_type() my.mode = 'edit' elif my.ticket_key: from pyasm.security import Ticket, Login ticket = Ticket.get_by_valid_key(my.ticket_key) if not ticket: raise TacticException("No valid ticket") login_code = ticket.get_value("login") login = Login.get_by_code(login_code) my.search_type = "sthpw/login" my.search_id = login.get_id() my.mode = 'edit' elif my.code: my.search_type = my.kwargs.get("search_type") search = Search(my.search_type) search.add_filter("code", my.code) sobject = search.get_sobject() my.search_id = sobject.get_id() my.search_type = sobject.get_base_search_type() my.mode = 'edit' else: my.search_type = my.kwargs.get("search_type") my.search_id = my.kwargs.get("search_id") if not my.search_id: my.search_id = -1 my.search_id = int(my.search_id) if my.search_id != -1: my.mode = "edit" else: my.mode = "insert" # explicit override if my.kwargs.get("mode"): my.mode = my.kwargs.get("mode") my.view = my.kwargs.get("view") if not my.view: my.view = my.kwargs.get("config_base") if not my.view: my.view = "edit" default_data = my.kwargs.get('default') if not default_data: default_data = {} elif isinstance(default_data, basestring): try: default_data = jsonloads(default_data) except: #may be it's regular dictionary try: default_data = eval(default_data) except: print "Warning: Cannot evaluate [%s]" %default_data default_data = {} if sobject: my.set_sobjects([sobject], None) else: my.do_search() # TODO: get_config() is going the right direction (less features) but the more complicated method is biased # towards edit and insert view.. and so it needs improvement as well if my.view not in ["insert", "edit"]: # try a new smaller way to get config only when an explicit view # is set my.config = my.get_config() else: my.config = WidgetConfigView.get_by_search_type(my.search_type, my.view, use_cache=False) # for inline config definitions config_xml = my.kwargs.get("config_xml") if config_xml: #from pyasm.common import Xml #xml = Xml() #xml.read_string(config_xml) #node = xml.get_node("config/%s" % my.view) #xml.set_attribute(node, "class", "tactic.ui.panel.EditWdg") #config = WidgetConfig.get(view=my.view, xml=xml) config_xml = config_xml.replace("&", "&") config = WidgetConfig.get(view="tab", xml=config_xml) my.config.insert_config(0, config) my.skipped_element_names = [] # if there is a layout view, then find the element names using that layout_view = my.kwargs.get("layout_view") if layout_view: layout_view = layout_view.replace("/", ".") search = Search("config/widget_config") search.add_filter("view", layout_view) layout_config = search.get_sobject() xml = layout_config.get_xml_value("config") my.element_names = xml.get_values("config//html//element/@name") else: my.element_names = my.config.get_element_names() override_element_names = my.kwargs.get("element_names") if override_element_names: element_names = override_element_names ignore = my.kwargs.get("ignore") if isinstance(ignore, basestring): ignore = ignore.split("|") if not ignore: ignore = [] my.element_titles = [] my.element_descriptions = [] for element_name in my.element_names: my.element_titles.append( my.config.get_element_title(element_name) ) my.element_descriptions.append( my.config.get_element_description(element_name) ) #my.element_titles = my.config.get_element_titles() #my.element_descriptions = my.config.get_element_descriptions() # MongoDb # Default columns if not my.element_names: impl = SearchType.get_database_impl_by_search_type(my.search_type) if impl.get_database_type() == "MongoDb": my.element_names = impl.get_default_columns() my.element_titles = ['Code', 'Name', 'Description'] my.element_descriptions = ['Code', 'Name', 'Description'] my.input_prefix = my.kwargs.get('input_prefix') if not my.input_prefix: my.input_prefix = 'edit' security = Environment.get_security() default_access = "edit" project_code = Project.get_project_code() if my.parent_key: from pyasm.biz import Schema schema = Schema.get() parent_stype = SearchKey.extract_base_search_type(my.parent_key) relationship = schema.get_relationship_attrs(parent_stype, my.search_type, type="hierarchy") for element_name in my.element_names: # If parent_key is available, data associated with the parent table does not need # to be specified by the user, and their widgets can be excluded from the edit widget if element_name == relationship.get("from_col"): ignore.append(element_name) for i, element_name in enumerate(my.element_names): if element_name in ignore: my.skipped_element_names.append(element_name) continue # check security access access_key2 = { 'search_type': my.search_type, 'project': project_code } access_key1 = { 'search_type': my.search_type, 'key': element_name, 'project': project_code } access_keys = [access_key1, access_key2] is_editable = security.check_access('element', access_keys, "edit", default=default_access) if not is_editable: my.skipped_element_names.append(element_name) continue widget = my.config.get_display_widget(element_name, kbd_handler=False) # some element could be disabled due to its data_type e.g. sql_timestamp if not widget: my.skipped_element_names.append(element_name) continue widget.set_sobject(my.sobjects[0]) default_value = default_data.get(element_name) if default_value: widget.set_value(default_value) attrs = my.config.get_element_attributes(element_name) editable = widget.is_editable() if editable: editable = attrs.get("edit") editable = editable != "false" if not editable: my.skipped_element_names.append(element_name) continue # set parent widget.set_parent_wdg(my) # set parent_key in insert mode for now if my.mode =='insert' and my.parent_key: widget.set_option('parent_key', my.parent_key) title = my.element_titles[i] if title: widget.set_title(title) my.widgets.append(widget) description = my.element_descriptions[i] widget.add_attr("title", description)