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 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_bottom_wdg(my): if my.get_option('mode') =='input': return web = WebContainer.get_web() if web.get_selected_app() not in ['XSI','Maya']: return div = DivWdg(css='spt_outdated_ref') refs = my.session.get_data().get_nodes("session/node/ref") snap_codes = [] snap_contexts = [] sobjects = [] session_data_dict = {} asset_codes = [] current_snapshots = [] node_names = [] session_versions = [] for ref in refs: snap_code = Xml.get_attribute(ref, "asset_snapshot_code") node_name = Xml.get_attribute(ref, "name") version = Xml.get_attribute(ref, "asset_snapshot_version") asset_code = Xml.get_attribute(ref, "asset_code") if snap_code in snap_codes: continue snap_codes.append(snap_code) snap_contexts.append(Xml.get_attribute(ref, "asset_snapshot_context")) asset_codes.append(asset_code) session_data_dict[snap_code] = version, node_name # must search one by one warnings=[] for idx, snap_code in enumerate(snap_codes): snapshot = Snapshot.get_by_code(snap_code) if not snapshot: continue search_type = snapshot.get_value('search_type') search_id = snapshot.get_value('search_id') sk = SearchKey.build_search_key(search_type, search_id, column='id') current_snapshot = Snapshot.get_snapshot(search_type, search_id, context=snap_contexts[idx], version=0) if not current_snapshot: warnings.append("Current version for [%s] context [%s] not found" %(sk, snap_contexts[idx])) continue session_version, node_name = session_data_dict.get(snap_code) if session_version and int(current_snapshot.get_version()) > int(session_version): current_snapshots.append(current_snapshot) sobjects.append(current_snapshot.get_sobject()) node_names.append(node_name) session_versions.append(int(session_version)) title = DivWdg('Outdated References') title.add_style('text-decoration','underline') div.add(title) # draw the nodes to be udpated for idx, current_snap in enumerate(current_snapshots): cb = CheckboxWdg(my.REF_CB_NAME) cb.add_class('spt_ref') cb.add_style('display: none') sobj = sobjects[idx] node_name = node_names[idx] session_version = session_versions[idx] snapshot = current_snap cb_value = my.get_input_value(sobj, snapshot) items = cb_value.split('|') items[-1] = node_name cb_value = '|'.join(items) cb.set_option('value', cb_value) div.add(cb) div.add('%0.1d. %s v%0.3d -> v%0.3d\n' \ %(idx+1, node_name, session_version, snapshot.get_version())) div.add(HtmlElement.br()) for warning in warnings: div.add(SpanWdg(warning, css='warning')) div.add(HtmlElement.br()) if current_snapshots: # add the button prefix = my.search_type #input_name = '%s_%s' %(my.search_type, my.CB_NAME) update_button = ProdIconButtonWdg("Update all references") update_button.add_behavior({'type': "click_up",\ 'cbjs_action': '''var cousins = bvr.src_el.getParent('.spt_outdated_ref').getElements('.spt_ref'); cousins.each( function(x) {x.checked=true;}); py_replace_reference(bvr, '%s','%s')''' % (prefix, my.REF_CB_NAME)}) div.add( SpanWdg(update_button, css='small')) div.add(HtmlElement.br(2)) return div
def get_bottom_wdg(my): if my.get_option('mode') == 'input': return web = WebContainer.get_web() if web.get_selected_app() not in ['XSI', 'Maya']: return div = DivWdg(css='spt_outdated_ref') refs = my.session.get_data().get_nodes("session/node/ref") snap_codes = [] snap_contexts = [] sobjects = [] session_data_dict = {} asset_codes = [] current_snapshots = [] node_names = [] session_versions = [] for ref in refs: snap_code = Xml.get_attribute(ref, "asset_snapshot_code") node_name = Xml.get_attribute(ref, "name") version = Xml.get_attribute(ref, "asset_snapshot_version") asset_code = Xml.get_attribute(ref, "asset_code") if snap_code in snap_codes: continue snap_codes.append(snap_code) snap_contexts.append( Xml.get_attribute(ref, "asset_snapshot_context")) asset_codes.append(asset_code) session_data_dict[snap_code] = version, node_name # must search one by one warnings = [] for idx, snap_code in enumerate(snap_codes): snapshot = Snapshot.get_by_code(snap_code) if not snapshot: continue search_type = snapshot.get_value('search_type') search_id = snapshot.get_value('search_id') sk = SearchKey.build_search_key(search_type, search_id, column='id') current_snapshot = Snapshot.get_snapshot( search_type, search_id, context=snap_contexts[idx], version=0) if not current_snapshot: warnings.append( "Current version for [%s] context [%s] not found" % (sk, snap_contexts[idx])) continue session_version, node_name = session_data_dict.get(snap_code) if session_version and int( current_snapshot.get_version()) > int(session_version): current_snapshots.append(current_snapshot) sobjects.append(current_snapshot.get_sobject()) node_names.append(node_name) session_versions.append(int(session_version)) title = DivWdg('Outdated References') title.add_style('text-decoration', 'underline') div.add(title) # draw the nodes to be udpated for idx, current_snap in enumerate(current_snapshots): cb = CheckboxWdg(my.REF_CB_NAME) cb.add_class('spt_ref') cb.add_style('display: none') sobj = sobjects[idx] node_name = node_names[idx] session_version = session_versions[idx] snapshot = current_snap cb_value = my.get_input_value(sobj, snapshot) items = cb_value.split('|') items[-1] = node_name cb_value = '|'.join(items) cb.set_option('value', cb_value) div.add(cb) div.add('%0.1d. %s v%0.3d -> v%0.3d\n' \ %(idx+1, node_name, session_version, snapshot.get_version())) div.add(HtmlElement.br()) for warning in warnings: div.add(SpanWdg(warning, css='warning')) div.add(HtmlElement.br()) if current_snapshots: # add the button prefix = my.search_type #input_name = '%s_%s' %(my.search_type, my.CB_NAME) update_button = ProdIconButtonWdg("Update all references") update_button.add_behavior({'type': "click_up",\ 'cbjs_action': '''var cousins = bvr.src_el.getParent('.spt_outdated_ref').getElements('.spt_ref'); cousins.each( function(x) {x.checked=true;}); py_replace_reference(bvr, '%s','%s')''' % (prefix, my.REF_CB_NAME)}) div.add(SpanWdg(update_button, css='small')) div.add(HtmlElement.br(2)) return div
def setup_html_list_for_components_in_order(self, width=600): components_list = HtmlElement.ul() components_list.add_style('list-style-type', 'none') components_list.add_style('margin-left', '10px') components_list.add_style('padding-left', '0px') component_search = Search('twog/component') component_search.add_filter('order_code', self.order_sobject.get_code()) components = component_search.get_sobjects() for component in components: component_name_div = DivWdg() component_name_div.add_style('font-weight', 'bold') component_name_div.add(component.get('name')) component_code_div = DivWdg() component_code_div.add('Code: {0}'.format(component.get_code())) component_title_div = DivWdg() component_title = get_sobject_name_by_code( 'twog/title', component.get('title_code')) if component_title: component_title_div.add('Title: {0}'.format(component_title)) else: component_title_div.add('No Title Selected') component_description_div = DivWdg() component_description_div.add_style('font-style', 'italic') component_description_div.add(component.get('description')) component_pipeline_div = DivWdg() component_pipeline_name = get_sobject_name_by_code( 'sthpw/pipeline', component.get('pipeline_code')) if component_pipeline_name: component_pipeline_div.add( 'Pipeline: <i>{0}</i>'.format(component_pipeline_name)) else: component_pipeline_div.add('<i>No Pipeline Assigned</i>') component_instructions_div = DivWdg() component_instructions_name = get_sobject_name_by_code( 'twog/instructions', component.get('instructions_code')) if component_instructions_name: component_instructions_div.add( 'Instructions: <i>{0}</i>'.format( component_instructions_name)) else: component_instructions_div.add( '<i>No Instrutions assigned</i>') component_language_div = DivWdg() component_language = get_sobject_name_by_code( 'twog/language', component.get_value('language_code')) if component_language: component_language_div.add( 'Language: <i>{0}</i>'.format(component_language)) else: component_language_div.add('<i>No language selected</i>') # Set up a div for the component's status, if one exists (it should). component_status_div = DivWdg() component_status = component.get('status') if component_status: # Get the label and color for the component status by looking it up in a dictionary. # If the status is not found, None will be returned instead component_status_label, component_status_color = get_component_status_label_and_color( component_status) if component_status_label and component_status_color: # Put the label in a span, so it can be assigned a color component_status_span = SpanWdg() component_status_span.add(component_status_label) component_status_span.add_style('color', component_status_color) # Add "Status:" along with the colored span to the div component_status_div.add('Status: ') component_status_div.add(component_status_span) else: # Status was not found, present it as it is in the database component_status_div.add( 'Status: {0}'.format(component_status)) else: # There should never be a case where a status is not set on a component, but it could happen component_status_div.add('<i>Status not set</i>') component_estimated_total_hours_div = DivWdg() estimated_total_hours = get_component_estimated_total_hours_from_component_code( component.get_code()) if estimated_total_hours: component_estimated_total_hours_div.add( 'Estimated Total Hours: {0}'.format(estimated_total_hours)) component_estimated_remaining_hours_div = DivWdg() estimated_remaining_hours = get_component_estimated_remaining_hours_from_component_code( component.get_code()) if estimated_remaining_hours: component_estimated_remaining_hours_div.add( 'Estimated Remaining Hours: {0}'.format( estimated_remaining_hours)) component_div = DivWdg() component_div.add_style('background-color', '#d9edcf') component_div.add_style('padding', '10px') component_div.add_style('border-radius', '10px') component_div.add(component_name_div) component_div.add(component_code_div) component_div.add(component_title_div) component_div.add(component_description_div) component_div.add(component_pipeline_div) component_div.add(component_instructions_div) component_div.add(component_language_div) component_div.add(component_status_div) component_div.add(component_estimated_total_hours_div) component_div.add(component_estimated_remaining_hours_div) instructions_button = ButtonNewWdg(title='Instructions', icon='CONTENTS') instructions_button.add_behavior( obu.get_load_popup_widget_behavior( 'Component Instructions', 'order_builder.ComponentInstructionsWdg', component.get_search_key())) instructions_button.add_style('display', 'inline-block') change_instructions_button = ButtonNewWdg( title='Change Instructions', icon='DOCUMENTATION') change_instructions_button.add_behavior( obu.get_load_popup_widget_with_reload_behavior( 'Change Instructions', 'order_builder.ChangeInstructionsWdg', component.get_search_key(), 'Order Builder', 'order_builder.OrderBuilderWdg', self.order_sobject.get_search_key())) change_instructions_button.add_style('display', 'inline-block') # Get the instructions search key for the Edit Instructions widget instructions_document_search_key = SearchKey.build_search_key( 'twog/instructions', component.get('instructions_code'), project_code='twog') edit_instructions_button = ButtonNewWdg(title='Edit Instructions', icon='EDIT') edit_instructions_button.add_behavior( obu.get_load_new_tab_behavior( 'edit_instructions_{0}'.format( instructions_document_search_key), 'Edit Instructions', 'widgets.EditInstructionsWdg', instructions_document_search_key)) edit_instructions_button.add_style('display', 'inline-block') add_instructions_from_template_button = ButtonNewWdg( title='Add Instructions From Template', icon='EDIT') add_instructions_from_template_button.add_behavior( obu.get_load_popup_widget_with_reload_behavior( 'Add Instructions From Template', 'widgets.AddInstructionsFromTemplateWdg', component.get_search_key(), 'Order Builder', 'order_builder.OrderBuilderWdg', self.order_sobject.get_search_key())) add_instructions_from_template_button.add_style( 'display', 'inline-block') change_title_button = ButtonNewWdg(title='Change Title', icon='') change_title_button.add_behavior( obu.get_load_popup_widget_with_reload_behavior( 'Change Title', 'order_builder.ChangeTitleWdg', component.get_search_key(), 'Order Builder', 'order_builder.OrderBuilderWdg', self.order_sobject.get_search_key())) change_title_button.add_style('display', 'inline-block') change_pipeline_button = ButtonNewWdg(title='Change Pipeline', icon='PIPELINE') change_pipeline_button.add_behavior( obu.get_load_popup_widget_with_reload_behavior( 'Change Pipeline', 'widgets.AssignPipelineWdg', component.get_search_key(), 'Order Builder', 'order_builder.OrderBuilderWdg', self.order_sobject.get_search_key())) change_pipeline_button.add_style('display', 'inline-block') add_tasks_from_pipeline_wdg = ButtonNewWdg( title='Add Tasks from Pipeline', icon='INSERT_MULTI') add_tasks_from_pipeline_wdg.add_behavior( get_load_assign_tasks_wdg(component.get_search_key())) add_tasks_from_pipeline_wdg.add_style('display', 'inline-block') add_task_button = ButtonNewWdg(title='Add Task', icon='INSERT') add_task_button.add_behavior( obu.get_load_popup_widget_behavior( 'Add Task', 'order_builder.InsertTaskWdg', component.get_search_key())) add_task_button.add_style('display', 'inline-block') note_button = ButtonNewWdg(title='Add Note', icon='NOTE') note_button.add_behavior( obu.get_add_notes_behavior(component.get_search_key())) note_button.add_style('display', 'inline-block') button_row_div = SpanWdg() button_row_div.add_style('display', 'inline-block') button_row_div.add(instructions_button) button_row_div.add(edit_instructions_button) button_row_div.add(change_instructions_button) button_row_div.add(add_instructions_from_template_button) button_row_div.add(change_title_button) button_row_div.add(change_pipeline_button) button_row_div.add(add_tasks_from_pipeline_wdg) button_row_div.add(add_task_button) button_row_div.add(note_button) component_div.add(button_row_div) tasks = component.get_all_children('sthpw/task') component_task_div = DivWdg() component_task_div.add_style('width', '{0}px'.format(width - 10)) component_task_div.add_style('margin-left', '10px') # If there are tasks associated with the component, add them as a sub-list below it if tasks: task_list = DivWdg() for task in sorted(tasks, key=lambda x: x.get_code()): task_div = DivWdg() task_div.add(self.get_task_div(task)) task_list.add(task_div) component_task_div.add(task_list) component_outer_div = DivWdg() component_outer_div.add(component_div) component_outer_div.add(component_task_div) components_list.add(component_outer_div) return components_list