Ejemplo n.º 1
0
    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
Ejemplo n.º 2
0
    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
Ejemplo n.º 3
0
    def execute(my):

        input = my.get_input()
        search_key = input.get("search_key")
        search_code = input.get('search_code')

        sobj_id = input.get('id')
        if not sobj_id:
            sobj = Search.get_by_search_key(search_key)
            sobj_id = sobj.get_id()

        assert(sobj_id != None)

        # it is possible that the id is not an integer (ie MongoDb)
        # In this case, search_id cannot be used and this id is considered
        # a code
        if not search_code and not isinstance(sobj_id, int):
            search_code = sobj_id

        search_type = SearchKey.extract_search_type(search_key)
        
        # find the old sobject
        if sobj_id != -1:
            search = Search("sthpw/sobject_list")
            search.add_filter( "search_type", search_type )
            if search_code:
                search.add_filter( "search_code", search_code )
            else:
                search.add_filter( "search_id", sobj_id )
            sobject = search.get_sobject()
        else:
            sobject = None
        
        
        if input.get("is_delete") == True:
            if sobject:
                sobject.delete()
            return

        if not sobject:
            sobject = SearchType.create("sthpw/sobject_list")


        if not search_type.startswith("sthpw/"):
            project_code = Project.extract_project_code(search_type)
        else:
            project = "admin"

        sobject.set_value("project_code", project_code)



        caller = my.get_caller()

        data = set()

        data.update( my.cleanup(caller.get_value("code", no_exception=True) ))
        data.update( my.cleanup(caller.get_value("name", no_exception=True) ))
        data.update( my.cleanup(caller.get_value("description", no_exception=True) ))
        data.update( my.cleanup(caller.get_value("keywords", no_exception=True) ))

        # extra columns to add
        columns = []
        for column in columns:
            data.append( my.cleanup(caller.get_value(column) ))

        
        keywords = " ".join(data)
        sobject.set_value("keywords", keywords)

        sobject.set_parent(caller)
        sobject.commit(triggers=False)
Ejemplo n.º 4
0
    def execute(self):

        self.handle_keywords()


        input = self.get_input()
        search_key = input.get("search_key")
        search_code = input.get('search_code')

        sobj_id = input.get('id')
        sobj = Search.get_by_search_key(search_key)


        # Why not user caller???? 
        caller = self.get_caller()

        # see if this sobject is the list of sobjects that need to be in the
        # sobject list
        search_types = ProjectSetting.get_value_by_key("global_search/search_types")
        if search_types:
            search_types = search_types.split(",")
            if sobj and sobj.get_base_search_type() not in search_types:
                return

        
        if not sobj_id:
            sobj_id = sobj.get_id()

        assert(sobj_id != None)

        # it is possible that the id is not an integer (ie MongoDb)
        # In this case, search_id cannot be used and this id is considered
        # a code
        if not search_code and not isinstance(sobj_id, int):
            search_code = sobj_id

        search_type = SearchKey.extract_search_type(search_key)

        input_search_type = input.get("search_type")
        base_search_type = input_search_type.split("?")[0]

        # find the old sobject list entry
        if sobj_id != -1:
            search = Search("sthpw/sobject_list")
            search.add_filter( "search_type", search_type )
            if search_code:
                search.add_filter( "search_code", search_code )
            else:
                search.add_filter( "search_id", sobj_id )
            sobject = search.get_sobject()
        else:
            sobject = None


        # delete the sobject list
        if input.get("is_delete") == True:
            if sobject:
                sobject.delete()
            return

        if not sobject:
            sobject = SearchType.create("sthpw/sobject_list")
            sobject.set_auto_code()

        if not search_type.startswith("sthpw/"):
            project_code = Project.extract_project_code(search_type)
        else:
            project = "admin"

        sobject.set_value("project_code", project_code)



        # build up a data set for sobject list
        data = set()

        data.update( self.cleanup(caller.get_value("code", no_exception=True) ))
        data.update( self.cleanup(caller.get_value("name", no_exception=True) ))
        data.update( self.cleanup(caller.get_value("description", no_exception=True) ))
        data.update( self.cleanup(caller.get_value("keywords", no_exception=True) ))

        # commit the information
        keywords = " ".join(data)
        sobject.set_value("keywords", keywords)

        sobject.set_parent(caller)
        sobject.commit(triggers=False)
Ejemplo n.º 5
0
    def _test_dir_naming(my):

        # change to the test dir naming class
        my.sobj.set_value('dir_naming_cls', 'pyasm.biz.naming_test.TestDirNaming')
        my.sobj.commit()

        # 1. try a different search_type unittest/person
        version = 9
        code = 'phil2'
        process = 'model'
        type = 'main'
        context = 'modeling'

        asset = SearchType.create( 'unittest/person' )
        asset.set_value("code",code)
        asset.set_value("name_first", "Philip")
        asset.commit()

        # change a different input file name
        file_obj = File(File.SEARCH_TYPE)
        # due to new restriction of set_sobject_value().. we can't use it any more
        #file_obj.set_sobject_value(asset)
        sk = SearchKey.get_by_sobject(asset, use_id =True)
        st = SearchKey.extract_search_type(sk)
        sid = SearchKey.extract_id(sk)
        file_obj.set_value('search_type', st)
        file_obj.set_value('search_id', sid)
        file_obj.set_value('file_name','some_maya_model.mb') 
        file_obj.set_value('type', type)
        file_obj.set_value('base_type', 'file')
        file_obj.commit()

        virtual_snapshot = Snapshot.create_new()
        virtual_snapshot_xml = '<snapshot process=\'%s\'><file type=\'%s\' file_code=\'%s\'/></snapshot>' % (process, type, file_obj.get_code())
        virtual_snapshot.set_value("snapshot", virtual_snapshot_xml)
        virtual_snapshot.set_value("context", context)

        virtual_snapshot.set_sobject(asset)
        virtual_snapshot.set_value("version", version)
        
       
        

        Project.set_project('unittest')
        dir_naming = Project.get_dir_naming()
        dir_naming.set_sobject(asset)
        dir_naming.set_snapshot(virtual_snapshot)
        dir_naming.set_file_object(file_obj)
        dir_name = dir_naming.get_dir()
        expected_dir_name = '/assets/phil2/mb.main/v009'
        expected_dir_name2 = '/phil2/mb.main/v009'
        my.assertEquals(expected_dir_name, dir_name)
        
        lib_paths = virtual_snapshot.get_all_lib_paths()
        sand_paths = virtual_snapshot.get_all_lib_paths(mode='sandbox')
        client_paths = virtual_snapshot.get_all_lib_paths(mode='client_repo')
       
        base_dir = Config.get_value("checkin", "asset_base_dir", sub_key='default')
        sand_base_dir = dir_naming.get_base_dir(protocol='sandbox')
        client_base_dir = dir_naming.get_base_dir(protocol='client_repo')
       

        my.assertEquals(lib_paths[0].startswith('%s%s'%(base_dir, expected_dir_name2)), True)
        my.assertEquals(sand_paths[0].startswith('%s%s'%(sand_base_dir[0], expected_dir_name2)), True)
        my.assertEquals(client_paths[0].startswith('%s%s'%(client_base_dir[0], expected_dir_name2)), True)

        # 2  get_preallocated_path
        # set version 1 here since it's the first snapshot for this sobject. 
        # without a virtual file_object, the file_name is empty, and so the dir ma.maya is now .maya
        my.assertEquals("phil/.maya/v001", my.get_preallocated_dir()) 
        
        # switch back to regular file naming
        my.sobj.set_value('file_naming_cls', 'pyasm.biz.naming_test.TestFileNaming')
        my.sobj.commit()

        my.assertEquals("phil/ma.maya/v001", my.get_preallocated_dir()) 
Ejemplo n.º 6
0
    def execute(self):

        self.handle_keywords()

        input = self.get_input()
        search_key = input.get("search_key")
        search_code = input.get('search_code')

        sobj_id = input.get('id')
        sobj = Search.get_by_search_key(search_key)

        # Why not user caller????
        caller = self.get_caller()

        # see if this sobject is the list of sobjects that need to be in the
        # sobject list
        search_types = ProjectSetting.get_value_by_key(
            "global_search/search_types")
        if search_types:
            search_types = search_types.split(",")
            if sobj and sobj.get_base_search_type() not in search_types:
                return

        if not sobj_id:
            sobj_id = sobj.get_id()

        assert (sobj_id != None)

        # it is possible that the id is not an integer (ie MongoDb)
        # In this case, search_id cannot be used and this id is considered
        # a code
        if not search_code and not isinstance(sobj_id, int):
            search_code = sobj_id

        search_type = SearchKey.extract_search_type(search_key)

        input_search_type = input.get("search_type")
        base_search_type = input_search_type.split("?")[0]

        # find the old sobject list entry
        if sobj_id != -1:
            search = Search("sthpw/sobject_list")
            search.add_filter("search_type", search_type)
            if search_code:
                search.add_filter("search_code", search_code)
            else:
                search.add_filter("search_id", sobj_id)
            sobject = search.get_sobject()
        else:
            sobject = None

        # delete the sobject list
        if input.get("is_delete") == True:
            if sobject:
                sobject.delete()
            return

        if not sobject:
            sobject = SearchType.create("sthpw/sobject_list")
            sobject.set_auto_code()

        if not search_type.startswith("sthpw/"):
            project_code = Project.extract_project_code(search_type)
        else:
            project = "admin"

        sobject.set_value("project_code", project_code)

        # build up a data set for sobject list
        data = set()

        data.update(self.cleanup(caller.get_value("code", no_exception=True)))
        data.update(self.cleanup(caller.get_value("name", no_exception=True)))
        data.update(
            self.cleanup(caller.get_value("description", no_exception=True)))
        data.update(
            self.cleanup(caller.get_value("keywords", no_exception=True)))

        # commit the information
        keywords = " ".join(data)
        sobject.set_value("keywords", keywords)

        sobject.set_parent(caller)
        sobject.commit(triggers=False)
Ejemplo n.º 7
0
    def execute(self):

        notification = self.kwargs.get('sobject_dict')
        search_key = notification.get('__search_key__')
        event = notification.get('event')
        parts = event.split('|')
        if len(parts) < 2:
            raise TacticException(
                'event should be in the form of {action}|{search_type}, e.g. update|sthpw/task or update|sthpw/task|status'
            )
        orig_search_type = parts[1]
        search_type_obj = SearchType.get(orig_search_type)
        sobject = SearchType.create(orig_search_type)

        self.sobjects.append(sobject)

        search_type = SearchKey.extract_search_type(search_key)
        search_id = notification.get('id')
        columns = search_type_obj.get_columns(orig_search_type)
        for column in columns:
            type = search_type_obj.get_column_type(orig_search_type, column)
            if column == 'search_type':
                value = search_type
            elif column == 'search_id':
                value = search_id
            elif column == 'project_code':
                value = Project.get_project_code()
            elif column in ['assigned', 'login']:
                value = Environment.get_user_name()
            elif type in ['integer', 'float', 'number']:
                value = 100
            elif type == 'timestamp':
                value = '20110101'
            else:
                value = '%s_test' % column
            try:
                sobject.set_value(column, value)
            except:
                continue

        notification_stype = notification.get('search_type')
        if notification_stype:
            sobject.set_value("search_type", notification_stype)

        # some dummy output
        output = {'id': sobject.get_id()}

        notification_process = notification.get('process')
        if notification_process:
            if 'process' in columns:
                sobject.set_value("process", notification_process)
        try:
            triggers = Trigger.call(
                sobject,
                event,
                output=output,
                forced_mode='same process,same transaction',
                process=notification_process,
                search_type=notification_stype)
            if triggers:
                for idx, trigger in enumerate(triggers):
                    self.add_description('%s. %s' %
                                         (idx + 1, trigger.get_description()))
            else:
                raise TacticException(
                    'No notification trigger is fired. Possible mismatched project_code for this notification entry.'
                )
        except Exception, e:
            raise
            raise Exception(e.__str__())
Ejemplo n.º 8
0
    def execute(self):

        notification = self.kwargs.get('sobject_dict')
        search_key = notification.get('__search_key__')
        event = notification.get('event')
        parts  = event.split('|')
        if len(parts) < 2:
            raise TacticException('event should be in the form of {action}|{search_type}, e.g. update|sthpw/task or update|sthpw/task|status')
        orig_search_type = parts[1]
        search_type_obj  = SearchType.get(orig_search_type)
        sobject = SearchType.create(orig_search_type)

       
            
        self.sobjects.append(sobject)

        search_type = SearchKey.extract_search_type(search_key)
        search_id = notification.get('id')
        columns = search_type_obj.get_columns(orig_search_type)
        for column in columns:
            type = search_type_obj.get_column_type(orig_search_type,column)
            if column == 'search_type':
                value = search_type
            elif column == 'search_id':
                value = search_id
            elif column == 'project_code':
                value = Project.get_project_code()
            elif column in ['assigned', 'login']:
                value = Environment.get_user_name()
            elif type in ['integer','float','number']:
                value = 100
            elif type == 'timestamp':
                value = '20110101'
            else:
                value = '%s_test'%column
            try:
                sobject.set_value(column, value)
            except:
                continue


        notification_stype = notification.get('search_type')
        if notification_stype:
            sobject.set_value("search_type",  notification_stype)

        # some dummy output
        output = {'id': sobject.get_id()}

        notification_process = notification.get('process')
        if notification_process:
            if 'process' in columns:
                sobject.set_value("process", notification_process)
        try:
            triggers = Trigger.call(sobject, event, output=output, forced_mode='same process,same transaction', process = notification_process, search_type = notification_stype)
            if triggers:
                for idx, trigger in enumerate(triggers):
                    self.add_description('%s. %s' %(idx+1, trigger.get_description()))
            else:
                raise TacticException('No notification trigger is fired. Possible mismatched project_code for this notification entry.')
        except Exception, e:
            raise
            raise Exception(e.__str__())
Ejemplo n.º 9
0
    def get_display(my):

        search_key = my.kwargs.get("search_key")
        msg = None
        base_search_type = SearchKey.extract_search_type(search_key)
        sobject = SearchKey.get_by_search_key(search_key)
        process_div = DivWdg()
        process_div.add_style('padding-top: 10px')

        if base_search_type  in ['sthpw/task', 'sthpw/note']:
            my.process = sobject.get_value('process')
            my.context = sobject.get_value('context')
            if not my.process:
                my.process = ''

            parent = sobject.get_parent()
            if parent:
                search_key = SearchKey.get_by_sobject(parent)
            else:
                msg = "Parent for [%s] not found"%search_key
            
        else:
            my.process = my.kwargs.get('process')

        
        top = my.top
        top.add_class('spt_simple_checkin')
        top.add_color("background", "background")
        top.add_styles("position: relative")

        content = DivWdg(msg)
        top.add(content)
        #content.add_border()
        #content.add_color("background", "background3")
        #content.add_color("color", "background3")
        content.add_style("width: 600px")
        content.add_styles("margin-left: auto; margin-right: auto;")
        content.add_style("height: 200px")

        from tactic.ui.widget import CheckinWdg
        content.add_behavior( {
            'type': 'load',
            'cbjs_action': CheckinWdg.get_onload_js()
        } )


        button_div = DivWdg()
        
        content.add(process_div)

        content.add(button_div)
        button = IconWdg(title="Check-In", icon=IconWdg.CHECK_IN_3D_LG)

        title = Common.get_display_title(my.checkin_action)
        button.add_attr('title', title)


        button_div.add(button)
        button_div.set_box_shadow("1px 1px 1px 1px")
        button_div.add_style("width: 60px")
        button_div.add_style("height: 60px")
        button_div.add_style("float: left")
        button_div.add_style("background: white")
        button_div.add_class("hand")

        button_div.add_style("padding: 2px 3px 0 0")
        button_div.add_style("margin: 20px 60px 20px 200px")
        button_div.add_style("text-align: center")

        button_div.add("Check-in")

        # to be consistent with Check-in New File
        if my.process:
            checkin_process = my.process
        else:
            # Dont' specify, the user can choose later in check-in widget
            checkin_process = ''
        button.add_behavior( {
            'type': 'click_up',
            'search_key': search_key,
            'process': checkin_process,
            'context': my.context,
            'cbjs_action': '''
            var class_name = 'tactic.ui.widget.CheckinWdg';
            var applet = spt.Applet.get();


            spt.app_busy.show("Choose file(s) to check in")


            var current_dir = null;
            var is_sandbox = false;
            var refresh = false
            var values = spt.checkin.browse_folder(current_dir, is_sandbox, refresh);
            if (!values) {
                spt.app_busy.hide();
                return;
            }

            var file_paths = values.file_paths;
            if (file_paths.length == 0) {
                spt.alert("You need to select files(s) to check in.");
                spt.app_busy.hide();
                return;
            }

            spt.app_busy.hide();

            var args = {
                'search_key': bvr.search_key,
                'show_links': false,
                'show_history': false,
                'close_on_publish': true
            }
            if (bvr.process) args.process = bvr.process;
            if (bvr.context) args.context = bvr.context;

            var kwargs = {};
            kwargs.values = values;
            spt.panel.load_popup("Check-in", class_name, args, kwargs);

            /*
            var options=  {
                title: "Check-in Widget",
                class_name: 'tactic.ui.widget.CheckinWdg',
                popup_id: 'checkin_widget'
            };
            var bvr2 = {};
            bvr2.options = options;
            bvr2.values = values;
            bvr2.args = args;
            spt.popup.get_widget({}, bvr2)

            */

            '''
        } )


        button_div = DivWdg()
        content.add(button_div)
        button = IconWdg(title="Check-Out", icon=IconWdg.CHECK_OUT_3D_LG)
        button_div.add(button)
        button_div.set_box_shadow("1px 1px 1px 1px")
        button_div.add_style("width: 60px")
        button_div.add_style("height: 60px")
        button_div.add_style("float: left")
        button_div.add_style("margin: 20px")
        button_div.add_style("padding: 2px 3px 0 0")
        button_div.add_style("background: white")
        button_div.add_class("hand")

        button_div.add_style("text-align: center")
        button_div.add("Check-out")

       
        sobject = SearchKey.get_by_search_key(search_key)

        # snapshot is retrieved for getting the process informatoin, they are not being used
        # for loading as real_time snapshot query option is used. 
        search = Search("sthpw/snapshot")
        search.add_sobject_filter(sobject)
        if my.process:
            search.add_filter("process", my.process)
        search.add_filter("is_latest", True)
        snapshot = search.get_sobject()

        if not my.process and snapshot:
            my.process = snapshot.get_value('process')
            # for old process-less snapshots
            if not my.process:
                my.process = snapshot.get_value('context')

        process_wdg = DivWdg(HtmlElement.b(checkin_process))
        if checkin_process:
            width = len(checkin_process)*10
        else:
            width = 10
        process_wdg.add_styles('margin-left: auto; margin-right: auto; text-align: center; width: %s'%width)
        process_div.add(process_wdg)
        # DO NOT pass in snapshot_code, get it in real time

        snapshot_codes = []
   
        show_status = True
        if my.checkout_action == 'latest':
            cbjs_action = CheckinSandboxListWdg.get_checkout_cbjs_action(my.process, show_status)
            bvr = {'snapshot_codes': snapshot_codes,
                    'real_time': True,
                    'file_types': ['main'],
                    'filename_mode': 'repo',
                    'cbjs_action': cbjs_action}

        elif my.checkout_action == 'latest (version_omitted)':
            cbjs_action = CheckinSandboxListWdg.get_checkout_cbjs_action(my.process, show_status)
            bvr = {'snapshot_codes':snapshot_codes,
                    'real_time': True,
                    'file_types': ['main'],
                    'filename_mode': 'versionless',
                    'cbjs_action': cbjs_action}

        elif my.checkout_action == 'latest versionless':
            cbjs_action = CheckinSandboxListWdg.get_checkout_cbjs_action(my.process, show_status)
            bvr = {'snapshot_codes':snapshot_codes,
                    'real_time': True,
                    'versionless': True,
                    'file_types': ['main'],
                    'filename_mode': 'versionless',
                    'cbjs_action': cbjs_action}
       
        elif my.checkout_action == 'open file browser':
            bvr =  {
           
            'cbjs_action': '''
            var class_name = 'tactic.ui.checkin.SObjectDirListWdg';
            var kwargs = {
                search_keys: [bvr.search_key],
                process: '%s' 
            };
            spt.panel.load_popup("Check-out", class_name, kwargs);
            '''%my.process
            }
        bvr.update({ 'type': 'click_up', 'search_key': search_key})
        button.add_behavior(bvr)
        title = Common.get_display_title(my.checkout_action)
        button.add_attr('title', title)


        
        #TODO: remove these margin-top which is used to compensate all the ButtonNewWdg top extra white space
        
        content.add("<br clear='all'/>")
        status_div = DivWdg()
        status_div.add_style('margin: 20px 0 0 10px')
        status_div.add_style('width: 100%')
        text_info = FloatDivWdg()
        text_info.add_styles('padding: 4px; width: 500px')
        text_info.add_style('margin-top: 8px')
        text_info.add_attr('title','Displays the last checked out file path')

        text_info.add_border()
        text_info.set_round_corners()

        text_content = DivWdg()
        text_content.add('&nbsp;')
        text_content.add_class('spt_status_area')

        text_info.add(text_content)
        label = FloatDivWdg('path:')
        label.add_style('margin: 12px 6px 0 6px')

        # button
        button = ButtonNewWdg(title="Explore", icon=IconWdg.FOLDER_GO)
        button.add_style('padding-bottom: 15px')
        button.add_behavior( {
        'type': 'click_up',
        'cbjs_action': '''
            var applet = spt.Applet.get();
            var status_div = bvr.src_el.getParent('.spt_simple_checkin').getElement('.spt_status_area');
            var value = status_div.get('text');

            var dir_name = spt.path.get_dirname(value);
            if (dir_name)
                applet.open_explorer(dir_name);
        '''
        } )

        status_div.add(label)
        status_div.add(text_info)
        content.add(status_div)
        content.add(button)
    

        content.add_behavior({'type':'load',
            'cbjs_action': ''' 
            
            if (!spt.Applet.applet) {
                spt.api.app_busy_show('Initializing Java', 'Please wait...');
                var exec = function() {var applet = spt.Applet.get()};
                spt.api.app_busy_hide(exec);
            }'''})
        
        return top