def check(my): if my.mode == 'export_matched': from tactic.ui.panel import TableLayoutWdg table = TableLayoutWdg(search_type=my.search_type, view=my.view,\ show_search_limit='false', search_limit=-1, search_view=my.search_view,\ search_class=my.search_class, simple_search_view=my.simple_search_view, init_load_num=-1) table.handle_search() search_objs = table.sobjects my.selected_search_keys = SearchKey.get_by_sobjects(search_objs, use_id=True) return True for sk in my.input_search_keys: st = SearchKey.extract_search_type(sk) if st not in my.search_type_list: my.search_type_list.append(st) id = SearchKey.extract_id(sk) if id == '-1': continue my.selected_search_keys.append(sk) if len(my.search_type_list) > 1: my.check_passed = False my.error_msg = 'More than 1 search type is selected. Please keep the selection to one type only.' return False if not my.search_type_list and my.mode == 'export_selected': my.check_passed = False my.error_msg = 'Search type cannot be identified. Please select a valid item.' return False return True
def execute(self): self.search_key_list = self.kwargs.get('search_key_list') web = WebContainer.get_web() skip_duplicated = web.get_form_value('skip_duplicated') == 'on' pipeline_mode = web.get_form_value('pipeline_mode') sobjects = SearchKey.get_by_search_keys(self.search_key_list) count = 0 offset = 0 for sobject in sobjects: if isinstance(sobject, Task): raise TacticException('Creation of task for [Task] is not allowed') sk = SearchKey.get_by_sobject(sobject) if not sobject.has_value('pipeline_code'): #raise TacticException('Creation of task is not allowed for item with no pipeline_code attribute.') pipeline_code = '__default__' sobject.set_value("pipeline_code", pipeline_code) else: pipeline_code = sobject.get_value('pipeline_code') input_name = '%s|task_process'% pipeline_code contexts = [] process_names = web.get_form_values(input_name) process_names = [name for name in process_names if name] if pipeline_mode == 'context': # when pipeline_mode is context, we only specify contexts # in add_initial_tasks contexts = process_names[:] process_names = [] tasks = Task.add_initial_tasks(sobject, sobject.get_value('pipeline_code'), processes=process_names, contexts=contexts, skip_duplicate=skip_duplicated, mode=pipeline_mode, start_offset=offset) count += len(tasks) offset += 5 self.add_description("%s Tasks added in total." % count)
def execute(my): my.search_key_list = my.kwargs.get('search_key_list') web = WebContainer.get_web() skip_duplicated = web.get_form_value('skip_duplicated') == 'on' pipeline_mode = web.get_form_value('pipeline_mode') sobjects = SearchKey.get_by_search_keys(my.search_key_list) count = 0 offset = 0 for sobject in sobjects: if isinstance(sobject, Task): raise TacticException('Creation of task for [Task] is not allowed') sk = SearchKey.get_by_sobject(sobject) if not sobject.has_value('pipeline_code'): #raise TacticException('Creation of task is not allowed for item with no pipeline_code attribute.') pipeline_code = '__default__' sobject.set_value("pipeline_code", pipeline_code) else: pipeline_code = sobject.get_value('pipeline_code') input_name = '%s|task_process'% pipeline_code contexts = [] process_names = web.get_form_values(input_name) process_names = [name for name in process_names if name] if pipeline_mode == 'context': # when pipeline_mode is context, we only specify contexts # in add_initial_tasks contexts = process_names[:] process_names = [] tasks = Task.add_initial_tasks(sobject, sobject.get_value('pipeline_code'), processes=process_names, contexts=contexts, skip_duplicate=skip_duplicated, mode=pipeline_mode, start_offset=offset) count += len(tasks) offset += 5 my.add_description("%s Tasks added in total." % count)
def check(my): if my.mode == 'export_matched': from tactic.ui.panel import TableLayoutWdg my.table = TableLayoutWdg(search_type=my.search_type, view=my.view,\ show_search_limit='false', search_limit=-1, search_view=my.search_view,\ search_class=my.search_class, simple_search_view=my.simple_search_view, init_load_num=-1) my.table.handle_search() search_objs = my.table.sobjects my.selected_search_keys = SearchKey.get_by_sobjects(search_objs, use_id=True) return True for sk in my.input_search_keys: st = SearchKey.extract_search_type(sk) if st not in my.search_type_list: my.search_type_list.append(st) id = SearchKey.extract_id(sk) if id == '-1': continue my.selected_search_keys.append(sk) if len(my.search_type_list) > 1: my.check_passed = False my.error_msg = 'More than 1 search type is selected. Please keep the selection to one type only.' return False if not my.search_type_list and my.mode == 'export_selected': my.check_passed = False my.error_msg = 'Search type cannot be identified. Please select a valid item.' return False return True
def get_display(my): my.context = '' sobject = my.get_current_sobject() if sobject.get_base_search_type() in ['sthpw/task', 'sthpw/note']: my.process = sobject.get_value('process') my.context = sobject.get_value('context') if not my.process: my.process = '' sobject_mode = my.kwargs.get("sobject_mode") if not sobject_mode: sobject_mode = "parent" #sobject_mode = "connect" if sobject_mode == "parent": parent = sobject.get_parent() elif sobject_mode == "connect": parent = Search.eval("@SOBJECT(connect)", sobject, single=True) elif sobject_mode == "expression": expression = "???" parent = Search.eval("@SOBJECT(connect)", sobject, single=True) else: parent = sobject if not parent: return DivWdg() search_key = SearchKey.get_by_sobject(parent) else: my.process = my.get_option('process') if not my.process: my.process = "publish" search_key = SearchKey.get_by_sobject(sobject) #my.behavior['process'] = my.process #my.behavior['context'] = my.context #my.behavior['search_key'] = search_key # set the atrs div = super(CheckinButtonElementWdg, my).get_display() div.add_attr("spt_process", my.process) div.add_attr("spt_context", my.context) div.add_attr("spt_search_key", search_key) return div
def add_header(my, table, title): table.add_style('width', '50em') parent_st = my.kwargs.get('parent_search_type') parent_sid = my.kwargs.get('parent_search_id') parent_context = '' parent_version = '' sobj = Search.get_by_id(parent_st, parent_sid) sobj_code = 'New' sobj_title = '' if sobj: sobj_code = sobj.get_code() sobj_title = sobj.get_search_type_obj().get_title() if isinstance(sobj, Snapshot): parent_context = sobj.get_context() parent_version = sobj.get_version() th = table.add_header("Add Submission for %s [%s]" % (sobj_title, sobj_code)) th.set_attr("colspan", "2") hidden = HiddenWdg('parent_search_type', parent_st) th.add(hidden) hidden = HiddenWdg('parent_search_id', parent_sid) th.add(hidden) hidden = HiddenWdg('parent_context', parent_context) th.add(hidden) hidden = HiddenWdg('parent_version', parent_version) th.add(hidden) if sobj: hidden = HiddenWdg('parent_search_key', SearchKey.get_by_sobject(sobj)) th.add(hidden)
def get_section_wdg(self, sobject): parent_key = SearchKey.get_by_sobject(sobject) section_id = "wow" title = "" view = "children" target_id = "sobject_relation" kwargs = { 'section_id': section_id, 'title': title, 'view': view, 'target_id': target_id, 'width': '125', 'parent_key': parent_key } section_div = DivWdg() section_div.add_style("display: block") section_div.set_id(section_id) section_div.set_attr('spt_class_name', "tactic.ui.panel.ChildrenBookmarkMenuWdg") for name, value in kwargs.items(): if name == "config": continue section_div.set_attr("spt_%s" % name, value) section_wdg = SObjectChildrenMenuWdg(**kwargs) section_div.add(section_wdg) return section_div
def handle_td(my, td): sobj = my.get_current_sobject() parent = None value = sobj.get_value("process") td.add_attr("spt_input_value", value) if sobj.is_insert(): state = my.get_state() parent_key = state.get("parent_key") if parent_key: parent = SearchKey.get_by_search_key(parent_key) else: # get the parent pipeline code try: parent = sobj.get_parent() except SObjectSecurityException, e: print "SObjectSecurityException raised for getting parent of [%s]" % sobj.get_code() pass except SearchException, e: if e.__str__().find("not registered") != -1: pass elif e.__str__().find("does not exist for database") != -1: pass else: raise
def postprocess(self): web = WebContainer.get_web() value = web.get_form_value( self.get_input_name() ) if not value: return # get all fo the sobjects from the search keys instance_type = self.get_option("instance_type") # path is used for self-relating in an instance table src_path = self.get_option("path") #src_sobject = self.sobject search = Search(self.sobject.get_search_type()) search.add_id_filter(self.sobject.get_id()) src_sobject = search.get_sobject() # this is passed in from EditCmd in insert mode parent_key = self.get_option('parent_key') # in some rare cases we have project as the parent_key if parent_key and self.is_insert and 'sthpw/project' not in parent_key: # this is the parent dst_sobject = SearchKey.get_by_search_key(parent_key) # add all the new sobjects #instances = dst_sobject.get_related_sobject(instance_type) instance = SearchType.create(instance_type) instance.add_related_connection(src_sobject, dst_sobject, src_path=src_path) instance.commit()
def add_sobject_to_cache(my, sobject): '''add an sobject to the cache. This is useful if a new sobject has been inserted and it is too expensive to have to recache the entire table just for this one entry''' # make sure this sobject's search type is the same as the search type # for this cache search_type = sobject.get_base_search_type() assert search_type == my.search_type # FIXME: add to all of the caches for key, cache in my.caches.items(): if key == 'search_key': # add to the search_key cache search_key = SearchKey.get_by_sobject(sobject) cache[search_key] = sobject elif key == 'code': # add to the code cache code = sobject.get_code() cache[code] = sobject else: value = sobject.get_value(key) cache[value] = sobject # make sure this cache is set to dirty so other processes update my.make_dirty()
def get_display(my): div = DivWdg() sobject = my.get_current_sobject() search_key = SearchKey.get_by_sobject(sobject) if sobject.is_admin(): return "ADMIN" icon = IconButtonWdg("Global Permissions", IconWdg.EDIT) icon.add_behavior( { "type": "click_up", "cbjs_action": "spt.popup.get_widget(evt, bvr)", "options": { "class_name": "tactic.ui.panel.SecurityManagerWdg", "title": "Permisssion Manager", "popup_id": "Permission Manager" }, "args": { "search_key": search_key } } ) div.add(icon) return div
def get_action_html(my): search_key = SearchKey.get_by_sobject(my.sobjects[0]) behavior_submit = { 'type': 'click_up', 'cb_fire_named_event': 'append_pressed', 'element_names': my.element_names, 'search_key': search_key, 'input_prefix': my.input_prefix } behavior_cancel = { 'type': 'click_up', 'cb_fire_named_event': 'preclose_edit_popup', 'cbjs_postaction': "spt.popup.destroy( spt.popup.get_popup( $('edit_popup') ) );" } button_list = [{'label': "%s/Close" % my.mode.capitalize(), 'bvr': behavior_submit}, {'label': "Cancel", 'bvr': behavior_cancel}] edit_close = TextBtnSetWdg( buttons=button_list, spacing =6, size='large', \ align='center',side_padding=10) div = DivWdg() div.add_styles('height: 35px; margin-top: 10px;') div.center() div.add(edit_close) return div
def init_cache(my): '''initialize the cache''' my.mtime = datetime.datetime.now() keys = my.caches.keys() my.caches = {} search = Search(my.search_type) search.set_show_retired(True) my.sobjects = search.get_sobjects() # build a search_key cache search_key_cache = {} search_keys = SearchKey.get_by_sobjects(my.sobjects) for search_key, sobject in zip(search_keys, my.sobjects): search_key_cache[search_key] = sobject my.caches['search_key'] = search_key_cache code_cache = {} for sobject in my.sobjects: code = sobject.get_code() code_cache[code] = sobject my.caches['code'] = code_cache for key in keys: if key in ['search_key', 'code']: continue my.build_cache_by_column(key)
def add_sobject_to_cache(self, sobject): '''add an sobject to the cache. This is useful if a new sobject has been inserted and it is too expensive to have to recache the entire table just for this one entry''' # make sure this sobject's search type is the same as the search type # for this cache search_type = sobject.get_base_search_type() assert search_type == self.search_type # FIXME: add to all of the caches for key, cache in self.caches.items(): if key == 'search_key': # add to the search_key cache search_key = SearchKey.get_by_sobject(sobject) cache[search_key] = sobject elif key == 'code': # add to the code cache code = sobject.get_code() cache[code] = sobject else: value = sobject.get_value(key) cache[value] = sobject # make sure this cache is set to dirty so other processes update self.make_dirty()
def init_cache(self): '''initialize the cache''' self.mtime = datetime.datetime.now() keys = self.caches.keys() self.caches = {} search = Search(self.search_type) search.set_show_retired(True) self.sobjects = search.get_sobjects() # build a search_key cache search_key_cache = {} search_keys = SearchKey.get_by_sobjects(self.sobjects) for search_key, sobject in zip(search_keys, self.sobjects): search_key_cache[search_key] = sobject self.caches['search_key'] = search_key_cache code_cache = {} for sobject in self.sobjects: code = sobject.get_code() code_cache[code] = sobject self.caches['code'] = code_cache for key in keys: if key in ['search_key', 'code']: continue self.build_cache_by_column(key)
def get_files(my): paths = [] # remember this here for now my.files = {} my.snapshots = {} search_key = my.kwargs.get("search_key") search_keys = my.kwargs.get("search_keys") if search_key: sobject = SearchKey.get_by_search_key(search_key) my.sobjects = [sobject] if search_keys: if isinstance(search_keys, basestring): search_keys = search_keys.replace("'", '"') search_keys = jsonloads(search_keys) my.sobjects = Search.get_by_search_keys(search_keys) if not my.sobjects: return [] my.sobject = my.sobjects[0] for sobject in my.sobjects: sobject_paths = my.get_sobject_files(sobject) paths.extend(sobject_paths) return paths
def execute(my): plugin = my.sobject web = WebContainer.get_web() value = web.get_form_value( my.get_input_name() ) if not value: return src_search_keys = jsonloads(value) manifest = plugin.get_xml_value("manifest") top_node = manifest.get_node("manifest") for search_key in src_search_keys: sobject = SearchKey.get_by_search_key(search_key) node = manifest.create_element("sobject") # For now, a plugin must contain project specfic entries search_type = sobject.get_base_search_type() code = sobject.get_value("code") manifest.set_attribute(node, "search_type", search_type) manifest.set_attribute(node, "code", code) #search_key = SearchKey.get_by_sobject(sobject) #manifest.set_attribute(node, "search_key", search_key) manifest.append_child(top_node, node) plugin.set_value("manifest", manifest.to_string() ) plugin.commit()
def execute(my): #my.snapshot_dict = {} web = WebContainer.get_web() shot_code = web.get_form_value("shot_code") search = Search(my.search_type) search.add_filter('code', shot_code) shot = search.get_sobject() #shot = Shot.get_by_code(shot_code) is_current = web.get_form_value("currency") if is_current in ['True', 'on']: is_current = True else: is_current = False is_revision = web.get_form_value("checkin_as") if is_revision == "Version": is_revision = False else: is_revision = True checkin_status = web.get_form_value("checkin_status") checkin = ShotCheckin(shot) checkin.set_option("unknown_ref", web.get_form_value("unknown_ref")) checkin.set_process(my.process) description = web.get_form_value("%s_description" % shot.get_code() ) checkin.set_context(my.context) checkin.set_description(description) checkin.set_current(is_current) checkin.set_revision(is_revision) use_handoff_dir = web.get_form_value("use_handoff_dir") if use_handoff_dir in ['true','on']: checkin.set_use_handoff(True) checkin.execute() snapshot = checkin.snapshot version = snapshot.get_version() my.sobjects = [shot] #my.snapshot_dict['%s' %shot.get_code()] = snapshot my.add_description("%s checkin '%s': v%0.3d, %s" % (my.context, shot.get_code(), version, description)) web.set_form_value('publish_search_type','prod/shot') TabWdg.set_redirect('Log') my.info['context'] = my.context my.info['revision'] = str(is_revision) my.info['checkin_status'] = checkin_status output = {'context': my.context} output['search_key'] = SearchKey.build_by_sobject(shot) output['checkin_status'] = checkin_status Trigger.call(my, 'app_checkin', output)
def get_section_wdg(my, sobject): parent_key = SearchKey.get_by_sobject(sobject) section_id = "wow" title = "" view = "children" target_id = "sobject_relation" kwargs = { 'section_id': section_id, 'title': title, 'view': view, 'target_id': target_id, 'width': '125', 'parent_key': parent_key } section_div = DivWdg() section_div.add_style("display: block") section_div.set_id(section_id) section_div.set_attr('spt_class_name', "tactic.ui.panel.ChildrenBookmarkMenuWdg") for name, value in kwargs.items(): if name == "config": continue section_div.set_attr("spt_%s" % name, value) section_wdg = SObjectChildrenMenuWdg(**kwargs) section_div.add(section_wdg) return section_div
def handle_td(self, td): sobject = self.get_current_sobject() parent = None if sobject.is_insert(): parent_key = self.state.get('parent_key') if parent_key: parent = SearchKey.get_by_search_key(parent_key) else: try: parent = sobject.get_parent() except SObjectSecurityException as e: pass except SearchException as e: if e.__str__().find('not registered') != -1: pass elif e.__str__().find('does not exist for database') != -1: pass else: raise process = sobject.get_value('process') current_value = sobject.get_value(self.get_name()) if current_value: value = '%s||%s'%(process, current_value) td.add_attr("spt_input_value", value) if parent: td.set_attr("spt_pipeline_code", parent.get_value("pipeline_code", no_exception=True))
def get_ref_obj(self, sobject): search_type = sobject.get_value("search_type") search_code = sobject.get_value("search_code", no_exception=True) if not search_code: search_id = sobject.get_value("search_code") else: search_id = None key = SearchKey.build_search_key(search_type, search_code) ref_sobject = self.ref_sobj_dict.get(str(key)) if not ref_sobject: try: if search_code: ref_sobject = Search.get_by_code(search_type, search_code) else: ref_sobject = Search.get_by_id(search_type, search_id) if not ref_sobject: return None except SearchException as e: print e.__str__() return None return ref_sobject
def check(my): search_key = my.kwargs.get('search_key') my.sobject = SearchKey.get_by_search_key(search_key) from pyasm.web import WebContainer web = WebContainer.get_web() my.old_password = web.get_form_value("old password") if isinstance(my.old_password, list): my.old_password = my.old_password[0] #encrypted = md5.new(my.old_password).hexdigest() encrypted = hashlib.md5(my.old_password).hexdigest() if encrypted != my.sobject.get_value('password'): raise UserException('Old password is incorrect.') my.password = web.get_form_value("password") if isinstance(my.password, list): my.password = my.password[0] if my.sobject == None: return UserException("Current user cannot be determined.") my.re_enter = web.get_form_value("password re-enter") if isinstance(my.re_enter, list): my.re_enter = my.re_enter[0] if my.re_enter != "" and my.re_enter != my.password: raise UserException( "Passwords must match. Please fill in the re-enter.") return True
def add_header(self, table, title): table.add_style('width', '50em') parent_st = self.kwargs.get('parent_search_type') parent_sid = self.kwargs.get('parent_search_id') parent_context = '' parent_version = '' sobj = Search.get_by_id(parent_st, parent_sid) sobj_code = 'New' sobj_title = '' if sobj: sobj_code = sobj.get_code() sobj_title = sobj.get_search_type_obj().get_title() if isinstance(sobj, Snapshot): parent_context = sobj.get_context() parent_version = sobj.get_version() th = table.add_header( "Add Submission for %s [%s]" % (sobj_title, sobj_code)) th.set_attr("colspan", "2") hidden = HiddenWdg('parent_search_type', parent_st ) th.add(hidden) hidden = HiddenWdg('parent_search_id', parent_sid ) th.add(hidden) hidden = HiddenWdg('parent_context', parent_context ) th.add(hidden) hidden = HiddenWdg('parent_version', parent_version ) th.add(hidden) if sobj: hidden = HiddenWdg('parent_search_key', SearchKey.get_by_sobject(sobj) ) th.add(hidden)
def convert_to_js(self, sobject, expression): # HACK!!: to very robust implementation pattern = re.compile('@(\w+)\((.*?)\)') matches = pattern.findall(expression) if not matches: return '', expression js_expression = expression columns = [] for match in matches: method = match[0] item = match[1] if method == 'GET': search_key = SearchKey.build_by_sobject(sobject) parts = item.split(".") column = parts[-1] replace = '"%s","%s"' % (search_key, parts[-1]) columns.append(column) else: parts = item.split(".") column = parts[-1] replace = '"%s"' % column columns.append(column) js_expression = js_expression.replace(item, replace) return js_expression, columns
def handle_td(my, td): super(LoginTableElementWdg, my).handle_td(td) task = my.get_current_sobject() if task: search_type = task.get_value('search_type') search_id = task.get_value('search_id') if not search_type or not search_id: return search_key = SearchKey.build_search_key(search_type, search_id, column='id') from pyasm.common import SObjectSecurityException try: parent = Search.get_by_search_key(search_key) pipeline = Pipeline.get_by_sobject(parent) if pipeline: attrs = pipeline.get_process_attrs(task.get_value('process')) td.add_attr('spt_pipeline_code', attrs.get('%s_login_group'%my.get_name())) except SObjectSecurityException, e: pass except SearchException, e: if e.__str__().find('not registered') != -1: pass elif e.__str__().find('does not exist for database') != -1: pass elif e.__str__().find('Cannot find project') != -1: pass else: raise
def get_files(self): paths = [] # remember this here for now self.files = {} self.snapshots = {} search_key = self.kwargs.get("search_key") sobject = SearchKey.get_by_search_key(search_key) # if it is deleted, return if not sobject: return [] if isinstance(sobject, Snapshot): snapshots = [sobject] else: snapshots = Snapshot.get_by_sobject(sobject, "publish") for snapshot in snapshots: snapshot_paths = snapshot.get_all_lib_paths() files = snapshot.get_all_file_objects() for path, file in zip(snapshot_paths, files): # if the path is a directory, get all of the files if os.path.isdir(path): for root, dirnames, filenames in os.walk(path): for filename in filenames: item_path = "%s/%s" % (root, filename) paths.append(item_path) self.files[item_path] = file self.snapshots[item_path] = snapshot for dirname in dirnames: item_path = "%s/%s/" % (root, dirname) paths.append(item_path) self.files[item_path] = file self.snapshots[item_path] = snapshot """ dirlist = os.listdir(path) for item in dirlist: item_path = "%s%s" % (path, item) if os.path.isdir(path): item_path = "%s/" % item_path paths.append(item_path) self.files[path] = file """ else: paths.append(path) self.files[path] = file base_dir_alias = file.get_value('base_dir_alias') if not self.base_dir and base_dir_alias: self.base_dir = Environment.get_asset_dir( alias=base_dir_alias) return paths
def handle_td(self, td): sobj = self.get_current_sobject() parent = None value = sobj.get_value('process') td.add_attr('spt_input_value', value) if sobj.is_insert(): state = self.get_state() parent_key = state.get('parent_key') if parent_key: parent = SearchKey.get_by_search_key(parent_key) else: # get the parent pipeline code try: parent = sobj.get_parent() except SObjectSecurityException as e: print "SObjectSecurityException raised for getting parent of [%s]" %sobj.get_code() pass except SearchException as e: if e.__str__().find('not registered') != -1: pass elif e.__str__().find('does not exist for database') != -1: pass else: raise except Exception as e: print "WARNING: ", e if parent: pipeline_code = parent.get_value("pipeline_code", no_exception=True) if pipeline_code: td.add_attr('spt_pipeline_code', pipeline_code)
def init_kwargs(my): """initialize kwargs""" state = my.kwargs.get("state") if state: parent_key = state.get("parent_key") if parent_key: my.sobject = SearchKey.get_by_search_key(parent_key) my.expression = my.get_option("expression") if not my.expression: my.expression = my.kwargs.get("expression") my.alt_expression = my.get_option("alt_expression") if not my.alt_expression: my.alt_expression = my.kwargs.get("alt_expression") my.mode = my.get_option("mode") if not my.mode: my.mode = my.kwargs.get("mode") if not my.mode: my.mode = "value" my.show_retired = my.get_option("show_retired") if not my.show_retired: my.show_retired = my.kwargs.get("show_retired") # default to False if my.show_retired == "true": my.show_retired = True else: my.show_retired = False my.enable_eval_listener = False if my.get_option("enable_eval_listener") in [True, "true", "True", "TRUE"]: my.enable_eval_listener = True
def postprocess(my): web = WebContainer.get_web() value = web.get_form_value(my.get_input_name()) if not value: return # get all fo the sobjects from the search keys instance_type = my.get_option("instance_type") # path is used for self-relating in an instance table src_path = my.get_option("path") #src_sobject = my.sobject search = Search(my.sobject.get_search_type()) search.add_id_filter(my.sobject.get_id()) src_sobject = search.get_sobject() # this is passed in from EditCmd in insert mode parent_key = my.get_option('parent_key') # in some rare cases we have project as the parent_key if parent_key and my.is_insert and 'sthpw/project' not in parent_key: # this is the parent dst_sobject = SearchKey.get_by_search_key(parent_key) # add all the new sobjects #instances = dst_sobject.get_related_sobject(instance_type) instance = SearchType.create(instance_type) instance.add_related_connection(src_sobject, dst_sobject, src_path=src_path) instance.commit()
def convert_to_js(my, sobject, expression): # HACK!!: to very robust implementation pattern = re.compile("@(\w+)\((.*?)\)") matches = pattern.findall(expression) if not matches: return "", expression js_expression = expression columns = [] for match in matches: method = match[0] item = match[1] if method == "GET": search_key = SearchKey.build_by_sobject(sobject) parts = item.split(".") column = parts[-1] replace = '"%s","%s"' % (search_key, parts[-1]) columns.append(column) else: parts = item.split(".") column = parts[-1] replace = '"%s"' % column columns.append(column) js_expression = js_expression.replace(item, replace) return js_expression, columns
def handle_td(my, td): sobj = my.get_current_sobject() parent = None value = sobj.get_value('process') td.add_attr('spt_input_value', value) if sobj.is_insert(): state = my.get_state() parent_key = state.get('parent_key') if parent_key: parent = SearchKey.get_by_search_key(parent_key) else: # get the parent pipeline code try: parent = sobj.get_parent() except SObjectSecurityException, e: print "SObjectSecurityException raised for getting parent of [%s]" % sobj.get_code( ) pass except SearchException, e: if e.__str__().find('not registered') != -1: pass elif e.__str__().find('does not exist for database') != -1: pass else: raise
def get_display(my): sobject = my.get_current_sobject() my.search_key = SearchKey.get_by_sobject(sobject) div = DivWdg() div.add_class("hand") title = "Show Item Details" if my.widget: widget = my.widget else: widget = IconButtonWdg(title=title, icon=IconWdg.ZOOM) code = sobject.get_code() name = sobject.get_value("name", no_exception=True) if not name: name = code widget.add_behavior( { 'type': 'click_up', 'search_key': my.search_key, 'code': code, 'name': name, 'cbjs_action': ''' spt.tab.set_main_body_tab(); var class_name = 'tactic.ui.tools.TaskDetailPanelWdg'; var kwargs = { search_key: bvr.search_key, }; var mode = ''; var layout = bvr.src_el.getParent(".spt_tool_top"); if (layout != null) { mode = 'tool' } if (mode == 'tool') { spt.app_busy.show("Loading ..."); var layout = bvr.src_el.getParent(".spt_tool_top"); var element = layout.getElement(".spt_tool_content"); spt.panel.load(element, class_name, kwargs); spt.app_busy.hide(); } else { var element_name = "detail_"+bvr.code; var title = "Detail ["+bvr.name+"]"; spt.tab.add_new(element_name, title, class_name, kwargs); } ''' } ) div.add(widget) return div
def get_no_icon_wdg(my, missing=False): sobject = my.get_current_sobject() if not sobject: return '' div = my.top div.add_style("position: relative") div.add_style("margin: 3px") div.add_class("spt_thumb_top") div.set_id( "thumb_%s" % sobject.get_search_key() ) icon_size = my.get_icon_size() if icon_size: div.add_style("%s: %s" % (my.aspect, icon_size) ) if missing: img = HtmlElement.img(ThumbWdg.get_missing_image()) elif sobject.get_value("_is_collection", no_exception=True): img = HtmlElement.img("/context/icons/mime-types/folder2.jpg") else: img = HtmlElement.img(ThumbWdg.get_no_image()) img.add_class("spt_image") #from tactic.ui.table import SObjectDetailElementWdg #detail = SObjectDetailElementWdg() #detail.set_widget(img) #detail.set_sobject(sobject) #div.add(detail) div.add(img) div.add_class("hand") if my.SQL_ERROR: warning_div = DivWdg('<i>-- preprocess error --</i>') warning_div.add_styles('position: absolute; z-index: 100; float: left; top: 0; left: 0; font-size: smaller;') div.add_style('position: relative') div.add(warning_div) search_key = SearchKey.get_by_sobject(sobject) code = sobject.get_code() detail = my.get_option("detail") if detail != 'false': my.add_icon_behavior(div, sobject) unit = None if isinstance(icon_size, basestring): icon_size, unit = my.split_icon_size(icon_size) img.add_style("%s: 100%%" % my.aspect ) else: img.add_style("%s: %s" % (my.aspect, my.get_icon_size()) ) img.add_style("min-%s: 15px" % my.aspect) return div
def get_item_div(self, sobject): ''' get the item div the sobject''' top = DivWdg() top.add_style("padding: 3px 2px") top.add_class("spt_drop_item") top.add_class("SPT_DROP_ITEM") item_div = DivWdg() top.add(item_div, "item_div") item_div.add_style("text-overflow: ellipsis") item_div.add_style("white-space: nowrap") item_div.add_style("width: 80%") item_div.add_attr('title','Click to remove') item_div.add_style("display", "inline-block") item_div.add_style("vertical-align", "top") item_div.add_style("overflow", "hidden") icon_div = DivWdg() top.add(icon_div) icon = IconWdg(icon="BS_REMOVE") icon_div.add(icon) icon_div.add_behavior( { 'type': 'click_up', #'cbjs_action': '''spt.dg_table_action.sobject_drop_remove(evt,bvr)''' 'cbjs_action': '''spt.drop.sobject_drop_remove(evt,bvr)''' } ) icon.add_style("opacity: 0.3") icon_div.add_class("hand") icon_div.add_style("display", "inline-block") icon_div.add_style("vertical-align", "top") #icon_div.add_border() #self.menu.set_over(item_div, event="mousein") #self.menu.set_out(top, event="mouseleave") # set this as the place for the display value to go item_div.add_class("spt_drop_display_value") add_icon = True ExpressionParser.clear_cache() if sobject: if add_icon: self._add_icon(sobject, item_div) if self.display_expr: display_value = Search.eval(self.display_expr, sobjects = sobject, single=True) else: display_value = sobject.get_display_value() if isinstance(display_value, list): display_value = display_value[0] item_div.add( display_value ) self.values.append( SearchKey.get_by_sobject(sobject) ) return top
def get_custom_layout_wdg(my, layout_view): content_div = DivWdg() from tactic.ui.panel import CustomLayoutWdg layout = CustomLayoutWdg(view=layout_view) content_div.add(layout) for widget in my.widgets: name = widget.get_name() if my.input_prefix: widget.set_input_prefix(my.input_prefix) layout.add_widget(widget, name) search_key = SearchKey.get_by_sobject(my.sobjects[0], use_id=True) search_type = my.sobjects[0].get_base_search_type() element_names = my.element_names[:] for element_name in my.skipped_element_names: element_names.remove(element_name) config_xml = my.kwargs.get("config_xml") bvr = { 'type': 'click_up', 'mode': my.mode, 'element_names': element_names, 'search_key': search_key, 'input_prefix': my.input_prefix, 'view': my.view, 'config_xml': config_xml } if my.mode == 'insert': bvr['refresh'] = 'true' # for adding parent relationship in EditCmd if my.parent_key: bvr['parent_key'] = my.parent_key hidden_div = DivWdg() hidden_div.add_style("display: none") content_div.add(hidden_div) hidden = TextAreaWdg("__data__") hidden_div.add(hidden) hidden.set_value( jsondumps(bvr) ) show_action = my.kwargs.get("show_action") if show_action in [True, 'true']: content_div.add( my.get_action_html() ) return content_div
def get_item_div(my, sobject): ''' get the item div the sobject''' top = DivWdg() top.add_style("padding: 3px 2px") top.add_class("spt_drop_item") top.add_class("SPT_DROP_ITEM") item_div = DivWdg() top.add(item_div, "item_div") item_div.add_style("text-overflow: ellipsis") item_div.add_style("white-space: nowrap") item_div.add_style("width: 80%") item_div.add_attr('title', 'Click to remove') item_div.add_style("display", "inline-block") item_div.add_style("vertical-align", "top") item_div.add_style("overflow", "hidden") icon_div = DivWdg() top.add(icon_div) icon = IconWdg(icon="BS_REMOVE") icon_div.add(icon) icon_div.add_behavior({ 'type': 'click_up', #'cbjs_action': '''spt.dg_table_action.sobject_drop_remove(evt,bvr)''' 'cbjs_action': '''spt.drop.sobject_drop_remove(evt,bvr)''' }) icon.add_style("opacity: 0.3") icon_div.add_class("hand") icon_div.add_style("display", "inline-block") icon_div.add_style("vertical-align", "top") #icon_div.add_border() #my.menu.set_over(item_div, event="mousein") #my.menu.set_out(top, event="mouseleave") # set this as the place for the display value to go item_div.add_class("spt_drop_display_value") add_icon = True ExpressionParser.clear_cache() if sobject: if add_icon: my._add_icon(sobject, item_div) if my.display_expr: display_value = Search.eval(my.display_expr, sobjects=sobject, single=True) else: display_value = sobject.get_display_value() if isinstance(display_value, list): display_value = display_value[0] item_div.add(display_value) my.values.append(SearchKey.get_by_sobject(sobject)) return top
def add_to_selected(cls, search_keys): # make sure the sobjects exist for search_key in search_keys: sobject = SearchKey.get_by_search_key(search_key) item = SearchType.create("sthpw/clipboard") item.set_user() item.add_related_sobject(sobject) item.set_value("category", "select") item.commit()
def execute(my): input = my.get_input() search_key = input.get("search_key") sobj = SearchKey.get_by_search_key(search_key) login_group = sobj.get_value('login_group') sobj.set_value('code', login_group) sobj.commit(triggers=False)
def get_no_icon_wdg(my, missing=False): sobject = my.get_current_sobject() if not sobject: return '' div = my.top div.add_style("position: relative") div.add_style("margin: 3px") div.add_class("spt_thumb_top") div.set_id( "thumb_%s" % sobject.get_search_key() ) icon_size = my.get_icon_size() if icon_size: div.add_style("%s: %s" % (my.aspect, icon_size) ) if missing: img = HtmlElement.img(ThumbWdg.get_missing_image()) else: img = HtmlElement.img(ThumbWdg.get_no_image()) img.add_class("spt_image") #from tactic.ui.table import SObjectDetailElementWdg #detail = SObjectDetailElementWdg() #detail.set_widget(img) #detail.set_sobject(sobject) #div.add(detail) div.add(img) div.add_class("hand") if my.SQL_ERROR: warning_div = DivWdg('<i>-- preprocess error --</i>') warning_div.add_styles('position: absolute; z-index: 100; float: left; top: 0; left: 0; font-size: smaller;') div.add_style('position: relative') div.add(warning_div) search_key = SearchKey.get_by_sobject(sobject) code = sobject.get_code() detail = my.get_option("detail") if detail != 'false': my.add_icon_behavior(div, sobject) if type(icon_size) == types.StringType and icon_size.endswith("%"): img.add_style("%s: 100%%" % my.aspect ) else: img.add_style("%s: %spx" % (my.aspect, my.get_icon_size()) ) img.add_style("min-%s: 15px" % my.aspect) return div
def execute(my): web = WebContainer.get_web() value = web.get_form_value( my.get_input_name() ) if not value: value = my.get_data() if not value: return src_search_keys = jsonloads(value) #print "xxx: ", type(src_search_keys), src_search_keys # get all fo the sobjects from the search keys #src_sobjects = SearchKey.get_by_search_keys(src_search_keys) instance_type = my.get_option("instance_type") # path is used for self-relating in an instance table src_path = my.get_option("path") src_sobjects = [] src_instances = [] for src_search_key in src_search_keys: src_sobject = SearchKey.get_by_search_key(src_search_key) if src_sobject.get_base_search_type() == instance_type: src_instances.append(src_sobject) else: src_sobjects.append(src_sobject) dst_sobject = my.sobject # get all of the current instances and see if any were removed instances = dst_sobject.get_related_sobjects(instance_type) for instance in instances: exists = False for src_instance in src_instances: if src_instance.get_search_key() == instance.get_search_key(): exists = True if not exists: instance.delete() # add all the new sobjects for src_sobject in src_sobjects: instance = SearchType.create(instance_type) instance.add_related_connection(src_sobject, dst_sobject, src_path=src_path) instance.commit()
def get_no_icon_wdg(my, missing=False): sobject = my.get_current_sobject() if not sobject: return '' div = my.top div.add_style("position: relative") div.add_style("margin: 3px") div.set_id( "thumb_%s" % sobject.get_search_key() ) icon_size = my.get_icon_size() if icon_size: div.add_style("%s: %s" % (my.aspect, icon_size) ) if missing: img = HtmlElement.img(ThumbWdg.get_missing_image()) else: img = HtmlElement.img(ThumbWdg.get_no_image()) img.add_class("spt_image") #from tactic.ui.table import SObjectDetailElementWdg #detail = SObjectDetailElementWdg() #detail.set_widget(img) #detail.set_sobject(sobject) #div.add(detail) div.add(img) div.add_class("hand") if my.SQL_ERROR: warning_div = DivWdg('<i>-- preprocess error --</i>') warning_div.add_styles('position: absolute; z-index: 100; float: left; top: 0; left: 0; font-size: smaller;') div.add_style('position: relative') div.add(warning_div) search_key = SearchKey.get_by_sobject(sobject) code = sobject.get_code() detail = my.get_option("detail") if detail != 'false': my.add_icon_behavior(div, sobject) if type(icon_size) == types.StringType and icon_size.endswith("%"): img.add_style("%s: 100%%" % my.aspect ) else: img.add_style("%s: %spx" % (my.aspect, my.get_icon_size()) ) img.add_style("min-%s: 15px" % my.aspect) return div
def execute(self): web = WebContainer.get_web() value = web.get_form_value( self.get_input_name() ) if not value: value = self.get_data() if not value: return src_search_keys = jsonloads(value) #print "xxx: ", type(src_search_keys), src_search_keys # get all fo the sobjects from the search keys #src_sobjects = SearchKey.get_by_search_keys(src_search_keys) instance_type = self.get_option("instance_type") # path is used for self-relating in an instance table src_path = self.get_option("path") src_sobjects = [] src_instances = [] for src_search_key in src_search_keys: src_sobject = SearchKey.get_by_search_key(src_search_key) if src_sobject.get_base_search_type() == instance_type: src_instances.append(src_sobject) else: src_sobjects.append(src_sobject) dst_sobject = self.sobject # get all of the current instances and see if any were removed instances = dst_sobject.get_related_sobjects(instance_type) for instance in instances: exists = False for src_instance in src_instances: if src_instance.get_search_key() == instance.get_search_key(): exists = True if not exists: instance.delete() # add all the new sobjects for src_sobject in src_sobjects: instance = SearchType.create(instance_type) instance.add_related_connection(src_sobject, dst_sobject, src_path=src_path) instance.commit()
def check(self): if self.mode == 'matched': from tactic.ui.panel import FastTableLayoutWdg table = FastTableLayoutWdg(search_type=self.search_type, view=self.view,\ show_search_limit='false', search_limit=-1, search_view=self.search_view, \ simple_search_view=self.simple_search_view, search_class=self.search_class) table.handle_search() search_objs = table.sobjects self.search_key_list = SearchKey.get_by_sobjects(search_objs, use_id=True) return True else: self.search_key_list = self.kwargs.get('search_key_list') if self.search_key_list and isinstance(self.search_key_list, basestring): self.search_key_list = eval(self.search_key_list)
def get_table(my, sobject, snapshots): parent_key = SearchKey.get_by_sobject(sobject) table = TableLayoutWdg(table_id='snapshot_history_table', search_type='sthpw/snapshot', view='checkin_history', show_search_limit=False, show_gear=False, show_insert=False, parent_key=parent_key, mode='simple') table.set_sobjects(snapshots) return table """
def check(my): if my.mode == 'matched': from tactic.ui.panel import FastTableLayoutWdg table = FastTableLayoutWdg(search_type=my.search_type, view=my.view,\ show_search_limit='false', search_limit=-1, search_view=my.search_view, \ simple_search_view=my.simple_search_view, search_class=my.search_class) table.handle_search() search_objs = table.sobjects my.search_key_list = SearchKey.get_by_sobjects(search_objs, use_id=True) return True else: my.search_key_list = my.kwargs.get('search_key_list') if my.search_key_list and isinstance(my.search_key_list, basestring): my.search_key_list = eval(my.search_key_list)
def execute(my): #my.snapshot_dict = {} # get all of the selected instances web = WebContainer.get_web() instances = web.get_form_values("asset_instances") set_instances = web.get_form_values("set_instances") is_current = web.get_form_value("currency") checkin_status = web.get_form_value("checkin_status") if is_current in ['True', 'on']: is_current = True else: is_current = False is_revision = web.get_form_value("checkin_as") if is_revision == "Version": is_revision = False else: is_revision = True snapshot_type = web.get_form_value("snapshot_type") if not instances and not set_instances: raise CommandExitException("No instances selected") # go through the asset instances and set instances and check them in for instance in instances: if instance: my._checkin(instance, my.context, is_current=is_current, \ is_revision=is_revision, snapshot_type=snapshot_type, \ texture_search_type=my.texture_search_type) for set_instance in set_instances: if set_instance: my._checkin(set_instance, my.context, asset_type='set', \ is_current=is_current, is_revision=is_revision, \ snapshot_type=snapshot_type) web.set_form_value('publish_search_type', 'prod/asset') #TabWdg.set_redirect('Log') my.info['context'] = my.context my.info['revision'] = str(is_revision) my.info['checkin_status'] = checkin_status output = {'context': my.context} output['search_key'] = SearchKey.build_by_sobject(my.sobject) output['checkin_status'] = checkin_status Trigger.call(my, 'app_checkin', output)
def extract_project_code(cls, search_type): base_search_type, data = SearchKey._get_data(search_type) project_code = data.get("project") if project_code == None: # this is specifically for project-specific sType search_type_obj = SearchType.get(search_type) database = search_type_obj.get_value("database") if database != "{project}": project_code = database else: # get the global project code project_code = Project.get_project_code() #project_code = cls.get_global_project_code() return project_code
def get_display(self): top = self.top top.add_style("padding: 10px") top.add_color("background", "background", -5) top.add_style("min-width: 600px") paths = self.get_files() # assume that all the paths are part of the same repo repo = 'tactic' for file in self.files.values(): repo = file.get_value("repo_type", no_exception=True) break if repo == 'perforce': search_key = self.kwargs.get("search_key") sobject = SearchKey.get_by_search_key(search_key) project = sobject.get_project() depot = project.get_value("location", no_exception=True) if not depot: depot = project.get_code() location = '//%s' % depot dir_list = SnapshotDirListWdg(base_dir=location, location="scm", show_base_dir=True, paths=paths, all_open=True, files=self.files, snapshots=self.snapshots) else: # If not discovered thru base_dir_alias, use the default if not self.base_dir: self.base_dir = Environment.get_asset_dir() dir_list = SnapshotDirListWdg(base_dir=self.base_dir, location="server", show_base_dir=True, paths=paths, all_open=True, files=self.files, snapshots=self.snapshots) top.add(dir_list) return top