示例#1
0
    def _get_sobject_history_wdg(my):
        ''' this method is called thru ajax '''
        args = WebContainer.get_web().get_form_args()
        
        # get the args in the URL
        search_type = args['search_type']
        search_id = args['search_id']
        #sobject = Search.get_by_id(search_type, search_id)

        div = Widget()

        search = Search("sthpw/sobject_log")
        search.add_filter("search_type", search_type)
        search.add_filter("search_id", search_id)
        sobjects = search.get_sobjects()

        search = Search("sthpw/transaction_log")
        search.add_filters("id", [x.get_value("transaction_log_id") for x in sobjects] )
        sobjects = search.get_sobjects()


        table = TableWdg("sthpw/transaction_log", "table", css='table')
        table.set_show_property(False)
        table.set_sobjects(sobjects)
        div.add(table)
        div.add(HtmlElement.br(2))

        return div

     
        div.add(assigned_shot_wdg)
        div.add(HtmlElement.br(2))
        return div
示例#2
0
    def preprocess(my):
       
        my.is_preprocessed = True
        # get all of the instances

        search = Search("prod/shot_instance")

        # if not used in a TableWdg, only get the shot instances for one asset
        if not my.parent_wdg:
            search.add_filter('asset_code', my.get_current_sobject().get_code())

        search.add_order_by("shot_code")
        instances = search.get_sobjects()

        my.asset_instances = instances

        my.instances = {}
        for instance in instances:
            asset_code = instance.get_value("asset_code")
            
            list = my.instances.get(asset_code)
            if not list:
                list = []
                my.instances[asset_code] = list

            list.append(instance)
       
        search = Search("prod/shot")
        search.add_filters( "code", [x.get_value('shot_code') for x in instances] )
        shots = search.get_sobjects()
        my.shots = SObject.get_dict(shots, ["code"])
        my.shots_list = shots
示例#3
0
    def _get_sobject_history_wdg(self):
        ''' this method is called thru ajax '''
        args = WebContainer.get_web().get_form_args()

        # get the args in the URL
        search_type = args['search_type']
        search_id = args['search_id']
        #sobject = Search.get_by_id(search_type, search_id)

        div = Widget()

        search = Search("sthpw/sobject_log")
        search.add_filter("search_type", search_type)
        search.add_filter("search_id", search_id)
        sobjects = search.get_sobjects()

        search = Search("sthpw/transaction_log")
        search.add_filters(
            "id", [x.get_value("transaction_log_id") for x in sobjects])
        sobjects = search.get_sobjects()

        table = TableWdg("sthpw/transaction_log", "table", css='table')
        table.set_show_property(False)
        table.set_sobjects(sobjects)
        div.add(table)
        div.add(HtmlElement.br(2))

        return div

        div.add(assigned_shot_wdg)
        div.add(HtmlElement.br(2))
        return div
示例#4
0
    def get_connections(cls,
                        sobjects,
                        direction="dst",
                        context='',
                        context_filters=[],
                        src_search=None):
        '''return a Search instance if src_search is provided'''
        if not sobjects and not src_search:
            return []
        search = Search(SObjectConnection)

        if direction == "dst":
            prefix = "src"
        else:
            prefix = "dst"

        if src_search:
            search.add_filter("%s_search_type" % prefix,
                              src_search.get_search_type())
            search.add_search_filter('%s_search_id' % prefix,
                                     src_search,
                                     op="in")
        else:
            search_types = [x.get_search_type() for x in sobjects]
            search_ids = [x.get_id() for x in sobjects]

            if len(Common.get_unique_list(search_types)) == 1:
                search.add_filter("%s_search_type" % prefix, search_types[0])
                search.add_filters("%s_search_id" % prefix, search_ids)
            else:
                search.add_op("begin")
                for search_type, search_id in zip(search_types, search_ids):
                    search.add_op("begin")
                    search.add_filter("%s_search_type" % prefix, search_type)
                    search.add_filter("%s_search_id" % prefix, search_id)
                    search.add_op("and")
                search.add_op("or")

        if context:
            search.add_filter("context", context)
        elif context_filters:
            search.add_op_filters(context_filters)

        if src_search:
            return search

# cache for connection sobjects
        key = search.get_statement()
        cache = Container.get("SObjectConnection:cache")
        if cache == None:
            cache = {}
            Container.put("SObjectConnection:cache", cache)

        ret_val = cache.get(key)
        if ret_val != None:
            return ret_val

        connections = search.get_sobjects()

        return connections
示例#5
0
    def get_subscriptions(my, category, mode="new"):

        search = Search("sthpw/subscription")
        search.add_user_filter()
        if category:
            search.add_filter("category", category)



        if mode == "new":
            search.add_op("begin")
            search.add_filter("last_cleared", '"message"."timestamp"', quoted=False, op="<")
            search.add_filter("last_cleared", "NULL", quoted=False, op="is")
            search.add_op("or")


            #project_code = Project.get_project_code()
            #search.add_filter("project_code", project_code )

            # use an inner join because if there are no messages, we don't
            # want the subscription
            search.add_order_by("message.timestamp", direction="desc", join="INNER")

            # don't show user message except when category is certain values
            user = Environment.get_user_name()
            search.add_op("begin")
            search.add_filter("login", user, op="!=", table="message")
            search.add_filters("category", ["script","default","sobject"], table="message")
            search.add_op("or")
        else:
            search.add_order_by("message.timestamp", direction="desc")

        subscriptions = search.get_sobjects()

        return subscriptions
示例#6
0
    def get_tasks(my, sobjects=[]):

        # get all of the relevant tasks to the user
        task_search = Search("sthpw/task")
        task_search.add_column("search_id", distinct=True)

        if sobjects:
            task_search.add_filter("search_type",
                                   sobjects[0].get_search_type())
            sobject_ids = SObject.get_values(sobjects, "id", unique=True)
            task_search.add_filters("search_id", sobject_ids)

        # only look at this project
        search_type = SearchType.get(my.search_type).get_full_key()
        task_search.add_filter("search_type", search_type)

        my.process_filter.alter_search(task_search)
        if isinstance(my.user_filter, UserFilterWdg):
            my.user_filter.alter_search(task_search)
        else:
            user = Environment.get_user_name()
            task_search.add_filter('assigned', user)

        status_filters = my.task_status_filter.get_values()

        if not status_filters:
            return []

        task_search.add_filters("status", status_filters)

        tasks = task_search.get_sobjects()

        return tasks
示例#7
0
    def preprocess(self):

        self.is_preprocessed = True
        # get all of the instances

        search = Search("prod/shot_instance")

        # if not used in a TableWdg, only get the shot instances for one asset
        if not self.parent_wdg:
            search.add_filter('asset_code',
                              self.get_current_sobject().get_code())

        search.add_order_by("shot_code")
        instances = search.get_sobjects()

        self.asset_instances = instances

        self.instances = {}
        for instance in instances:
            asset_code = instance.get_value("asset_code")

            list = self.instances.get(asset_code)
            if not list:
                list = []
                self.instances[asset_code] = list

            list.append(instance)

        search = Search("prod/shot")
        search.add_filters("code",
                           [x.get_value('shot_code') for x in instances])
        shots = search.get_sobjects()
        self.shots = SObject.get_dict(shots, ["code"])
        self.shots_list = shots
示例#8
0
    def get_display(self):

        sobject = self.get_current_sobject()
        sobject = sobject.get_parent()
        if not sobject:
            return Widget()

        # get all of the sobject_logs
        search = Search("sthpw/sobject_log")
        search.add_sobject_filter(sobject)
        logs = search.get_sobjects()

        search = Search("sthpw/transaction_log")
        search.add_filters("id",
                           [x.get_value("transaction_log_id") for x in logs])
        search.set_limit(200)
        logs = search.get_sobjects()

        from layout_wdg import TableWdg
        widget = Widget()
        table = TableWdg("sthpw/transaction_log")
        table.add_class("minimal")
        table.set_header_flag(False)
        table.set_show_property(False)
        table.set_no_results_wdg("&nbsp;")
        table.set_sobjects(logs)
        widget.add(table)
        return widget
示例#9
0
    def get_output_tasks(my, type=None):

        process = my.get_value("process")
        parent = my.get_parent()

        # get the pipeline
        pipeline_code = parent.get_value("pipeline_code", no_exception=True)
        if not pipeline_code:
            return []

        pipeline = Pipeline.get_by_code(pipeline_code)
        if not pipeline:
            return []

        processes = pipeline.get_output_processes(process, type=type)
        if not processes:
            return []

        tasks = []

        process_names = [x.get_name() for x in processes]

        search = Search("sthpw/task")
        search.add_filters("process", process_names)
        search.add_parent_filter(parent)
        tasks = search.get_sobjects()

        return tasks
示例#10
0
    def get_display(my):

        #project = Project.get()
        schema = Schema.get()
        # no hierarchy to prevent all sthpw and parent sTypes
        search_type_names = schema.get_search_types(hierarchy=False)
        search = Search('sthpw/search_object')
        search.add_filters('search_type', search_type_names)
        search_types = search.get_sobjects()

        task_search_type = SearchType.get("sthpw/task")
        search_types.append(task_search_type)

        values = [x.get_value("search_type") for x in search_types]
        labels = []
        for x in search_types:
            label = "%s (%s)" % (x.get_value("title"),
                                 x.get_value("search_type"))
            labels.append(label)

        sobject = my.get_current_sobject()
        if not sobject:
            value = ""
        else:
            value = sobject.get_value(my.get_name())

        my.set_option("values", values)
        my.set_option("labels", labels)
        my.add_empty_option("-- Select --")
        if value:
            my.set_value(value)

        return super(SearchTypeInputWdg, my).get_display()
示例#11
0
    def preprocess(self):

        sobjects = self.sobjects
        if not sobjects:
            return

        # find all of the instances in a shot
        sobject = sobjects[0]
        foreign_key = sobject.get_foreign_key()

        search_type = WebState.get().get_state("planner_search_type")
        search = Search(search_type)

        search.add_column(foreign_key)

        if len(sobjects) == 1:
            search.add_filter(foreign_key, sobject.get_code())
        else:
            search_codes = [x.get_code() for x in sobjects]
            search.add_filters(foreign_key, search_codes)

        search_type = sobject.get_search_type()
        search.add_order_by(foreign_key)
        children = search.get_sobjects()

        # convert to a dictionary
        for child in children:
            code = child.get_value(foreign_key)
            number = self.numbers.get(code)
            if not number:
                number = 0

            number += 1
            self.numbers[code] = number
示例#12
0
    def get_subscriptions(self, category, mode="new"):

        search = Search("sthpw/subscription")
        search.add_user_filter()
        if category:
            search.add_filter("category", category)



        if mode == "new":
            search.add_op("begin")
            search.add_filter("last_cleared", '"message"."timestamp"', quoted=False, op="<")
            search.add_filter("last_cleared", "NULL", quoted=False, op="is")
            search.add_op("or")


            #project_code = Project.get_project_code()
            #search.add_filter("project_code", project_code )

            # use an inner join because if there are no messages, we don't
            # want the subscription
            search.add_order_by("message.timestamp", direction="desc", join="INNER")

            # don't show user message except when category is certain values
            user = Environment.get_user_name()
            search.add_op("begin")
            search.add_filter("login", user, op="!=", table="message")
            search.add_filters("category", ["script","default","sobject","progress"], table="message")
            search.add_op("or")
        else:
            search.add_order_by("message.timestamp", direction="desc")

        subscriptions = search.get_sobjects()
        return subscriptions
示例#13
0
    def get_display(self):

        sobject = self.get_current_sobject()
        sobject = sobject.get_parent()
        if not sobject:
            return Widget()

        # get all of the sobject_logs
        search = Search("sthpw/sobject_log")
        search.add_sobject_filter(sobject)
        logs = search.get_sobjects()

        search = Search("sthpw/transaction_log")
        search.add_filters("id", [x.get_value("transaction_log_id") for x in logs] )
        search.set_limit(200)
        logs = search.get_sobjects()
        
        from layout_wdg import TableWdg
        widget = Widget()
        table = TableWdg("sthpw/transaction_log")
        table.add_class("minimal")
        table.set_header_flag(False)
        table.set_show_property(False)
        table.set_no_results_wdg( "&nbsp;" )
        table.set_sobjects(logs)
        widget.add(table)
        return widget
示例#14
0
    def get_sobjects(my, connections, direction='dst', filters=None, return_search=False):

        if not connections:
            return []

        if direction == "dst":
            prefix = "dst"
        else:
            prefix = "src"

        search_type = connections[0].get_value("%s_search_type" % prefix)

        search = Search(search_type)
        search_ids = [x.get_value("%s_search_id" % prefix) for x in connections]
        search.add_filters("id", search_ids )

        if filters:
            search.add_op_filters(filters)

        if return_search:
            return search

        sobjects = search.get_sobjects()

        return sobjects
示例#15
0
    def execute(my):

        my.collection_key = my.kwargs.get("collection_key")
        my.search_keys = my.kwargs.get("search_keys")

        collection = Search.get_by_search_key(my.collection_key)
        collection_code = collection.get("code")
        sobjects = Search.get_by_search_keys(my.search_keys)
        search_codes = [x.get_code() for x in sobjects]


        search_type = collection.get_base_search_type()
        parts = search_type.split("/")
        collection_type = "%s/%s_in_%s" % (parts[0], parts[1], parts[1])

        search = Search(collection_type)
        search.add_filter("parent_code", collection.get_code())
        search.add_filters("search_code", search_codes)

        items = search.get_sobjects()

        for item in items:
            item.delete()

        my.add_description("Remove [%s] item(s) from Collection [%s]" % (len(my.search_keys), collection_code))
示例#16
0
    def get_security_wdg(self):

        div = DivWdg()
        div.add_class("spt_security")

        div.add("A server can sync either be scoped for a single project or all projects.  Transactions that occur in the admin project never get synced.")

        div.add("<br/>"*2)

        div.add("Project: ")

        search = Search("sthpw/project")
        search.add_filters("code", ['admin','unittest'], op='not in')
        search.add_order_by("title")
        projects = search.get_sobjects()

        select = SelectWdg("projects")
        div.add(select)
        labels = [x.get_value("title") for x in projects]
        values = [x.get_value("code") for x in projects]

        project_code = Project.get_project_code()
        if project_code != 'admin':
            select.set_value(project_code)
        select.set_option("labels", labels)
        select.set_option("values", values)
        select.add_empty_option("-- All --")


        div.add("<br/>"*2)

        return div
示例#17
0
    def get_display(self):

        #project = Project.get()
        schema = Schema.get()
        # no hierarchy to prevent all sthpw and parent sTypes 
        search_type_names = schema.get_search_types(hierarchy=False)
        search = Search('sthpw/search_object')
        search.add_filters('search_type', search_type_names)
        search_types = search.get_sobjects()

        task_search_type = SearchType.get("sthpw/task")
        search_types.append(task_search_type)

        values = [ x.get_value("search_type") for x in search_types]
        labels = []
        for x in search_types:
            label = "%s (%s)" % (x.get_value("title"), x.get_value("search_type"))
            labels.append(label)


        sobject = self.get_current_sobject()
        if not sobject:
            value = ""
        else:
            value = sobject.get_value(self.get_name() )

        self.set_option("values", values)
        self.set_option("labels", labels)
        self.add_empty_option("-- Select --")
        if value:
            self.set_value(value)

        return super(SearchTypeInputWdg, self).get_display()
示例#18
0
    def get_output_tasks(my):

        process = my.get_value("process")
        parent = my.get_parent()

        # get the pipeline
        pipeline_code = parent.get_value("pipeline_code", no_exception=True)
        if not pipeline_code:
            return []

        pipeline = Pipeline.get_by_code(pipeline_code)
        if not pipeline:
            return []

        processes = pipeline.get_output_processes(process)
        if not processes:
            return []

        tasks = []

        process_names = [x.get_name() for x in processes]

        search = Search("sthpw/task")
        search.add_filters("process", process_names)
        search.add_parent_filter(parent)
        tasks = search.get_sobjects()

        return tasks
示例#19
0
    def execute(my):

        my.collection_key = my.kwargs.get("collection_key")
        my.search_keys = my.kwargs.get("search_keys")

        collection = Search.get_by_search_key(my.collection_key)
        collection_code = collection.get("code")
        sobjects = Search.get_by_search_keys(my.search_keys)
        search_codes = [x.get_code() for x in sobjects]

        search_type = collection.get_base_search_type()
        parts = search_type.split("/")
        collection_type = "%s/%s_in_%s" % (parts[0], parts[1], parts[1])

        search = Search(collection_type)
        search.add_filter("parent_code", collection.get_code())
        search.add_filters("search_code", search_codes)

        items = search.get_sobjects()

        for item in items:
            item.delete()

        my.add_description("Remove [%s] item(s) from Collection [%s]" %
                           (len(my.search_keys), collection_code))
示例#20
0
    def preprocess(self):

        sobjects = self.sobjects
        if not sobjects:
            return

        # find all of the instances in a shot
        sobject = sobjects[0]
        foreign_key = sobject.get_foreign_key()

        search_type = WebState.get().get_state("planner_search_type")
        search = Search( search_type )

        search.add_column(foreign_key)

        if len(sobjects) == 1:
            search.add_filter(foreign_key, sobject.get_code())
        else:
            search_codes = [x.get_code() for x in sobjects]
            search.add_filters(foreign_key, search_codes)

        search_type = sobject.get_search_type()
        search.add_order_by(foreign_key)
        children = search.get_sobjects()

        # convert to a dictionary
        for child in children:
            code = child.get_value(foreign_key)
            number = self.numbers.get(code)
            if not number:
                number = 0
           
            number += 1
            self.numbers[code] = number
示例#21
0
    def get_security_wdg(my):

        div = DivWdg()
        div.add_class("spt_security")

        div.add(
            "A server can sync either be scoped for a single project or all projects.  Transactions that occur in the admin project never get synced."
        )

        div.add("<br/>" * 2)

        div.add("Project: ")

        search = Search("sthpw/project")
        search.add_filters("code", ['admin', 'unittest'], op='not in')
        search.add_order_by("title")
        projects = search.get_sobjects()

        select = SelectWdg("projects")
        div.add(select)
        labels = [x.get_value("title") for x in projects]
        values = [x.get_value("code") for x in projects]

        project_code = Project.get_project_code()
        if project_code != 'admin':
            select.set_value(project_code)
        select.set_option("labels", labels)
        select.set_option("values", values)
        select.add_empty_option("-- All --")

        div.add("<br/>" * 2)

        return div
示例#22
0
    def get_tasks(my, sobject):

        search_type = SearchType.get("prod/shot").get_full_key()

        # get all of the shots in the episode
        shots = sobject.get_all_children("prod/shot")
        ids = SObject.get_values(shots, "id")

        search = Search("sthpw/task")
        search.add_filter("search_type", search_type)
        search.add_filters("search_id", ids)
        return search.get_sobjects()
示例#23
0
    def get_search_types(my, include_sthpw=False, include_config=False, include_multi_project=False):
        '''get all the search types in this project'''
        if my.search_types != None:
            return my.search_types

        project_type = my.get_value("type")

        search = Search("sthpw/search_object")

        project_code = my.get_code()
        namespaces = [project_code]
        namespaces.append(project_type)

        if include_sthpw:
            namespaces.append("sthpw")
        if include_config:
            namespaces.append("config")
        if include_multi_project:
            if not include_config:
                search.add_filter('namespace','config',op='!=')
            if not include_sthpw:
                search.add_filter('namespace','sthpw',op='!=')
            search.add_op('begin')
            search.add_filter('database','{project}')
            

        search.add_filters("namespace", namespaces)

        if include_multi_project:
            search.add_op('or')

        search.add_order_by("search_type")
        search_type_objs = search.get_sobjects()

        """
        from pyasm.biz import Schema
        schema = Schema.get()
        xml = schema.get_xml_value("schema")
        search_types = xml.get_values("schema/search_type/@name")
        search = Search("sthpw/search_object")
        search.add_filters("code", search_types)
        search_type_objs = search.get_sobjects()
        """



        search_types = []
        for x in search_type_objs:
            # to avoid the old ill-defined prod/custom_property defined in sthpw namespace
            if (x.get_value('namespace') == 'sthpw' and x.get_value('search_type').find('custom_property') == -1)\
                or my.has_table(x):
                search_types.append(x)
        return search_types
示例#24
0
    def get_tasks(self, sobject):

        search_type = SearchType.get("prod/shot").get_full_key()

        # get all of the shots in the episode
        shots = sobject.get_all_children("prod/shot")
        ids = SObject.get_values(shots, "id")

        search = Search("sthpw/task")
        search.add_filter("search_type", search_type)
        search.add_filters("search_id", ids)
        return search.get_sobjects()
示例#25
0
    def get_connections(cls, sobjects, direction="dst", context='', context_filters=[], src_search=None):
        '''return a Search instance if src_search is provided'''
        if not sobjects and not src_search:
            return []
        search = Search(SObjectConnection)

        if direction == "dst":
            prefix = "src"
        else:
            prefix = "dst"
        
        if src_search:
            search.add_filter("%s_search_type" % prefix, src_search.get_search_type() )
            search.add_search_filter('%s_search_id'%prefix, src_search, op="in") 
        else:
            search_types = [x.get_search_type() for x in sobjects]
            search_ids = [x.get_id() for x in sobjects]

            if len(Common.get_unique_list(search_types)) == 1:
                search.add_filter("%s_search_type" % prefix, search_types[0] )
                search.add_filters("%s_search_id" % prefix, search_ids)
            else:
                search.add_op("begin")
                for search_type, search_id in zip(search_types, search_ids):
                    search.add_op("begin")
                    search.add_filter("%s_search_type" % prefix, search_type )
                    search.add_filter("%s_search_id" % prefix, search_id )
                    search.add_op("and")
                search.add_op("or")

        if context:
            search.add_filter("context", context)
        elif context_filters:
            search.add_op_filters(context_filters)

        if src_search:
            return search

		# cache for connection sobjects
        key = search.get_statement()
        cache = Container.get("SObjectConnection:cache")
        if cache == None:
            cache = {}
            Container.put("SObjectConnection:cache", cache)

        ret_val = cache.get(key)
        if ret_val != None:
            return ret_val

        
        connections = search.get_sobjects()
        
        return connections
示例#26
0
    def get_search_types(my, include_sthpw=False, include_config=False, include_multi_project=False):
        '''get all the search types in this project'''
        if my.search_types != None:
            return my.search_types

        project_type = my.get_value("type")

        search = Search("sthpw/search_object")

        project_code = my.get_code()
        namespaces = [project_code]
        namespaces.append(project_type)

        if include_sthpw:
            namespaces.append("sthpw")
        if include_config:
            namespaces.append("config")
        if include_multi_project:
            if not include_config:
                search.add_filter('namespace','config',op='!=')
            if not include_sthpw:
                search.add_filter('namespace','sthpw',op='!=')
            search.add_op('begin')
            search.add_filter('database','{project}')
            

        search.add_filters("namespace", namespaces)

        if include_multi_project:
            search.add_op('or')

        search.add_order_by("search_type")
        search_type_objs = search.get_sobjects()

        """
        from pyasm.biz import Schema
        schema = Schema.get()
        xml = schema.get_xml_value("schema")
        search_types = xml.get_values("schema/search_type/@name")
        search = Search("sthpw/search_object")
        search.add_filters("code", search_types)
        search_type_objs = search.get_sobjects()
        """



        search_types = []
        for x in search_type_objs:
            # to avoid the old ill-defined prod/custom_property defined in sthpw namespace
            if (x.get_value('namespace') == 'sthpw' and x.get_value('search_type').find('custom_property') == -1)\
                or my.has_table(x):
                search_types.append(x)
        return search_types
示例#27
0
    def get_pipeline(my, pipeline_xml, add_tasks=False):

        pipeline = SearchType.create("sthpw/pipeline")
        pipeline.set_pipeline(pipeline_xml)
        pipeline_id = random.randint(0, 10000000)
        #pipeline.set_value("code", "test%s" % pipeline_id)
        #pipeline.set_id(pipeline_id)
        #pipeline.set_value("id", pipeline_id)
        pipeline.set_value("pipeline", pipeline_xml)
        pipeline.commit()

        process_names = pipeline.get_process_names()

        # delete the processes
        search = Search("config/process")
        search.add_filters("process", process_names)
        processes = search.get_sobjects()
        for process in processes:
            process.delete()

        # create new processes
        processes_dict = {}
        for process_name in process_names:

            # define the process nodes
            process = SearchType.create("config/process")
            process.set_value("process", process_name)
            process.set_value("pipeline_code", pipeline.get_code())
            process.set_json_value("workflow", {
                'on_complete': '''
                sobject.set_value('%s', "complete")
                ''' % process_name,
                'on_approve': '''
                sobject.set_value('%s', "approve")
                ''' % process_name,
 
            } )
            process.commit()

            processes_dict[process_name] = process


            # Note: we don't have an sobject yet
            if add_tasks:
                task = SaerchType.create("sthpw/task")
                task.set_parent(sobject)
                task.set_value("process", process_name)
                task.commit()


        return pipeline, processes_dict
示例#28
0
    def get_pipeline(my, pipeline_xml, add_tasks=False):

        pipeline = SearchType.create("sthpw/pipeline")
        pipeline.set_pipeline(pipeline_xml)
        pipeline_id = random.randint(0, 10000000)
        #pipeline.set_value("code", "test%s" % pipeline_id)
        #pipeline.set_id(pipeline_id)
        #pipeline.set_value("id", pipeline_id)
        pipeline.set_value("pipeline", pipeline_xml)
        pipeline.commit()

        process_names = pipeline.get_process_names()

        # delete the processes
        search = Search("config/process")
        search.add_filters("process", process_names)
        processes = search.get_sobjects()
        for process in processes:
            process.delete()

        # create new processes
        processes_dict = {}
        for process_name in process_names:

            # define the process nodes
            process = SearchType.create("config/process")
            process.set_value("process", process_name)
            process.set_value("pipeline_code", pipeline.get_code())
            process.set_json_value(
                "workflow", {
                    'on_complete':
                    '''
                sobject.set_value('%s', "complete")
                ''' % process_name,
                    'on_approve':
                    '''
                sobject.set_value('%s', "approve")
                ''' % process_name,
                })
            process.commit()

            processes_dict[process_name] = process

            # Note: we don't have an sobject yet
            if add_tasks:
                task = SaerchType.create("sthpw/task")
                task.set_parent(sobject)
                task.set_value("process", process_name)
                task.commit()

        return pipeline, processes_dict
示例#29
0
    def execute(my):

        login = Environment.get_user_name()
        users = my.kwargs.get("users")

        everyone = [login]
        everyone.extend(users)

        # find out if there already is a subscription between this user
        # and others
        search = Search("sthpw/subscription")
        search.add_filter("login", login)
        search.add_filter("category", "chat")
        login_subscriptions = search.get_sobjects()
        keys = [x.get_value("message_code") for x in login_subscriptions]

        create = True

        # find the subscriptions for each user with the same keys
        for user in users:
            search = Search("sthpw/subscription")
            search.add_filters("message_code", keys)
            search.add_filter("login", user)
            user_subscriptions = search.get_sobjects()
            if user_subscriptions:
                create = False


        # create a new subscription
        if create:
            key = Common.generate_random_key()
            message = SearchType.create("sthpw/message")
            message.set_value("code", key)
            message.set_value("login", login)
            message.set_value("category", "chat")
            message.set_value("message", "Welcome!!!")
            message.commit()

            # create a subscription for each person
            for person in everyone:
                subscription = SearchType.create("sthpw/subscription")
                subscription.set_value("message_code", key)
                subscription.set_value("login", person)
                subscription.set_value("category", "chat")
                subscription.commit()
示例#30
0
    def alter_search(self, search):
        print "Introspect alter_search"

        # see if any of the filters have a class handler defined
        from tactic.ui.filter import FilterData
        filter_data = FilterData.get_from_cgi()
        values = filter_data.get_values_by_index("introspect", 0)

        do_search = values.get('search')
        if not do_search:
            return
            



        #search.add_filter("code", "chr002")
        session = SessionContents.get()

        node_names = session.get_node_names()

        snapshot_codes = session.get_snapshot_codes()
        snapshot_search = Search("sthpw/snapshot")
        snapshot_search.add_filters("code", snapshot_codes)
        snapshots = snapshot_search.get_sobjects()

        state_search_type = self.kwargs.get("search_type")


        # get ids
        ids = []
        for snapshot in snapshots:
            search_type = snapshot.get_value("search_type")
            if state_search_type:
                search_type_obj = SearchType.get(search_type)
                key = search_type_obj.get_base_key()
                print "compare: ", key, state_search_type
                if key != state_search_type:
                    continue

            id = snapshot.get_value("search_id")
            ids.append(id)

        print "ids: ", ids
        if ids:
            search.add_filters("id", ids)
示例#31
0
    def execute(self):

        login = Environment.get_user_name()
        users = self.kwargs.get("users")

        everyone = [login]
        everyone.extend(users)

        # find out if there already is a subscription between this user
        # and others
        search = Search("sthpw/subscription")
        search.add_filter("login", login)
        search.add_filter("category", "chat")
        login_subscriptions = search.get_sobjects()
        keys = [x.get_value("message_code") for x in login_subscriptions]

        create = True

        # find the subscriptions for each user with the same keys
        for user in users:
            search = Search("sthpw/subscription")
            search.add_filters("message_code", keys)
            search.add_filter("login", user)
            user_subscriptions = search.get_sobjects()
            if user_subscriptions:
                create = False


        # create a new subscription
        if create:
            key = Common.generate_random_key()
            message = SearchType.create("sthpw/message")
            message.set_value("code", key)
            message.set_value("login", login)
            message.set_value("category", "chat")
            message.set_value("message", "Welcome!!!")
            message.commit()

            # create a subscription for each person
            for person in everyone:
                subscription = SearchType.create("sthpw/subscription")
                subscription.set_value("message_code", key)
                subscription.set_value("login", person)
                subscription.set_value("category", "chat")
                subscription.commit()
示例#32
0
    def get_user_projects(cls):
        search = Search("sthpw/project")
        search.add_filters("code", ['admin','sthpw'], op='not in')
        projects = search.get_sobjects()

        security = Environment.get_security()
        key = { "code": "*" }
        if security.check_access("project", key, "allow", default="deny"):
            return projects

        # which projects is a user allowed to see
        allowed = []
        for project in projects:
            key = {"code": project.get_code() }
            if security.check_access("project", key, "allow", default="deny"):
                allowed.append(project)

        return allowed
示例#33
0
    def get_sobjects(self, group_names):
        # get the project sobjects
        search = Search("sthpw/project")
        search.add_filters("code", ['sthpw','admin','unittest'], op='not in')
        search.add_order_by("title")
        projects = search.get_sobjects()


        sobject = SearchType.create("sthpw/virtual")
        sobject.set_value("title", "ALL PROJECTS")
        sobject.set_value("_extra_data", {"is_all": True})
        sobject.set_value("id", 1)
        sobject.set_value("code", "*")
        projects.insert(0, sobject)


        # process all of the groups and find out which projects
        security = Environment.get_security()

        rules_dict = {}

        for project in projects:
            for group_name in group_names:

                access_rules = rules_dict.get(group_name)
                if access_rules == None:

                    #!!!!!!
                    #group = LoginGroup.get_by_group_name(group_name)
                    group = self.servers.get(group_name)


                    access_rules = group.get_xml_value("access_rules")
                    rules_dict[group_name] = access_rules

                node = access_rules.get_node("rules/rule[@group='project' and @code='%s']" % project.get_code())

                if node is not None:
                    project.set_value("_%s" % group_name, True)
                else:
                    project.set_value("_%s" % group_name, False)


        return projects
示例#34
0
    def preprocess(my):
        if my.sobjects:
            try:
                search = Search(Task)
                search_ids = [x.get_id() for x in my.sobjects]
                search.add_filters("search_id", search_ids)
                search_type = my.sobjects[0].get_search_type()
                search.add_filter("search_type", search_type)

                # go thru children of main search
                search = my.alter_task_search(search, prefix='children')
                # go thru Local Search
                search = my.alter_task_search(
                    search,
                    prefix='main_body',
                    prefix_namespace=my.__class__.__name__)

                sobj = my.sobjects[0]
                pipeline = Pipeline.get_by_sobject(sobj)
                if pipeline:
                    process_names = pipeline.get_process_names(True)
                    search.add_enum_order_by("process", process_names)
                else:
                    search.add_order_by("process")

                search.add_order_by("id")
                tasks = search.get_sobjects()
                # create a data structure
                for task in tasks:
                    search_type = task.get_value("search_type")
                    search_id = task.get_value("search_id")
                    search_key = "%s|%s" % (search_type, search_id)

                    sobject_tasks = my.data.get(search_key)
                    if not sobject_tasks:
                        sobject_tasks = []
                        my.data[search_key] = sobject_tasks
                    sobject_tasks.append(task)
            except:
                from tactic.ui.app import SearchWdg
                parent_search_type = get_search_type()
                SearchWdg.clear_search_data(parent_search_type)
                raise
示例#35
0
    def execute(self):
        input = self.get_input()

        search_key = input.get("search_key")
        task = Search.get_by_search_key(search_key)
        parent = task.get_parent()
        if not parent:
            raise TacticException("Task parent not found.")

        # get the definition of the trigger
        trigger_sobj = self.get_trigger_sobj()
        data = trigger_sobj.get_value("data")
        try:
            data = jsonloads(data)
        except:
            raise TacticException("Incorrect formatting of trigger [%s]." %
                                  trigger_sobj.get_value("code"))

        # check against source status if present
        src_status = data.get("src_status")
        if src_status:
            task_status = task.get_value("status")
            if task_status != src_status:
                return

        process_names = data.get("output")
        if not process_names:
            return

        # only create new task if another of the same
        # process does not already exist
        search = Search("sthpw/task")
        search.add_filters("process", process_names)
        search.add_parent_filter(parent)
        search.add_project_filter()
        tasks = search.get_sobjects()
        existing_processes = [x.get_value("process") for x in tasks]

        for process in process_names:
            if process in existing_processes:
                continue
            else:
                Task.create(parent, process, start_date=None, end_date=None)
示例#36
0
    def execute(self):
        input = self.get_input()

        search_key = input.get("search_key")
        task = Search.get_by_search_key(search_key)
        parent = task.get_parent()
        if not parent:
            raise TacticException("Task parent not found.")

        # get the definition of the trigger
        trigger_sobj = self.get_trigger_sobj()
        data = trigger_sobj.get_value("data")
        try:
            data = jsonloads(data)
        except:
            raise TacticException("Incorrect formatting of trigger [%s]." % trigger_sobj.get_value("code"))

        # check against source status if present 
        src_status = data.get("src_status")
        if src_status:
            task_status = task.get_value("status")
            if task_status != src_status:
                return

        process_names = data.get("output")
        if not process_names:
            return

        # only create new task if another of the same
        # process does not already exist
        search = Search("sthpw/task")
        search.add_filters("process", process_names)
        search.add_parent_filter(parent)
        search.add_project_filter()
        tasks = search.get_sobjects()
        existing_processes = [x.get_value("process") for x in tasks]
       
        for process in process_names:
            if process in existing_processes:    
                continue
            else:
                Task.create(parent, process, start_date=None, end_date=None)
示例#37
0
    def get_relations(self, sobjects):

        if not sobjects:
            return {}

        column = self.get_column()
        
        if not column.endswith('_id'):
            return {}


        search_ids = [x.get_value(column) for x in sobjects]
        table = column.replace("_id", "")

        project_code = Project.get_project_code()

        # look at the first ones search type for the namespace
        sobject = sobjects[0]
        search_type_obj = sobject.get_search_type_obj()
        namespace = search_type_obj.get_value("namespace")

        parent_type = self.get_option('search_type')
        if not parent_type:
            parent_type = "%s/%s" % (namespace, table)
            # parent_type = "%s/%s" % (project_code, table)

        # NOTE: this is just to fix a bug in MMS.  When updating the
        # personal_time_log, the crossover to sthpw causes a stack trace
        #if parent_type == 'MMS/login':
        #    parent_type = 'sthpw/login'


        search = Search(parent_type)
        search.add_filters("id", search_ids)
        parents = search.get_sobjects()

        parents_dict = {}
        for parent in parents:
            id = parent.get_id()
            parents_dict[id] = parent

        return parents_dict
示例#38
0
    def get_relations(my, sobjects):

        if not sobjects:
            return {}

        column = my.get_column()
        
        if not column.endswith('_id'):
            return {}


        search_ids = [x.get_value(column) for x in sobjects]
        table = column.replace("_id", "")

        project_code = Project.get_project_code()

        # look at the first ones search type for the namespace
        sobject = sobjects[0]
        search_type_obj = sobject.get_search_type_obj()
        namespace = search_type_obj.get_value("namespace")

        parent_type = my.get_option('search_type')
        if not parent_type:
            parent_type = "%s/%s" % (namespace, table)
            # parent_type = "%s/%s" % (project_code, table)

        # NOTE: this is just to fix a bug in MMS.  When updating the
        # personal_time_log, the crossover to sthpw causes a stack trace
        #if parent_type == 'MMS/login':
        #    parent_type = 'sthpw/login'


        search = Search(parent_type)
        search.add_filters("id", search_ids)
        parents = search.get_sobjects()

        parents_dict = {}
        for parent in parents:
            id = parent.get_id()
            parents_dict[id] = parent

        return parents_dict
示例#39
0
    def get_display(my):
        div = DivWdg()

        select = SelectWdg("browser_search_type")
        select.add_empty_option("<- Select ->")
        search = Search("sthpw/search_object")
        search.add_order_by("search_type")

        search_types = my.get_option("search_types")
        if search_types:
            search_types = search_types.split("|")
            search.add_filters("search_type", search_types)

        select.set_persist_on_submit()
        select.set_search_for_options(search,"search_type","title")
        div.add(select)

        text = TextWdg("browser_search_text")
        text.set_persist_on_submit()
        div.add(text)

        # draw the sobjects
        sobject_element_id = "sobject_browser"
        button = ButtonWdg("Search")
        div.add(button)


        ajax = AjaxLoader()
        ajax.set_display_id(sobject_element_id)
        ajax.set_load_class("pyasm.widget.SObjectBrowserListWdg")
        ajax.add_element_name("browser_search_type")
        ajax.add_element_name("browser_search_text")
        script = ajax.get_on_script()
        button.add_event("onclick", script)


        div2 = DivWdg()
        div2.add_style("display: block")
        div2.set_id(sobject_element_id)
        div.add(div2)

        return div
示例#40
0
    def get_sobjects(my, group_names):
        # get the project sobjects
        search = Search("sthpw/project")
        search.add_filters("code", ['sthpw', 'admin', 'unittest'], op='not in')
        search.add_order_by("title")
        projects = search.get_sobjects()

        sobject = SearchType.create("sthpw/virtual")
        sobject.set_value("title", "ALL PROJECTS")
        sobject.set_value("_extra_data", {"is_all": True})
        sobject.set_value("id", 1)
        sobject.set_value("code", "*")
        projects.insert(0, sobject)

        # process all of the groups and find out which projects
        security = Environment.get_security()

        rules_dict = {}

        for project in projects:
            for group_name in group_names:

                access_rules = rules_dict.get(group_name)
                if access_rules == None:

                    #!!!!!!
                    #group = LoginGroup.get_by_group_name(group_name)
                    group = my.servers.get(group_name)

                    access_rules = group.get_xml_value("access_rules")
                    rules_dict[group_name] = access_rules

                node = access_rules.get_node(
                    "rules/rule[@group='project' and @code='%s']" %
                    project.get_code())

                if node is not None:
                    project.set_value("_%s" % group_name, True)
                else:
                    project.set_value("_%s" % group_name, False)

        return projects
示例#41
0
    def get_display(self):
        div = DivWdg()

        select = SelectWdg("browser_search_type")
        select.add_empty_option("<- Select ->")
        search = Search("sthpw/search_object")
        search.add_order_by("search_type")

        search_types = self.get_option("search_types")
        if search_types:
            search_types = search_types.split("|")
            search.add_filters("search_type", search_types)

        select.set_persist_on_submit()
        select.set_search_for_options(search,"search_type","title")
        div.add(select)

        text = TextWdg("browser_search_text")
        text.set_persist_on_submit()
        div.add(text)

        # draw the sobjects
        sobject_element_id = "sobject_browser"
        button = ButtonWdg("Search")
        div.add(button)


        ajax = AjaxLoader()
        ajax.set_display_id(sobject_element_id)
        ajax.set_load_class("pyasm.widget.SObjectBrowserListWdg")
        ajax.add_element_name("browser_search_type")
        ajax.add_element_name("browser_search_text")
        script = ajax.get_on_script()
        button.add_event("onclick", script)


        div2 = DivWdg()
        div2.add_style("display: block")
        div2.set_id(sobject_element_id)
        div.add(div2)

        return div
示例#42
0
    def alter_search(self, search):
        # remove the limit to get all the parents' id
        # add reapply the limit later.. This is needed for an accurate
        # result when limit and offset is applied later

        # IS THIS EVEN CALLED??
        sdfsadfasfd

        limit = search.get_select().limit 
        search.set_limit(None)
        
        # do a quick and dirty presearch search
        sobjects = search.get_sobjects()
        search.set_search_done(False)
        # HACK: reset order bys
        search.get_select().order_bys = []
        if not sobjects:
            return
        search.set_limit(limit)
        
        
        # get the parent type
        sobject = sobjects[0]
        parent_type = sobject.get_value("search_type")
        search_type_obj = SearchType.get(parent_type)
        # DO NOT USE base key or it won't search properly for multi project
        #parent_type = search_type_obj.get_base_key()

        parent_ids = [x.get_value("search_id") for x in sobjects]

        #parent_type = 'prod/asset'
        parent_search = Search(parent_type)
        parent_search.add_filters("id", parent_ids)
        parent_search.add_order_by("code")

        parents = parent_search.get_sobjects()

        ids = [x.get_id() for x in parents]

        search.add_enum_order_by("search_id", ids)
        search.get_sobjects()
        search.add_order_by("description")
示例#43
0
    def get_display(my):

        #project = Project.get()
        schema = Schema.get()
        # no hierarchy to prevent all sthpw and parent sTypes 
        search_type_names = schema.get_search_types(hierarchy=False)
        search = Search('sthpw/search_object')
        search.add_filters('search_type', search_type_names)
        search_types = search.get_sobjects()

        task_search_type = SearchType.get("sthpw/task")
        search_types.append(task_search_type)

        values = [ x.get_value("search_type") for x in search_types]
        filtered = []
        labels = []
        for x in search_types:
            base_type = x.get_base_key()
            exists = SearchType.column_exists(base_type, "pipeline_code")
            if not exists:
                continue

            label = "%s (%s)" % (x.get_value("title"), x.get_value("search_type"))
            labels.append(label)
            filtered.append(base_type)


        values = filtered

        sobject = my.get_current_sobject()
        if not sobject:
            value = ""
        else:
            value = sobject.get_value(my.get_name() )

        my.set_option("values", values)
        my.set_option("labels", labels)
        my.add_empty_option("-- Select --")
        if value:
            my.set_value(value)

        return super(SearchTypeWithPipelineInputWdg, my).get_display()
示例#44
0
    def get_display(self):

        #project = Project.get()
        schema = Schema.get()
        # no hierarchy to prevent all sthpw and parent sTypes
        search_type_names = schema.get_search_types(hierarchy=False)
        search = Search('sthpw/search_object')
        search.add_filters('search_type', search_type_names)
        search_types = search.get_sobjects()

        task_search_type = SearchType.get("sthpw/task")
        search_types.append(task_search_type)

        values = [x.get_value("search_type") for x in search_types]
        filtered = []
        labels = []
        for x in search_types:
            base_type = x.get_base_key()
            exists = SearchType.column_exists(base_type, "pipeline_code")
            if not exists:
                continue

            label = "%s (%s)" % (x.get_value("title"),
                                 x.get_value("search_type"))
            labels.append(label)
            filtered.append(base_type)

        values = filtered

        sobject = self.get_current_sobject()
        if not sobject:
            value = ""
        else:
            value = sobject.get_value(self.get_name())

        self.set_option("values", values)
        self.set_option("labels", labels)
        self.add_empty_option("-- Select --")
        if value:
            self.set_value(value)

        return super(SearchTypeWithPipelineInputWdg, self).get_display()
示例#45
0
    def alter_search(self, search):
        # remove the limit to get all the parents' id
        # add reapply the limit later.. This is needed for an accurate
        # result when limit and offset is applied later

        # IS THIS EVEN CALLED??
        sdfsadfasfd

        limit = search.get_select().limit
        search.set_limit(None)

        # do a quick and dirty presearch search
        sobjects = search.get_sobjects()
        search.set_search_done(False)
        # HACK: reset order bys
        search.get_select().order_bys = []
        if not sobjects:
            return
        search.set_limit(limit)

        # get the parent type
        sobject = sobjects[0]
        parent_type = sobject.get_value("search_type")
        search_type_obj = SearchType.get(parent_type)
        # DO NOT USE base key or it won't search properly for multi project
        #parent_type = search_type_obj.get_base_key()

        parent_ids = [x.get_value("search_id") for x in sobjects]

        #parent_type = 'prod/asset'
        parent_search = Search(parent_type)
        parent_search.add_filters("id", parent_ids)
        parent_search.add_order_by("code")

        parents = parent_search.get_sobjects()

        ids = [x.get_id() for x in parents]

        search.add_enum_order_by("search_id", ids)
        search.get_sobjects()
        search.add_order_by("description")
示例#46
0
    def alter_search(self, search):
        print "Introspect alter_search"

        # see if any of the filters have a class handler defined
        from tactic.ui.filter import FilterData
        filter_data = FilterData.get_from_cgi()
        values = filter_data.get_values_by_index("introspect", 0)

        do_search = values.get('search')
        if not do_search:
            return

        #search.add_filter("code", "chr002")
        session = SessionContents.get()

        node_names = session.get_node_names()

        snapshot_codes = session.get_snapshot_codes()
        snapshot_search = Search("sthpw/snapshot")
        snapshot_search.add_filters("code", snapshot_codes)
        snapshots = snapshot_search.get_sobjects()

        state_search_type = self.kwargs.get("search_type")

        # get ids
        ids = []
        for snapshot in snapshots:
            search_type = snapshot.get_value("search_type")
            if state_search_type:
                search_type_obj = SearchType.get(search_type)
                key = search_type_obj.get_base_key()
                print "compare: ", key, state_search_type
                if key != state_search_type:
                    continue

            id = snapshot.get_value("search_id")
            ids.append(id)

        print "ids: ", ids
        if ids:
            search.add_filters("id", ids)
示例#47
0
    def get_search_by_sobjects(cls, sobjects):
        '''adds a filter to the search to get the related'''
        if not sobjects:
            return None

        sobject = sobjects[0]

        search = Search(cls.SEARCH_TYPE)
        if len(sobjects) == 1:
            search_id = sobject.get_id()
            search.add_filter("search_id", search_id)
        else:
            search_ids = [x.get_id() for x in sobjects]
            search.add_filters("search_id", search_ids)

        search_type = sobject.get_search_type()
        search.add_filter("search_type", search_type)
        search.add_order_by("search_type")
        search.add_order_by("search_id")

        return search
示例#48
0
文件: task_wdg.py 项目: 0-T-0/TACTIC
    def preprocess(my):
        if my.sobjects:
            try:
                search = Search(Task) 
                search_ids = [x.get_id() for x in my.sobjects]
                search.add_filters("search_id", search_ids)
                search_type = my.sobjects[0].get_search_type()
                search.add_filter("search_type", search_type)
                
                # go thru children of main search
                search = my.alter_task_search(search, prefix='children')
                # go thru Local Search
                search = my.alter_task_search(search, prefix='main_body', prefix_namespace=my.__class__.__name__)

                sobj = my.sobjects[0]
                pipeline = Pipeline.get_by_sobject(sobj) 
                if pipeline:
                    process_names = pipeline.get_process_names(True)
                    search.add_enum_order_by("process", process_names)
                else:
                    search.add_order_by("process")

                search.add_order_by("id")
                tasks = search.get_sobjects()
                # create a data structure
                for task in tasks:
                    search_type = task.get_value("search_type")
                    search_id = task.get_value("search_id")
                    search_key = "%s|%s" % (search_type, search_id)

                    sobject_tasks = my.data.get(search_key)
                    if not sobject_tasks:
                        sobject_tasks = []
                        my.data[search_key] = sobject_tasks
                    sobject_tasks.append(task)
            except:
                from tactic.ui.app import SearchWdg
                parent_search_type = get_search_type()
                SearchWdg.clear_search_data(parent_search_type)
                raise
示例#49
0
文件: note.py 项目: blezek/TACTIC
    def get_search_by_sobjects(cls, sobjects):
        '''adds a filter to the search to get the related'''
        if not sobjects:
            return None

        sobject = sobjects[0]

        search = Search( cls.SEARCH_TYPE )
        if len(sobjects) == 1:
            search_id = sobject.get_id()
            search.add_filter("search_id", search_id)
        else:
            search_ids = [x.get_id() for x in sobjects]
            search.add_filters("search_id", search_ids)


        search_type = sobject.get_search_type()
        search.add_filter("search_type", search_type)
        search.add_order_by("search_type")
        search.add_order_by("search_id")

        return search
示例#50
0
    def get_display(my):

        parent_key = my.kwargs.get("parent_key")
        collection = Search.get_by_search_key(parent_key)

        collection_path = my.kwargs.get("path")

        search_type = collection.get_base_search_type()
        parts = search_type.split("/")
        collection_type = "%s/%s_in_%s" % (parts[0], parts[1], parts[1])

        search = Search(collection_type)
        search.add_filter("parent_code", collection.get_value("code"))
        collections = search.get_sobjects()
        collection_codes = [x.get_value("search_code") for x in collections]

        search = Search(search_type)
        search.add_filter("_is_collection", True)
        search.add_filters("code", collection_codes)
        collections = search.get_sobjects()

        top = my.top
        top.add_class("spt_collection_list")

        for item in collections:

            path = "%s/%s" % (collection_path, item.get_value("name") )
            collection_wdg = CollectionItemWdg(collection=item, path=path)
            top.add(collection_wdg)

            subcollection_wdg = DivWdg()
            top.add(subcollection_wdg)
            subcollection_wdg.add_class("spt_subcollection_wdg")
            subcollection_wdg.add_style("padding-left: 15px")

        return top
示例#51
0
    def get_display(my):

        parent_key = my.kwargs.get("parent_key")
        collection = Search.get_by_search_key(parent_key)

        collection_path = my.kwargs.get("path")

        search_type = collection.get_base_search_type()
        parts = search_type.split("/")
        collection_type = "%s/%s_in_%s" % (parts[0], parts[1], parts[1])

        search = Search(collection_type)
        search.add_filter("parent_code", collection.get_value("code"))
        collections = search.get_sobjects()
        collection_codes = [x.get_value("search_code") for x in collections]

        search = Search(search_type)
        search.add_filter("_is_collection", True)
        search.add_filters("code", collection_codes)
        collections = search.get_sobjects()

        top = my.top
        top.add_class("spt_collection_list")

        for item in collections:

            path = "%s/%s" % (collection_path, item.get_value("name"))
            collection_wdg = CollectionItemWdg(collection=item, path=path)
            top.add(collection_wdg)

            subcollection_wdg = DivWdg()
            top.add(subcollection_wdg)
            subcollection_wdg.add_class("spt_subcollection_wdg")
            subcollection_wdg.add_style("padding-left: 15px")

        return top
示例#52
0
    def get_tasks(my, sobjects=[]):


        # get all of the relevant tasks to the user
        task_search = Search("sthpw/task")
        task_search.add_column("search_id", distinct=True)


        if sobjects:
            task_search.add_filter("search_type", sobjects[0].get_search_type() )
            sobject_ids = SObject.get_values(sobjects, "id", unique=True)
            task_search.add_filters("search_id", sobject_ids)


        # only look at this project
        search_type = SearchType.get(my.search_type).get_full_key()
        task_search.add_filter("search_type", search_type)


        my.process_filter.alter_search(task_search)
        if isinstance(my.user_filter, UserFilterWdg):
            my.user_filter.alter_search(task_search)
        else:
            user = Environment.get_user_name()
            task_search.add_filter('assigned', user)
        
        status_filters = my.task_status_filter.get_values()
        
        if not status_filters:
            return []

        task_search.add_filters("status", status_filters)

        tasks = task_search.get_sobjects()
        
        return tasks
示例#53
0
    def get_sobject_files(my, sobject):
        paths = []

        show_versionless = my.kwargs.get("show_versionless")
        if show_versionless in [True, 'true']:
            show_versionless = True
        else:
            show_versionless = False


        if isinstance(sobject, Snapshot):
            snapshots = [sobject]
        else:
            # get the snapshots
            versions = my.get_value("versions")
            search = Search("sthpw/snapshot")

            search.add_parent_filter(sobject)


            if not versions or versions == 'latest':
                search.add_filter("is_latest", True)
            elif versions == 'current':
                search.add_filter("is_current", True)

            if show_versionless:
                search.add_filter("version", -1)
                search.add_op('or')

            processes = my.kwargs.get("processes")
            process = my.get_value("process")
            if process and process != 'all':
                search.add_filter("process", process)
            if processes:
                search.add_filters("process", processes)

            snapshots = search.get_sobjects()

            #snapshots = Snapshot.get_by_sobject(sobject)

        for snapshot in snapshots:

            exclude = ['web','icon']
            snapshot_paths = snapshot.get_all_lib_paths(exclude_file_types=exclude)
            files = snapshot.get_all_file_objects(exclude_file_types=exclude)
            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)
                            my.files[item_path] = file

                        for dirname in dirnames:
                            item_path = "%s/%s/" % (root, dirname)
                            paths.append(item_path)
                            my.files[item_path] = file

                else:
                    paths.append(path)
                    my.snapshots[path] = snapshot
                    my.files[path] = file

        return paths
示例#54
0
    def get_display(my):

        top = my.top
        my.set_as_panel(top)
        top.add_class("spt_checkout_top")
        top.add_color("background", "background")
        top.add_style("width: 800px")

        inner = DivWdg()
        top.add(inner)

        snapshot_codes = my.kwargs.get("snapshot_codes")
        search_keys = my.kwargs.get("search_keys")

        if snapshot_codes:
            if isinstance(snapshot_codes, basestring):
                snapshots_codes = eval(snapshot_codes)

            search = Search("sthpw/snapshot")
            search.add_filters("code", snapshot_codes)
            snapshots = search.get_sobjects()
        elif search_keys:

            if isinstance(search_keys, basestring):
                search_keys = eval(search_keys)

            sobjects = Search.get_by_search_keys(search_keys)
            snapshots = []
            for sobject in sobjects:
                snapshot = Snapshot.get_latest_by_sobject(sobject, process="publish")
                if snapshot:
                    snapshots.append(snapshot)

            snapshot_codes = []
            for snapshot in snapshots:
                snapshot_codes.append( snapshot.get("code") )

        if not snapshot_codes:
            no_snapshots_div = DivWdg()
            no_snapshots_div.add("No files in selection")
            inner.add(no_snapshots_div)
            return top


        sandbox_dir = Environment.get_sandbox_dir("default")
        project_code = Project.get_project_code()
        sandbox_dir = "%s/%s" % (sandbox_dir, project_code)

        base_dir = my.kwargs.get("base_dir")

        if base_dir:
            title_div = DivWdg()
            inner.add(title_div)
            title_div.add_color("background", "background3")
            title_div.add_color("color", "color3")
            title_div.add_style("padding", "15px")
            title_div.add_style("font-weight: bold")
            title_div.add("Path: %s" % base_dir)


        inner.add("Check-out to: %s" % sandbox_dir)


        button_div = ButtonRowWdg()
        inner.add(button_div)

        button = ButtonNewWdg(title="Refresh", icon=IconWdg.REFRESH)
        button_div.add(button)
        button.add_behavior( {
            'type': 'click_up',
            'cbjs_action': '''
            var top = bvr.src_el.getParent(".spt_checkout_top");
            spt.panel.refresh(top)
            '''
        } )


        web = WebContainer.get_web()
        if web.use_applet():

            button = ButtonNewWdg(title="Check-out", icon=IconWdg.CHECK_OUT)
            button_div.add(button)

            button.add_behavior( {
                'type': 'click_up',
                'snapshot_codes': snapshot_codes,
                'cbjs_action': '''
                var top = bvr.src_el.getParent(".spt_checkout_top");
                var progress = top.getElement(".spt_checkout_progress");
                var message = top.getElement(".spt_checkout_message");
                var snapshot_codes = bvr.snapshot_codes;
                var num_snapshots = snapshot_codes.length;

                var server = TacticServerStub.get();

                for (var i = 0; i < snapshot_codes.length; i++) {
                    var snapshot_code = snapshot_codes[i];

                    var percent = parseInt( (i+1) / (num_snapshots-1) * 100);

                    var desc = "Checking out: "+(i+1)+" of "+num_snapshots+": "+snapshot_code;
                    progress.setStyle("width", percent + "%");
                    message.innerHTML = desc;

                    server.checkout_snapshot(snapshot_code, null, {file_types: ['main'], filename_mode: 'source'});


                }
                progress.setStyle("width", "100%");
                progress.setStyle("background", "#0F0");
                message.innerHTML = ""
                '''
            } )


            button = ButtonNewWdg(title="Sandbox", icon=IconWdg.FOLDER_GO)
            button_div.add(button)

            button.add_behavior( {
                'type': 'click_up',
                'sandbox_dir': sandbox_dir,
                'cbjs_action': '''
                var applet = spt.Applet.get();
                applet.open_explorer(bvr.sandbox_dir);
                '''
            } )




        msg_div = DivWdg()
        inner.add(msg_div)
        msg_div.add_class("spt_checkout_message")
        msg_div.add(" ")


        progress_div = DivWdg()
        inner.add(progress_div)
        progress_div.add_style("width: auto")
        progress_div.add_style("height: 15px")
        progress_div.add_style("margin: 0px 10px 10px 10px")
        progress_div.add_border()

        progress = DivWdg()
        progress.add_class("spt_checkout_progress")
        progress_div.add(progress)
        progress.add_style("background", "#F00")
        progress.add_style("width", "0%")
        progress.add("&nbsp;")


        snapshot_div = DivWdg()
        inner.add(snapshot_div)

        layout = ViewPanelWdg(
                search_type="sthpw/snapshot",
                show_shelf=False,
                edit=False,
                width="100%",
                element_names=['preview','file','context','version','timestamp','description'],
        )
        snapshot_div.add(layout)
        layout.set_sobjects(snapshots[:50])


        if my.kwargs.get("is_refresh") == 'true':
            return inner
        else:
            return top
示例#55
0
    def get_group_wdg(self):

        div = DivWdg()

        title_wdg = DivWdg()
        div.add(title_wdg)
        title_wdg.add_style("padding: 5px")
        title_wdg.add_style("font-weight: bold")
        title_wdg.add_style("font-size: 14px")
        title_wdg.add_gradient("background", "background")
        title_wdg.add("Users")
        title_wdg.add_style("min-width: 200px")

        filtered_groups = self.kwargs.get("groups")
        if isinstance(filtered_groups, basestring):
            filtered_groups = filtered_groups.split("|")

        search = Search("sthpw/login_group")
        if filtered_groups:
            search.add_filters("login_group", filtered_groups)

        security = Environment.get_security()
        if not security.check_access("builtin", "view_site_admin", "allow"):
            search.add_filter("login_group", "admin", op="!=")
        search.add_project_filter()

        groups = search.get_sobjects()

        groups_div = DivWdg()
        div.add(groups_div)
        for group in groups:

            group_div = DivWdg()
            groups_div.add(group_div)

            title_div = DivWdg()
            group_div.add(title_div)
            title_div.add_color("background", "background3")
            title_div.add_color("color", "color3")
            title_div.add_style("margin-top: 5px")
            title_div.add_style("padding: 2px")

            swap = SwapDisplayWdg()
            title_div.add(swap)
            swap.add_style("float: left")

            title = DivWdg(group.get_value("login_group"))
            title_div.add(title)
            #title.add_style("float: left")
            title.add_style("font-weight: bold")
            title.add_style("padding-top: 2px")

            content_div = DivWdg()
            group_div.add(content_div)

            SwapDisplayWdg.create_swap_title(title,
                                             swap,
                                             div=content_div,
                                             is_open=True,
                                             action_script=None)

            logins = group.get_logins()
            logins_div = self.get_logins_wdg(logins)
            content_div.add(logins_div)
            content_div.add_style("padding-left: 15px")

        return div
示例#56
0
    def execute(my):

        start = time.time()

        from pyasm.common import SPTDate
        timestamp = SPTDate.now()
        timestamp = SPTDate.add_gmt_timezone(timestamp)
        timestamp = SPTDate.convert_to_local(timestamp)
        format = '%Y-%m-%d %H:%M:%S'
        timestamp = timestamp.strftime(format)

        updates = my.kwargs.get("updates")
        if isinstance(updates, basestring):
            updates = jsonloads(updates)
        last_timestamp = my.kwargs.get("last_timestamp")
        #assert last_timestamp
        if not last_timestamp:
            my.info = {"updates": {}, "timestamp": timestamp}
            return

        last_timestamp = parser.parse(last_timestamp)
        last_timestamp = SPTDate.add_gmt_timezone(last_timestamp)

        # give 2 seconds of extra room
        last_timestamp = last_timestamp - timedelta(seconds=2)

        # get out all of the search_keys
        client_keys = set()
        client_stypes = set()
        for id, values_list in updates.items():
            if isinstance(values_list, dict):
                values_list = [values_list]

            for values in values_list:
                handler = values.get("handler")
                if handler:
                    handler = Common.create_from_class_path(handler)
                    # it could be a list
                    search_key = handler.get_search_key()
                else:
                    search_key = values.get("search_key")

                if search_key:
                    if isinstance(search_key, list):
                        search_key_set = set(search_key)
                    else:
                        search_key_set = set()
                        search_key_set.add(search_key)
                    client_keys.update(search_key_set)

                stype = values.get("search_type")
                if stype:
                    client_stypes.add(stype)

        # find all of the search that have changed
        changed_keys = set()
        changed_types = set()
        for check_type in ['sthpw/change_timestamp', 'sthpw/sobject_log']:
            search = Search(check_type)
            search.add_filter("timestamp", last_timestamp, op=">")
            search.add_filters("search_type",
                               ["sthpw/sobject_log", "sthpw/status_log"],
                               op="not in")
            changed_sobjects = search.get_sobjects()
            for sobject in changed_sobjects:
                search_type = sobject.get_value("search_type")
                search_code = sobject.get_value("search_code")
                if search_type.startswith("sthpw/"):
                    search_key = "%s?code=%s" % (search_type, search_code)
                else:
                    search_key = "%s&code=%s" % (search_type, search_code)
                changed_keys.add(u'%s' % search_key)
                changed_types.add(search_type)

        intersect_keys = client_keys.intersection(changed_keys)

        from pyasm.web import HtmlElement

        results = {}
        for id, values_list in updates.items():
            if isinstance(values_list, dict):
                values_list = [values_list]

            for values in values_list:

                handler = values.get("handler")
                if handler:
                    handler = Common.create_from_class_path(handler)
                    # handler can return a list of search_keys
                    search_key = handler.get_search_key()
                else:
                    search_key = values.get("search_key")

                stype = values.get("search_type")
                if search_key:
                    if isinstance(search_key, list):
                        search_key_set = set(search_key)
                    else:
                        search_key_set = set()
                        search_key_set.add(search_key)

                    # filter for search_type first if it exists
                    # check if any search_key is contained in intersect_keys, skip if not

                    if stype and stype in changed_types:
                        if len(intersect_keys -
                               search_key_set) == len(intersect_keys):
                            continue
                    elif len(intersect_keys -
                             search_key_set) == len(intersect_keys):
                        continue

                # evaluate any compare expressions
                compare = values.get("compare")
                if compare:
                    search_key = values.get("search_key")
                    if search_key:
                        sobject = Search.get_by_search_key(search_key)
                    else:
                        sobject = None
                    cmp_result = Search.eval(compare, sobject, single=True)
                    if cmp_result == True:
                        continue

                    # some value to display
                    value = "Loading ..."
                else:
                    value = HtmlElement.eval_update(values)

                if value == None:
                    continue

                results[id] = value

        my.info = {"updates": results, "timestamp": timestamp}

        #print "Dyn Cmd duration", time.time()  - start
        return results
示例#57
0
    def execute(my):
        assert my.search_type
        assert my.view
        assert my.file_path

        search = Search(my.search_type)
        if my.search_ids:
            search.add_enum_order_by("id", my.search_ids)
            search.add_filters("id", my.search_ids)
            sobjects = search.get_sobjects()
        elif my.search_keys:

            sobjects = Search.get_by_search_keys(my.search_keys,
                                                 keep_order=True)
            """
            search_codes = [SearchKey.extract_code(i) for i in my.search_keys if SearchKey.extract_code(i) ]
            if search_codes:
                search.add_filters("code", search_codes)
            else:
                search_ids = [SearchKey.extract_id(i) for i in my.search_keys if SearchKey.extract_id(i) ]
                search.add_filters("id", search_ids)
            """
        else:
            sobjects = search.get_sobjects()

        from pyasm.widget import WidgetConfigView
        from pyasm.web import Widget
        config = WidgetConfigView.get_by_search_type(my.search_type, my.view)

        columns = []
        if my.column_names:
            columns = my.column_names
        # should allow exporting ids only
        """
        else:
            if not config:
                columns = search.get_columns()
            else:
                columns = config.get_element_names()
        """
        if my.include_id:
            columns.insert(0, "id")

        # create the csv file
        org_file = file(my.file_path, 'w')
        csvwriter = csv.writer(org_file, quoting=csv.QUOTE_NONNUMERIC)

        # write the titles
        csvwriter.writerow(columns)

        elements = my.get_elements(config, columns)
        display_option_dict = {}
        # this is for widgets that do preprocessing on all sobjects
        for idx, element in enumerate(elements):
            element.set_sobjects(sobjects)
            element.preprocess()
            display_options = config.get_display_options(columns[idx])
            display_option_dict[element] = display_options

        for idx, sobject in enumerate(sobjects):
            values = []

            for element in elements:

                element.set_current_index(idx)
                value = element.get_text_value()
                if isinstance(value, Widget):
                    value = value.get_buffer_display()
                elif isinstance(value, basestring):
                    if isinstance(value, unicode):
                        value = value.encode('UTF-8', 'ignore')
                else:
                    value = str(value)

                options = display_option_dict.get(element)
                if options.get('csv_force_string') == 'true' and value:
                    value = '#FORCESTRING#%s' % value
                values.append(value)
            # write the values as list
            csvwriter.writerow(values)

        org_file.close()

        file2 = open(my.file_path, 'r')
        mod_file_path = '%s_mod' % my.file_path
        mod_file = open(mod_file_path, 'w')
        for line in file2:
            mod_line = re.sub(r'(\'|\"|)(#FORCESTRING#)', '=\\1', line)
            mod_file.write(mod_line)

        # new file
        file2.close()
        mod_file.close()

        #os.unlink(my.file_path)
        shutil.move(mod_file_path, my.file_path)
示例#58
0
    def get_display(self):
        top = self.top
        top.add_color("background", "background")
        top.add_color("color", "color")
        top.add_style("width", "400px")
        top.add_class('spt_delete_stype_top')
        top.add_border()

        project_code = Project.get_project_code()
        # Note search types should only really be deleted if they were just
        # created

        search_type = self.kwargs.get("search_type")
        if not search_type:
            node_name = self.kwargs.get("node_name")
            if node_name:
                #project_code = Project.get_project_code()
                search_type = "%s/%s" % (project_code, node_name)

        assert search_type
        built_in_stypes = ['task','note','work_hour','login','login_group','schema','project','login_in_group','snapshot','file','trigger','spt_trigger','widget_config','custom_script','notification','notification_log','file_access','cache','exception_log','milestone','pipeline','pref_list','pref_setting','project_type','repo','remote_repo','search_sobject','sobject_list','ticket','db_resource','wdg_settings','status_log','debug_log','transaction_log', 'sobject_log']

        for tbl in built_in_stypes:
            if search_type == 'sthpw/%s'%tbl:
                top.add("sType [%s] is internal and cannot be deleted!" % search_type)
                top.add_style("font-size: 14px")
                top.add_style('padding: 20px')
                return top

        search_type_obj = SearchType.get(search_type)
        if not search_type:
            top.add("sType [%s] does not exist!" % search_type)
            top.add_style("font-size: 14px")
            top.add_style('padding: 20px')
            return top
        table = search_type_obj.get_table()

        db_val = search_type_obj.get_value('database')
        if db_val == '{project}':
            label = ''
        elif db_val == 'sthpw':
            label = 'built-in'
        else:
            label = 'project-specific'

        
        # warn if more than 1 sType point to the same table in the same project
        expr = "@GET(sthpw/search_type['table_name', '%s']['database', 'in',  '{project}|%s']['namespace','%s'].search_type)" %(table, project_code, project_code)
        rtn = Search.eval(expr)
        
        warning_msg = ''
        if len(rtn) > 1:
            warning_msg = 'Warning: There is more than 1 sType [%s] pointing to the same table [%s]. Deleting will affect both sTypes.' %(', '.join(rtn), table)
           
        title_wdg = DivWdg()

        top.add(title_wdg)
        title_wdg.add(IconWdg(icon=IconWdg.WARNING))
        title_wdg.add("Delete %s sType: %s" % (label,search_type))
        title_wdg.add_color("background", "background", -10)
        title_wdg.add_style("font-weight: bold")
        title_wdg.add_style("font-size: 14px")


        content = DivWdg()
        top.add(content)
        content.add_style("padding: 10px")

        if warning_msg:
            content.add(DivWdg(warning_msg, css='warning'))
            content.add("<br/>")
        content.add("This sType uses the table \"%s\" to store items.<br/>" % table)


        content.add("<br/>")

        search = Search(search_type)
        count = search.get_count()
        content.add("Number of items in the table: %s<br/>" % count)

        content.add("<br/>")

        search.add_column("id")
        sobjects = search.get_sobjects()

        if sobjects:
            items_search_type = sobjects[0].get_search_type()

            search_ids = [x.get_id() for x in sobjects]

            notes_search = Search("sthpw/note")
            notes_search.add_filters("search_id", search_ids)
            notes_search.add_filter("search_type", items_search_type)
            note_count = notes_search.get_count()
            cb = CheckboxWdg('related_types')
            cb.set_attr('value', 'sthpw/note')
            content.add(cb)
            content.add(SpanWdg("Number of related notes: %s"% note_count, css='small') )
            content.add(HtmlElement.br())

            tasks_search = Search("sthpw/task")
            tasks_search.add_filters("search_id", search_ids)
            tasks_search.add_filter("search_type", items_search_type)
            task_count = tasks_search.get_count()
            cb = CheckboxWdg('related_types')
            cb.set_attr('value', 'sthpw/task')
            content.add(cb)
            content.add(SpanWdg("Number of related tasks: %s"% task_count, css='small') )
            content.add(HtmlElement.br())


            snapshots_search = Search("sthpw/snapshot")
            snapshots_search.add_filters("search_id", search_ids)
            snapshots_search.add_filter("search_type", items_search_type)
            snapshot_count = snapshots_search.get_count()
            cb = CheckboxWdg('related_types')
            cb.set_attr('value', 'sthpw/snapshot')
            content.add(cb)
            content.add(SpanWdg("Number of related snapshots: %s"% snapshot_count, css='small') )
            content.add(HtmlElement.br())

        pipelines_search = Search("sthpw/pipeline")
        pipelines_search.add_filter("search_type", search_type)
        pipeline_count = pipelines_search.get_count()
        cb = CheckboxWdg('related_types')
        cb.set_attr('value','sthpw/pipeline')
        content.add(cb)
        content.add(SpanWdg("Number of related pipelines: %s"% pipeline_count, css='small') )
        content.add(HtmlElement.br(2))




        content.add("<b>WARNING: Deleting the sType will delete all of these items.</b> ")
        content.add("<br/>"*2)
        content.add("Do you wish to continue deleting?")
        content.add("<br/>"*2)

        button_div = DivWdg()
        button_div.add_styles('width: 300px; height: 50px')
        button = ActionButtonWdg(title="Delete")
        button_div.add(button)
        content.add(button_div)
        button.add_style("float: left")

        button.add_behavior( {
        'type': 'click_up',
        'search_type': search_type,
        'cbjs_action': '''
        spt.app_busy.show("Deleting sType");
        var class_name = "tactic.ui.tools.DeleteSearchTypeCmd";
        var ui_top = bvr.src_el.getParent(".spt_delete_stype_top");
        var values = spt.api.Utility.get_input_values(ui_top);
        var kwargs = {
            'search_type': bvr.search_type,
             'values': values
        };
        var server = TacticServerStub.get();
        try {
            server.start({'title': 'Delete sType', 'description': 'Delete sType [' + bvr.search_type + ']'});
            server.execute_cmd(class_name, kwargs);
            var top = bvr.src_el.getParent(".spt_popup");
            spt.pipeline.remove_node(top.stype_node);

            // force a schema save
            spt.named_events.fire_event('schema|save', bvr)
            top.destroy();
            
            server.finish();
        
        }
        catch(e) {
            spt.alert(spt.exception.handler(e));
        }

        spt.app_busy.hide();

        spt.notify.show_message("Successfully deleted sType ["+bvr.search_type+"]");
       
        '''
        } )



        button = ActionButtonWdg(title="Cancel")
        button.add_style("float: left")
        button_div.add(button)
        button.add_behavior( {
        'type': 'click_up',
        'cbjs_action': '''
        var top = bvr.src_el.getParent(".spt_popup");
        top.destroy();
        '''
        } )


        return top