当前位置: 首页>>代码示例>>Python>>正文


Python search.SObjectFactory类代码示例

本文整理汇总了Python中pyasm.search.SObjectFactory的典型用法代码示例。如果您正苦于以下问题:Python SObjectFactory类的具体用法?Python SObjectFactory怎么用?Python SObjectFactory使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了SObjectFactory类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: create

    def create(sobject, value, prev_value=None):
        if prev_value == value:
            return

        # if this is successful, the store it in the status_log
        search_type = sobject.get_search_type()
        search_id = sobject.get_id()
        search_code = sobject.get_value("code")

        status_log = SObjectFactory.create("sthpw/status_log")
        status_log.set_value("login", Environment.get_user_name() )

        status_log.set_sobject_value(sobject)
        #status_log.set_value("search_type", search_type)
        #status_log.set_value("search_code", search_id, no_exception=True)
        #status_log.set_value("search_id", search_code, no_exception=True)

        if prev_value:
            status_log.set_value("from_status", prev_value)

        status_log.set_value("to_status", value)

        project_code = Project.get_project_name()
        status_log.set_value("project_code", project_code)

        status_log.commit()

        return status_log
开发者ID:blezek,项目名称:TACTIC,代码行数:28,代码来源:status.py

示例2: execute

    def execute(self):

        left_cb_name , right_cb_name = self.get_checkbox_names()
        
        web = WebContainer.get_web()

        right_search_keys = web.get_form_values(right_cb_name)
        if not right_search_keys:
            return

        right_sobjects = []
        for right_search_key in right_search_keys:
            right_sobject = Search.get_by_search_key(right_search_key)
            right_sobjects.append(right_sobject)

        search_type = self.get_search_type()

        left_search_keys = web.get_form_values(left_cb_name)
        for left_search_key in left_search_keys:

            left_sobject = Search.get_by_search_key( left_search_key )
            for right_sobject in right_sobjects:
                #instance_name = "%s" % right_sobject.get_value("name")

                left_foreign_key = left_sobject.get_foreign_key()
                right_foreign_key = right_sobject.get_foreign_key()

                instance = SObjectFactory.create(search_type)
                instance.set_value(left_foreign_key, left_sobject.get_code() )
                instance.set_value(right_foreign_key, right_sobject.get_code() )

                name = left_sobject.get_code()
                instance.set_value("name", name)
                instance.commit()
开发者ID:mincau,项目名称:TACTIC,代码行数:34,代码来源:sobject_planner_wdg.py

示例3: _create_timecard

 def _create_timecard(my, search_type, search_id):
     '''create an entry in the timecard table'''
     timecard = SObjectFactory.create("sthpw/timecard")
     timecard.set_value("search_type", search_type)
     timecard.set_value("search_id", search_id)
     timecard.set_value('login', Environment.get_user_name())
     timecard.set_value('project_code', Project.get_project_name()) 
     return timecard
开发者ID:0-T-0,项目名称:TACTIC,代码行数:8,代码来源:timecard_wdg.py

示例4: create_grouping

 def create_grouping(my, item_value, container_value):
     grouping = my._get_existing_grouping(item_value, container_value)
     if grouping:
         return grouping
     sobject = SObjectFactory.create( my.grouping_search_type )
     sobject.set_value( my.item_foreign_key, item_value)
     sobject.set_value( my.container_foreign_key, container_value)
     sobject.commit()
     return sobject
开发者ID:0-T-0,项目名称:TACTIC,代码行数:9,代码来源:sobject_group_wdg.py

示例5: execute

    def execute(my):

        web = WebContainer.get_web()
        
        # get the input names
        input_names = web.get_form_value(SerialStatusWdg.STATUS_CMD_INPUT).split('|')
        
        values = []
        for input_name in input_names:
            value = web.get_form_value(input_name)
            if value:
                values.append(web.get_form_value(input_name))
            
       
        # FIXME: HARDCODED Value for status column!!!!
        column = "status"

        for value in values:
            # get the sobject to be updated
            search_type,id,status = value.split("|")
            search = Search(search_type)
            search.add_id_filter(id)
            my.sobject = search.get_sobject()
            
            status_attr = my.sobject.get_attr(column)

            cur_status = status_attr.get_current_process()
            if cur_status == status:
                continue

            status_attr.set_status(status)
           
            update_column = 'time_update'
            if update_column in my.sobject.get_attr_names():
                my.sobject.set_value(update_column, Sql.get_timestamp_now(), quoted=False)
            my.sobject.commit()

           
            # if this is successful, the store it in the status_log
            status_log = SObjectFactory.create("sthpw/status_log")
            status_log.set_value("login", Environment.get_user_name() )
            status_log.set_value("search_type", search_type)
            status_log.set_value("search_id", id)
            #status_log.set_value("status", "%s to %s" % (cur_status, status) )
            status_log.commit()
            status_log.set_value("from_status", cur_status)
            status_log.set_value("to_status", status)

            # Call the finaled trigger
            Trigger.call(my, status)
开发者ID:0-T-0,项目名称:TACTIC,代码行数:50,代码来源:serial_status.py

示例6: check

    def check(my):
        # make this a callback for now
        my.init() 
       
        # check for required columns
        sobj = SObjectFactory.create(my.search_type)
        required_columns = sobj.get_required_columns()
        for required in required_columns:
            if required in my.columns:
                continue
            else:
                raise UserException('Missing required column [%s] in the input CSV' % required)

        return True
开发者ID:CeltonMcGrath,项目名称:TACTIC,代码行数:14,代码来源:csv_import_cmd.py

示例7: execute_slave

    def execute_slave(self, command):
        import socket, xmlrpclib, pickle, time
        pickled = pickle.dumps(command)

        queue = SObjectFactory.create("sthpw/queue")
        queue.set_value("queue", "render")
        queue.set_value("state", "pending")
        queue.set_value("command", command.__class__.__name__)
        queue.set_value("serialized", pickled)

        queue.set_value("priority", "AAA")
        queue.set_value("description", self.description)

        queue.set_user()
        queue.commit()
开发者ID:mincau,项目名称:TACTIC,代码行数:15,代码来源:remote_command.py

示例8: postprocess

    def postprocess(self):

        sobject = self.sobject

        if not sobject.is_insert():
            return


        processes = ["layout", "animation", "lighting"]

        # create a bunch of tasks
        for process in processes:
            task = SObjectFactory.create("sthpw/task")
            task.set_value("description", process)
            task.set_value("process", process)
            task.set_sobject_value(sobject)
            task.commit()
开发者ID:mincau,项目名称:TACTIC,代码行数:17,代码来源:task_create_action.py

示例9: log_exception

    def log_exception(my, exception):
        import sys,traceback
        tb = sys.exc_info()[2]
        stacktrace = traceback.format_tb(tb)
        stacktrace_str = "".join(stacktrace)
        print "-"*50
        print stacktrace_str
        print str(exception)
        print "-"*50

        user_name = Environment.get_user_name()
        exception_log = SObjectFactory.create("sthpw/exception_log")
        exception_log.set_value("login", user_name)
        exception_log.set_value("class", exception.__class__.__name__)
        exception_log.set_value("message", str(exception) )

        exception_log.set_value("stack_trace", stacktrace_str)

        exception_log.commit()

        del tb, stacktrace
开发者ID:talha81,项目名称:TACTIC-DEV,代码行数:21,代码来源:app_server.py

示例10: execute

    def execute(my):

        web = WebContainer.get_web()
        if web.get_form_value("Register") == "":
            raise CommandExitException()



        # hard code this to tasks for now
        search_type = "sthpw/task"

        info = {}
        for key in web.get_form_keys():

            # filter out unwanted keys
            if not key.startswith("timecard|"):
                continue

            value = web.get_form_value(key)
            if value == "":
                continue

            tmp, search_id, col = key.split("|")
            if not info.has_key(search_id):
                info[search_id] = []

            info[search_id].append( (col,value) )


        for search_id, values in info.items():
            timecard = SObjectFactory.create("sthpw/timecard")
            timecard.set_value("search_type", search_type)
            timecard.set_value("search_id", search_id)

            for value in values:
                timecard.set_value(value[0],value[1])

            timecard.commit()
开发者ID:0-T-0,项目名称:TACTIC,代码行数:38,代码来源:timecard_wdg.py

示例11: log

    def log(cls, level, message, category="default"):
        assert level in ("critical", "error", "warning", "info", "debug")

        # record the exception
        user_name = Environment.get_user_name()
        if not user_name:
            user_name = "UNKNOWN"

        # put the debug in a completely separate transaction from the main
        # transaction
        transaction = Transaction.get(force=True)
        transaction.set_record(False)

        debug_log = SObjectFactory.create("sthpw/debug_log")
        debug_log.set_value("login", user_name)
        debug_log.set_value("level", level)
        debug_log.set_value("category", category)
        debug_log.set_value("message", message )
        debug_log.commit()

        transaction.commit()
        transaction.remove_from_stack()

        return debug_log
开发者ID:0-T-0,项目名称:TACTIC,代码行数:24,代码来源:debug_log.py

示例12: get_display


#.........这里部分代码省略.........
        view_select.add_event("onchange", "document.form.submit()")
        view_select.set_persist_on_submit()
        #view_select.set_persistence()
        span = SpanWdg(css="med")
        span.add("Defined Views: ")
        span.add(view_select)
        div.add(span)

        div.add( self.get_create_view_wdg(search_type))

        div.add( HtmlElement.br(2) )


        div.add( self.get_new_tab_wdg() )


        widget.add(div)

        search = Search("sthpw/widget_config")
        #search.add_user_filter()
        search.add_filter("search_type", search_type)
        search.add_where("view != 'definition' and view != 'custom'")
        #search.add_column("view")
        widget_configs = search.get_sobjects()
        if widget_configs:
            view_select.set_sobjects_for_options(widget_configs,"view","view")
        view = view_select.get_value()
        if not view:
            view = "custom"
            #return widget

        # get the selected widget config
        for widget_config in widget_configs:
            if widget_config.get_value("view") == view:
                break
        else:
            return widget

        # get the handler: a little HACKY.
        config_xml = widget_config.get_xml_value("config")
        handler = config_xml.get_value("config/%s/@handler" % view)

        if not search_type:
            return widget

        widget.add(HtmlElement.br())
        span = SpanWdg()
        custom_view = CustomViewWdg(search_type)
        span.add(custom_view)
        span.add_style("float: right")
        widget.add(span)


        widget.add( HtmlElement.br() )
        widget.add("<h3>Example View [%s]</h3>" % view)

        # add a general filter
        filter_div = DivWdg()
        for i in range(0,1):
            filter = GeneralFilterWdg()
            filter.set_columns_from_search_type(search_type)
            filter_div.add("Filter: ")
            filter_div.add(filter)
            #filter_div.add(IconWdg("Remove Filter", IconWdg.RETIRE))
            filter_div.add( HtmlElement.br(2) )

        widget.add(filter_div)

        search = Search(search_type)
        search.set_limit(5)
        filter.alter_search(search)

        
        if not handler:
            if view in ["edit","insert"]:
                table = EditWdg(search_type, view)
            else:
                table = TableWdg(search_type, view)
        else:
            table = eval("%s(search_type,view)" % handler)

        #table.alter_search(search)
        sobjects = search.get_sobjects()

        if not sobjects and view in ["edit","insert"]:
            sobjects = [SObjectFactory.create(search_type)]
        table.set_sobjects(sobjects)
        widget.add(table)

        # show the custom properties
        widget.add("<h3>Custom Properties [%s]</h3>" % search_type)
        search = Search("prod/custom_property")
        search.add_filter("search_type", search_type)
        # This is actually reading the sthpw/custom_property conf file, weird
        table = TableWdg("prod/custom_property")
        table.set_search_limit(5)
        table.set_sobjects(search.get_sobjects() )
        widget.add(table)

        return widget
开发者ID:mincau,项目名称:TACTIC,代码行数:101,代码来源:custom_view_app_wdg.py

示例13: execute

    def execute(my):
        if not my.initialized:
            my.init()

        assert my.search_type
        assert my.file_path
        assert my.columns

        csv_parser = CsvParser(my.file_path)
        if my.has_title:
            csv_parser.set_has_title_row(True)
        else:
            csv_parser.set_has_title_row(False)

        if my.encoder:
            csv_parser.set_encoder(my.encoder)

        csv_parser.parse()

        # get the data and columns
        #csv_titles = csv_parser.get_titles()
        csv_data = csv_parser.get_data()
        # make sure all of the new columns are created
        csv_titles = []
        for i, column in enumerate(my.columns):
            if not column:
                new_column = my.new_columns[i]
                new_column_type = my.new_column_types[i]
                if new_column and new_column not in ['id', 'code'] and\
                    i in my.enabled_idx:
                    # create the new column
                    from pyasm.command import ColumnAddCmd
                    #col_type = "Name/Code"
                    cmd = ColumnAddCmd(my.search_type, new_column, new_column_type)
                    cmd.execute()

                    # create the sobject for now
                    sobject = SObjectFactory.create("prod/custom_property")
                    sobject.set_value("search_type", my.search_type)
                    sobject.set_value("name", new_column)
                    sobject.set_value("description", new_column)
                    sobject.commit()

                csv_titles.append( my.new_columns[i] )
            else:
                csv_titles.append( column )

        try:
            id_col = csv_titles.index(my.id_col)
            # id is special we want it to be identifiable at all times
            # but not importable
            if my.id_col != 'id' and id_col not in my.enabled_idx:
                id_col = -1
        except ValueError:
            id_col = -1

        new_entries = []
        updated_entries = []
        error_entries = []
        error = False
 
        # create entries or update values
        for row_count, row in enumerate(csv_data):
            sobject = None
            # if id_col doesn't exist
            is_new_entry = False
            
            if id_col == -1:
                sobject = SObjectFactory.create(my.search_type)
                is_new_entry = True
            else:
                id = row[id_col]
                if id:
                    # this essentially updates the current sobject in db
                    if my.id_col=='code':
                        sobject = Search.get_by_code(my.search_type, id.strip())
                    elif my.id_col=='id':
                        sobject = Search.get_by_id(my.search_type, id.strip())
                    else:
                        u_search = Search(my.search_type)
                        u_search.add_filter(my.id_col, id.strip())
                        sobject = u_search.get_sobject()
                    #assert sobject
                # in case a previously exported sobject with this code
                # or id has been deleted or it is a completely foreign code
                # or id, sobject will be None
                else: # skip if empty id or code
                    continue
                  
                if not sobject:
                    sobject = SObjectFactory.create(my.search_type)
                    is_new_entry = True

            new_columns = 0
            note = None
            for cell_count, cell in enumerate(row):
                '''
                column_override = my.columns[cell_count]

                if column_override:
#.........这里部分代码省略.........
开发者ID:CeltonMcGrath,项目名称:TACTIC,代码行数:101,代码来源:csv_import_cmd.py

示例14: get_upload_wdg

    def get_upload_wdg(my):
        widget = Widget()

        # get the search type
        widget.add( "1. Select type of asset: ")

        # handle new search_types
        new_search_type = CheckboxWdg("new_search_type_checkbox")
        new_search_type.add_event("onclick", "toggle_display('new_search_type_div')")
        #span = SpanWdg(css="med")
        #span.add(new_search_type)
        #span.add("Create new type")
        #span.add(" ... or ... ")
        #widget.add(span)

        new_search_type_div = DivWdg()
        new_search_type_div.set_id("new_search_type_div")

        name_input = TextWdg("asset_name")
        title = TextWdg("asset_title")
        description = TextAreaWdg("asset_description")

        table = Table()
        table.add_style("margin: 10px 20px")
        table.add_col().set_attr('width','140')
        table.add_col().set_attr('width','400')
        
        table.add_row()
        table.add_header("Search Type: ").set_attr('align','left')
        table.add_cell(name_input)
        table.add_row()
        table.add_header("Title: ").set_attr('align','left')
        table.add_cell(title)
        table.add_row()
        table.add_header("Description: ").set_attr('align','left')
        table.add_cell(description)
        new_search_type_div.add(table)
        new_search_type_div.add_style("display: none")
        #widget.add(new_search_type_div)


        # or use a pre-existing one
        search_type_select = SearchTypeSelectWdg("filter|search_type")
        search_type_select.add_empty_option("-- Select --")
        search_type_select.set_persist_on_submit()
        search_type_select.set_submit_onchange()
        widget.add(search_type_select)
        

        my.search_type = search_type_select.get_value()
        if my.search_type:
            sobj = SObjectFactory.create(my.search_type)
            required_columns = sobj.get_required_columns()
            
            widget.add(SpanWdg("Required Columns: ", css='med'))
            if not required_columns:
                required_columns = ['n/a']
            widget.add(SpanWdg(', '.join(required_columns), css='med'))

        widget.add( HtmlElement.br(2) )
        widget.add( "2. Upload a csv file: ")
        upload_wdg = HtmlElement.upload("uploaded_file")
        widget.add(upload_wdg)
        submit = IconSubmitWdg("Upload", IconWdg.UPLOAD, True)
        widget.add(submit)

        web = WebContainer.get_web()
        field_storage = web.get_form_value("uploaded_file")
        if field_storage != "":
            upload = FileUpload()
            upload.set_field_storage(field_storage)
            upload.set_create_icon(False)
            upload.execute()

            files = upload.get_files()
            if files:
                my.file_path = files[0]
            else:
                my.file_path = web.get_form_value("file_path")


        if my.file_path:
            hidden = HiddenWdg("file_path", my.file_path)
            widget.add(hidden)

        return widget
开发者ID:0-T-0,项目名称:TACTIC,代码行数:86,代码来源:csv_import_wdg.py

示例15: get_first_row_wdg

    def get_first_row_wdg(my):

        # read the csv file
        my.file_path = ""

        div = DivWdg()

        div.add( my.get_upload_wdg() )

        if not my.search_type:
            return div

        if not my.file_path:
            return div


        if not my.file_path.endswith(".csv"):
            div.add( "Uploaded file [%s] is not a csv file"% my.file_path)
            return div

        if not os.path.exists(my.file_path):
            raise Exception("Path '%s' does not exists" % my.file_path)

        div.add(HtmlElement.br(2))

        div.add( HtmlElement.b("The following is taken from first line in the uploaded csv file.  Select the appropriate column to match.") )
        div.add(HtmlElement.br())
        div.add(  HtmlElement.b("Make sure you have all the required columns** in the csv."))
        option_div = DivWdg()
        
        option_div.add_style("float: left")
        option_div.add_style("margin-right: 30px")

        option_div.add("<p>3. Parsing Options:</p>")

        my.search_type_obj = SearchType.get(my.search_type)


        # first row and second row
        option_div.add( HtmlElement.br(2) )
        option_div.add("Use Title Row: ")
        title_row_checkbox = FilterCheckboxWdg("has_title")
        title_row_checkbox.set_default_checked()
        option_div.add(title_row_checkbox)
        option_div.add( HintWdg("Set this to use the first row as a title row to match up columns in the database") )
        
        option_div.add( HtmlElement.br(2) )
        option_div.add("Sample Data Row: ")
        data_row_text = TextWdg("data_row")
        data_row_text.set_attr("size", "3")
        option_div.add(data_row_text)
        option_div.add( HintWdg("Set this as a sample data row to match the columns to the database") )

        option_div.add( HtmlElement.br(2) )
        
       
        div.add(option_div)
        my.has_title = title_row_checkbox.is_checked()
        
        
        # parse the first fow
        csv_parser = CsvParser(my.file_path)
        if my.has_title:
            csv_parser.set_has_title_row(True)
        else:
            csv_parser.set_has_title_row(False)
        csv_parser.parse()
        csv_titles = csv_parser.get_titles()
        csv_data = csv_parser.get_data()



        data_row = data_row_text.get_value()
        if not data_row:
            data_row = 0
        else:
            try:
                data_row = int(data_row)
            except ValueError:
                data_row = 0

            if data_row >= len(csv_data):
                data_row = len(csv_data)-1
        data_row_text.set_value(data_row)




        table = Table()
        table.set_attr("cellpadding", "10")

        table.add_row()
        table.add_header("CSV Column Value")
        table.add_header("TACTIC Column")
        table.add_header("Create New Column")
        
        columns = my.search_type_obj.get_columns()
        search_type = my.search_type_obj.get_base_search_type()
        sobj = SObjectFactory.create(search_type)
        required_columns = sobj.get_required_columns()
#.........这里部分代码省略.........
开发者ID:0-T-0,项目名称:TACTIC,代码行数:101,代码来源:csv_import_wdg.py


注:本文中的pyasm.search.SObjectFactory类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。