Beispiel #1
0
    def __init__(self, search_type, config_base, input_prefix='', config=None):

        if type(search_type) in types.StringTypes:
            self.search_type_obj = SearchType.get(search_type)
            self.search_type = search_type
        elif isinstance(search_type, SearchType):
            self.search_type_obj = search_type
            self.search_type = self.search_type_obj.get_base_key() 
        elif inspect.isclass(search_type) and issubclass(search_type, SObject):
            self.search_type_obj = SearchType.get(search_type.SEARCH_TYPE)
            self.search_type = self.search_type_obj.get_base_key()
        else:
            raise LayoutException('search_type must be a string or an sobject')
        self.config = config
        self.config_base = config_base
        self.input_prefix = input_prefix
        self.element_names = []
        self.element_titles = []

        from pyasm.web import DivWdg
        self.top = DivWdg()

        # Layout widgets compartmentalize their widgets in sections for drawing
        self.sections = {}

        super(BaseConfigWdg,self).__init__() 
Beispiel #2
0
    def __init__(my, search_type, config_base, input_prefix='', config=None):

        if type(search_type) in types.StringTypes:
            my.search_type_obj = SearchType.get(search_type)
            my.search_type = search_type
        elif isinstance(search_type, SearchType):
            my.search_type_obj = search_type
            my.search_type = my.search_type_obj.get_base_key() 
        elif inspect.isclass(search_type) and issubclass(search_type, SObject):
            my.search_type_obj = SearchType.get(search_type.SEARCH_TYPE)
            my.search_type = my.search_type_obj.get_base_key()
        else:
            raise LayoutException('search_type must be a string or an sobject')
        my.config = config
        my.config_base = config_base
        my.input_prefix = input_prefix
        my.element_names = []
        my.element_titles = []

        from pyasm.web import DivWdg
        my.top = DivWdg()

        # Layout widgets compartmentalize their widgets in sections for drawing
        my.sections = {}

        super(BaseConfigWdg,my).__init__() 
Beispiel #3
0
 def get_logins_by_id(note_id):
     login_in_group = SearchType.get(LoginInGroup.SEARCH_TYPE)
     group_note = SearchType.get(GroupNotification.SEARCH_TYPE)
     search = Search(Login.SEARCH_TYPE)
     query_str = ''
     
     if isinstance(note_id, list):
         query_str = "in (%s)" %",".join([str(id) for id in note_id])
     else:
         query_str = "= %d" %note_id
     search.add_where('''"login" in (select "login" from "%s" where "login_group" in (select "login_group" from "%s" where "notification_id" %s)) ''' % (login_in_group.get_table(), group_note.get_table(), query_str))
         
         
     return search.get_sobjects()
    def get_display(my):

        widget = Widget()

        div = DivWdg(css="filter_box")

        show_span = SpanWdg(css="med")
        show_span.add("Show All Types: ")
        checkbox = FilterCheckboxWdg("show_all_types")
        checkbox.set_persistence()
        show_span.add(checkbox)
        show_all_types = checkbox.get_value()
        div.add(show_span)

        span = SpanWdg(css="med")
        span.add("Search Type: ")

        select = SelectWdg("filter|search_type")
        select.add_empty_option("-- Select --")
        project = Project.get()
        project_type = project.get_base_type()
        search = Search("sthpw/search_object")
        if show_all_types:
            search.add_where(
                """
            namespace = '%s' or namespace = '%s' or search_type in ('sthpw/task')
            """
                % (project_type, project.get_code())
            )
        else:
            # show only the custom ones
            search.add_filter("namespace", project.get_code())

        search.add_order_by("title")
        sobjects = search.get_sobjects()

        select.set_sobjects_for_options(sobjects, "search_type", "title")
        # select.set_option("query", "sthpw/search_object|search_type|title")
        select.set_persistence()
        select.add_event("onchange", "document.form.submit()")
        search_type = select.get_value()
        span.add(select)
        div.add(span)

        # make sure the current selection exists
        try:
            SearchType.get(search_type)
        except SearchException, e:
            return div
Beispiel #5
0
    def get_logins_by_id(note_id):
        login_in_group = SearchType.get(LoginInGroup.SEARCH_TYPE)
        group_note = SearchType.get(GroupNotification.SEARCH_TYPE)
        search = Search(Login.SEARCH_TYPE)
        query_str = ''

        if isinstance(note_id, list):
            query_str = "in (%s)" % ",".join([str(id) for id in note_id])
        else:
            query_str = "= %d" % note_id
        search.add_where(
            '''"login" in (select "login" from "%s" where "login_group" in (select "login_group" from "%s" where "notification_id" %s)) '''
            % (login_in_group.get_table(), group_note.get_table(), query_str))

        return search.get_sobjects()
    def get_columns(my, required_only=False):
        if my.search_type == 'sthpw/virtual':
            return []

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

        from pyasm.biz import Project
        db_resource = Project.get_db_resource_by_search_type(my.search_type)
        database_name = db_resource.get_database()
        db = DbContainer.get(db_resource)

        # table may not exist
        try:
            all_columns = db.get_columns(table)
            columns = []
            if required_only:
                nullables = db.get_column_nullables(table)
                for column in all_columns:
                    null_ok = nullables.get(column)
                    if not null_ok:
                        columns.append(column)

                # if there are no required columns
                if not columns:
                    columns = all_columns 
                
            else:
                columns = all_columns 
        except SqlException:
            Environment.add_warning('missing table', 'Table [%s] does not exist in database [%s]' %(table, database_name))
            return  []

        return columns
Beispiel #7
0
 def get_groups_by_code(note_code):
     group_note = SearchType.get(GroupNotification.SEARCH_TYPE)
     
     search = Search(LoginGroup.SEARCH_TYPE)
     search.add_where('''"login_group" in (select "login_group" from "%s" where "notification_code" = '%s')''' %(group_note.get_table(), note_code))
         
     return search.get_sobjects()
Beispiel #8
0
    def get_full_search_type(cls,
                             search_type,
                             project_code=None,
                             project=None):
        if type(search_type) in types.StringTypes:
            if search_type.find("?") == -1:
                base_key = search_type
            else:
                # if there is a project, just use it
                return search_type
        else:
            base_key = search_type.get_base_key()

        if base_key.startswith("sthpw/"):
            full_key = base_key
            return full_key

        if project_code:
            code = project_code
        elif project:
            code = project.get_code()
        else:
            # get the current project
            #code = Project.get_global_project_code()
            search_type_obj = SearchType.get(base_key)
            code = search_type_obj.get_database()

        # NOTE: if someone expliclity set the Project.set('sthpw') before this,
        # it will affect the full key of this sobject
        # prevent sthpw projects from having a "project=" at the end
        if code in ["sthpw", "admin"]:
            full_key = base_key
        else:
            full_key = "%s?project=%s" % (base_key, code)
        return full_key
Beispiel #9
0
    def prod_render(my, dirs):
        dirs = my.get_default(dirs)

        search_type = SearchType.get( my.sobject.get_value("search_type") )
        table = search_type.get_table()
        dirs.append( table )

        base_search_type = search_type.get_base_search_type()

        parent = my.sobject.get_parent()

        if base_search_type =='prod/layer':
            shot_code = parent.get_value('shot_code')
            name = parent.get_value('name')
            dirs.append(shot_code)
            dirs.append(name)
        else:
            code = parent.get_code()
            dirs.append( code )

        if my.snapshot:
            version = my.snapshot.get_value("version")
        if not version:
            version = 1
        dirs.append("v%0.3d" % int(version))

        return dirs
Beispiel #10
0
    def get_by_search_type(cls, search_type, project_code=''):
        # make sure this is a be search type
        assert search_type
        search_type_obj = SearchType.get(search_type)
        if not search_type_obj:
            return []
        search_type = search_type_obj.get_base_key()

        cache_key = "%s|%s" % (search_type, project_code)


        # commenting out until we have a full implementation of
        # project pipelines
        """
        search = Search("config/pipeline")
        if search_type:
            search.add_filter("search_type", search_type)
        search.add_project_filter(project_code)
        pipelines = cls.get_by_search(search, cache_key, is_multi=True)
        """

        
        search = Search("sthpw/pipeline")
        if search_type:
            search.add_filter("search_type", search_type)
        search.add_project_filter(project_code)
        pipelines = cls.get_by_search(search, cache_key, is_multi=True)
        if not pipelines:
            return []
        for pipe in pipelines:
            code = pipe.get_code()
            cls.cache_sobject('sthpw/pipeline|%s' %code, pipe)
        return pipelines
Beispiel #11
0
    def has_table(my, search_type):
        if isinstance(search_type, basestring):
            search_type = SearchType.get(search_type)


        # in search type database == project 
        project_code = search_type.get_project_code()

        # get the db_resource for this project
        db_resource = my.get_project_db_resource()

        # get the table
        table = search_type.get_table()
        if not table:
            return False

        try:
            # looking up a database's tables other than the current one
            sql = DbContainer.get(db_resource)
            tables = sql.get_tables()
            has_table = table in tables
        except Exception, e:
            print "WARNING: in Project.has_table(): table [%s] not found" % table
            print "Message: ", e
            has_table = False
Beispiel #12
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()
Beispiel #13
0
    def get_display(my):

        project = Project.get()
        search_types = project.get_search_types()

        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()
Beispiel #14
0
    def get_display(my):

        widget = Widget()

        if not my.select:
            return widget

        if not my.schema:
            Environment.add_warning("No schema defined")
            widget.add("No schema defined")
            return widget


        if not my.search_type:
            Environment.add_warning("HierarchicalFilterWdg: Cannot find current search_type")
            widget.add("Cannot find current search_type")
            return widget

        span = SpanWdg(css="med")
        parent_type = my.get_parent_type()
        if parent_type:
            parent_type_obj = SearchType.get(parent_type)
            span.add("%s: " % parent_type_obj.get_value("title"))

        # assume that there is a code in the parent
        my.select.add_empty_option("-- Select --")
        my.select.set_option("query", "%s|code|code" % my.parent_type)
        span.add(my.select)

        widget.add(span)

        return widget
Beispiel #15
0
    def prod_render(self, dirs):
        dirs = self.get_default(dirs)

        search_type = SearchType.get(self.sobject.get_value("search_type"))
        table = search_type.get_table()
        dirs.append(table)

        base_search_type = search_type.get_base_search_type()

        parent = self.sobject.get_parent()

        if base_search_type == 'prod/layer':
            shot_code = parent.get_value('shot_code')
            name = parent.get_value('name')
            dirs.append(shot_code)
            dirs.append(name)
        else:
            code = parent.get_code()
            dirs.append(code)

        if self.snapshot:
            version = self.snapshot.get_value("version")
        if not version:
            version = 1
        dirs.append("v%0.3d" % int(version))

        return dirs
Beispiel #16
0
    def get_by_search_type(cls, search_type, project_code=''):
        # make sure this is a be search type
        assert search_type
        search_type_obj = SearchType.get(search_type)
        if not search_type_obj:
            return []
        search_type = search_type_obj.get_base_key()

        cache_key = "%s|%s" % (search_type, project_code)

        # commenting out until we have a full implementation of
        # project pipelines
        """
        search = Search("config/pipeline")
        if search_type:
            search.add_filter("search_type", search_type)
        search.add_project_filter(project_code)
        pipelines = cls.get_by_search(search, cache_key, is_multi=True)
        """

        search = Search("sthpw/pipeline")
        if search_type:
            search.add_filter("search_type", search_type)
        search.add_project_filter(project_code)
        pipelines = cls.get_by_search(search, cache_key, is_multi=True)
        if not pipelines:
            return []
        for pipe in pipelines:
            code = pipe.get_code()
            cls.cache_sobject('sthpw/pipeline|%s' % code, pipe)
        return pipelines
Beispiel #17
0
    def copy_sobject(my,
                     sobject,
                     dst_search_type,
                     context=None,
                     checkin_mode='inplace'):

        new_sobject = SearchType.create(dst_search_type)
        search_type = SearchType.get(dst_search_type)
        columns = SearchType.get_columns(dst_search_type)

        data = sobject.get_data()
        for name, value in data.items():
            if name in ['id', 'code', 'pipeline_code']:
                continue

            if name not in columns:
                continue

            if not value:
                continue
            new_sobject.set_value(name, value)

        new_sobject.commit()

        # get all of the current snapshots and file paths associated
        if not context:
            snapshots = Snapshot.get_all_current_by_sobject(sobject)
        else:
            snapshots = [Snapshot.get_current_by_sobject(sobject, context)]

        if not snapshots:
            return

        msgs = []
        for snapshot in snapshots:
            #file_paths = snapshot.get_all_lib_paths()
            file_paths_dict = snapshot.get_all_paths_dict()
            file_types = file_paths_dict.keys()
            if not file_types:
                continue

            # make sure the paths match the file_types
            file_paths = [file_paths_dict.get(x)[0] for x in file_types]

            mode = checkin_mode

            # checkin the files (inplace)
            try:
                context = snapshot.get_value('context')
                checkin = FileCheckin(new_sobject,
                                      context=context,
                                      file_paths=file_paths,
                                      file_types=file_types,
                                      mode=mode)
                checkin.execute()

                #print "done: ", context, new_sobject.get_related_sobjects("sthpw/snapshot")
            except CheckinException, e:
                msgs.append('Post-process Check-in Error for %s: %s ' %
                            (context, e.__str__()))
Beispiel #18
0
    def copy_sobject(my, sobject, dst_search_type, context=None, checkin_mode='inplace'):

        new_sobject = SearchType.create(dst_search_type)
        search_type = SearchType.get(dst_search_type)
        columns = SearchType.get_columns(dst_search_type)

        data = sobject.get_data()
        for name, value in data.items():
            if name in ['id','pipeline_code']:
                continue

            if name not in columns:
                continue

            if not value:
                continue

            if name == "code":
                value = Common.get_next_sobject_code(sobject, 'code')
                if not value:
                    continue
            new_sobject.set_value(name, value)
        if SearchType.column_exists(dst_search_type, "project_code"):
            project_code = Project.get_project_code()
            new_sobject.set_value("project_code", project_code)
        new_sobject.commit()



        # get all of the current snapshots and file paths associated
        if not context:
            snapshots = Snapshot.get_all_current_by_sobject(sobject)
        else:
            snapshots = [Snapshot.get_current_by_sobject(sobject, context)]

        if not snapshots:
            return

        msgs = []
        for snapshot in snapshots:
            #file_paths = snapshot.get_all_lib_paths()
            file_paths_dict = snapshot.get_all_paths_dict()
            file_types = file_paths_dict.keys()
            if not file_types:
                continue

            # make sure the paths match the file_types
            file_paths = [file_paths_dict.get(x)[0] for x in file_types]

            mode = checkin_mode

            # checkin the files (inplace)
            try:
                context = snapshot.get_value('context')
                checkin = FileCheckin(new_sobject, context=context, file_paths=file_paths, file_types=file_types, mode=mode)
                checkin.execute()

                #print "done: ", context, new_sobject.get_related_sobjects("sthpw/snapshot")
            except CheckinException, e:
                msgs.append('Post-process Check-in Error for %s: %s ' %(context, e.__str__()))
    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()
Beispiel #20
0
    def delete(my,log=False):
        column = my.get_value("name")

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

        table = search_type_obj.get_table()
        database = search_type_obj.get_database()

        # remove it from the table
        if log:
            AlterTableUndo.log_drop(database, table, column)
            sql = DbContainer.get(database)
            try:

                from pyasm.search.sql import Sql
                if Sql.get_database_type() == 'SQLServer':
                    statement = 'ALTER TABLE [%s] DROP "%s" %s' % \
                        (table, column)
                else:
                    statement = 'ALTER TABLE "%s" DROP COLUMN "%s"' % (table, column) 

                sql.do_update(statement)
            except SqlException, e:
                print("WARNING: %s" % e )
Beispiel #21
0
    def has_table(my, search_type):
        if isinstance(search_type, basestring):
            search_type = SearchType.get(search_type)


        # in search type database == project 
        project_code = search_type.get_project_code()

        # get the db_resource for this project
        db_resource = my.get_project_db_resource()

        # get the table
        table = search_type.get_table()
        if not table:
            return False

        try:
            # looking up a database's tables other than the current one
            sql = DbContainer.get(db_resource)
            tables = sql.get_tables()
            has_table = table in tables
        except Exception, e:
            print "WARNING: in Project.has_table(): table [%s] not found" % table
            print "Message: ", e
            has_table = False
Beispiel #22
0
    def delete(my, log=False):
        column = my.get_value("name")

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

        table = search_type_obj.get_table()
        database = search_type_obj.get_database()

        # remove it from the table
        if log:
            AlterTableUndo.log_drop(database, table, column)
            sql = DbContainer.get(database)
            try:

                from pyasm.search.sql import Sql
                if Sql.get_database_type() == 'SQLServer':
                    statement = 'ALTER TABLE [%s] DROP "%s" %s' % \
                        (table, column)
                else:
                    statement = 'ALTER TABLE "%s" DROP COLUMN "%s"' % (table,
                                                                       column)

                sql.do_update(statement)
            except SqlException, e:
                print("WARNING: %s" % e)
Beispiel #23
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
Beispiel #24
0
    def get_display(self):

        widget = Widget()

        if not self.select:
            return widget

        if not self.schema:
            Environment.add_warning("No schema defined")
            widget.add("No schema defined")
            return widget


        if not self.search_type:
            Environment.add_warning("HierarchicalFilterWdg: Cannot find current search_type")
            widget.add("Cannot find current search_type")
            return widget

        span = SpanWdg(css="med")
        parent_type = self.get_parent_type()
        if parent_type:
            parent_type_obj = SearchType.get(parent_type)
            span.add("%s: " % parent_type_obj.get_value("title"))

        # assume that there is a code in the parent
        self.select.add_empty_option("-- Select --")
        self.select.set_option("query", "%s|code|code" % self.parent_type)
        span.add(self.select)

        widget.add(span)

        return widget
    def get_display(my):

        widget = Widget()

        div = DivWdg(css="filter_box")

        show_span = SpanWdg(css='med')
        show_span.add('Show All Types: ')
        checkbox = FilterCheckboxWdg('show_all_types')
        checkbox.set_persistence()
        show_span.add(checkbox)
        show_all_types = checkbox.get_value()
        div.add(show_span)

        span = SpanWdg(css="med")
        span.add("Search Type: ")

        select = SelectWdg("filter|search_type")
        select.add_empty_option("-- Select --")
        project = Project.get()
        project_type = project.get_base_type()
        search = Search("sthpw/search_object")
        if show_all_types:
            search.add_where('''
            namespace = '%s' or namespace = '%s' or search_type in ('sthpw/task')
            ''' % (project_type, project.get_code()))
        else:
            # show only the custom ones
            search.add_filter('namespace', project.get_code())

        search.add_order_by("title")
        sobjects = search.get_sobjects()

        select.set_sobjects_for_options(sobjects, "search_type", "title")
        #select.set_option("query", "sthpw/search_object|search_type|title")
        select.set_persistence()
        select.add_event("onchange", "document.form.submit()")
        search_type = select.get_value()
        span.add(select)
        div.add(span)

        # make sure the current selection exists
        try:
            SearchType.get(search_type)
        except SearchException, e:
            return div
Beispiel #26
0
def execute(db_resource):

    # This works if there is a project set up already with the appropriate
    # db_resource.
    search_type = "table/foofoo?project=db2_test"
    search_type_obj = SearchType.get(search_type)
    search = Search(search_type)
    sobjects = search.get_sobjects()
    print "length: ", len(sobjects)

    # or (note that there is no project here).  The two arguments
    # are sufficient to determine a search.  Here we want to just "casually"
    # connect to a separate database resource.
    table = 'foofoo'
    search = db_resource.get_search(table)
    sobjects = search.get_sobjects()
    print "length: ", len(sobjects)
    for sobject in sobjects:
        print sobject.get_code(), sobject.get_value("description")

    table = 'widget_config'
    search = db_resource.get_search(table)
    sobjects = search.get_sobjects()
    print "length: ", len(sobjects)
    for sobject in sobjects:
        print sobject.get_code(), sobject.get_value("config")

    db_resource = DbResource(vendor="MySQL", database="fifi", user="******")
    introspect = DbIntrospect()
    introspect.register("fifi", db_resource)
    table = 'cards'
    search = db_resource.get_search(table)
    sobjects = search.get_sobjects()
    print "length: ", len(sobjects)
    for sobject in sobjects:
        print sobject.get_code(), sobject.get_value("description")

    print "sqlite: transaction_log"
    db_resource = DbResource.get_by_code('sqlite', 'sthpw')
    introspect = DbIntrospect()
    introspect.register("sqlite", db_resource)
    search = db_resource.get_search("transaction_log")
    sobjects = search.get_sobjects()
    print "length: ", len(sobjects)

    print "mysql: fifi"
    db_resource = DbResource.get_by_code('mysql', 'fifi')
    introspect = DbIntrospect()
    introspect.register("fifi", db_resource)
    search = db_resource.get_search("cards")
    sobjects = search.get_sobjects()
    print "length: ", len(sobjects)

    print "mysql: fifi"
    search_type = "table/node0?project=db3_test"
    search = Search(search_type)
    sobjects = search.get_sobjects()
    print "length: ", len(sobjects)
Beispiel #27
0
    def get_groups_by_code(note_code):
        group_note = SearchType.get(GroupNotification.SEARCH_TYPE)

        search = Search(LoginGroup.SEARCH_TYPE)
        search.add_where(
            '''"login_group" in (select "login_group" from "%s" where "notification_code" = '%s')'''
            % (group_note.get_table(), note_code))

        return search.get_sobjects()
Beispiel #28
0
    def get_sobjects_by_node(my, node):
        # get the sobjects        
        search_type = my.xml.get_attribute(node, "search_type")
        expr = my.xml.get_attribute(node, "expression")
        code = my.xml.get_attribute(node, "code")

        try:
            search_type = SearchType.get(search_type)
        except SearchException, e:
            return []
Beispiel #29
0
    def get_sobjects_by_node(my, node):
        # get the sobjects        
        search_type = my.xml.get_attribute(node, "search_type")
        expr = my.xml.get_attribute(node, "expression")
        code = my.xml.get_attribute(node, "code")

        try:
            search_type = SearchType.get(search_type)
        except SearchException, e:
            return []
Beispiel #30
0
    def get_data_type(cls, search_type, attr_type):
        search_type_obj = SearchType.get(search_type)

        db_resource = Project.get_db_resource_by_search_type(search_type)
        sql = DbContainer.get(db_resource)
        impl = sql.get_database_impl()


        # SearchType Manager and Add Widget Column use mixed upper and
        # lowercases for the following attr_type, so fix it at some point
        if not attr_type:
            attr_type = "varchar"

        if attr_type == "integer":
            data_type = impl.get_int() 
        elif attr_type == "float":
            data_type = "float"
        elif attr_type == "boolean":
            data_type = impl.get_boolean()
        elif attr_type == "link":
            data_type = "text"
        elif attr_type.startswith('varchar'):
            data_type = attr_type

        elif attr_type == 'time':
            data_type = impl.get_timestamp()
        elif attr_type in ["Date", "date"]:
            data_type = impl.get_timestamp()
        elif attr_type == "Category":
            data_type = "varchar(256)"
        elif attr_type in ["text", "Text"]:
            data_type = impl.get_text()
        elif attr_type in ["Date Range", 'timestamp']:
            data_type = impl.get_timestamp()
        elif attr_type == "Checkbox":
            data_type = "varchar(256)"
        elif attr_type in ["Foreign Key", "foreign_key"]:
            data_type = "varchar(256)"
        elif attr_type in ["List", "list"]:
            data_type = "varchar(512)"
        elif attr_type == "Name/Code":
            data_type = "varchar(256)"
        elif attr_type == "Number":
            data_type = impl.get_int() 

        elif attr_type in ["currency", "scientific", "percent"]:
            data_type = "float"
        elif attr_type == "timecode":
            data_type = impl.get_int() 

        else:
            #data_type = "varchar(256)"
            data_type = impl.get_varchar()

        return data_type
Beispiel #31
0
    def get_data_type(cls, search_type, attr_type):
        search_type_obj = SearchType.get(search_type)

        db_resource = Project.get_db_resource_by_search_type(search_type)
        sql = DbContainer.get(db_resource)
        impl = sql.get_database_impl()


        # SearchType Manager and Add Widget Column use mixed upper and
        # lowercases for the following attr_type, so fix it at some point
        if not attr_type:
            attr_type = "varchar"

        if attr_type == "integer":
            data_type = impl.get_int() 
        elif attr_type == "float":
            data_type = "float"
        elif attr_type == "boolean":
            data_type = impl.get_boolean()
        elif attr_type == "link":
            data_type = "text"
        elif attr_type.startswith('varchar'):
            data_type = attr_type

        elif attr_type == 'time':
            data_type = impl.get_timestamp()
        elif attr_type in ["Date", "date"]:
            data_type = impl.get_timestamp()
        elif attr_type == "Category":
            data_type = "varchar(256)"
        elif attr_type in ["text", "Text"]:
            data_type = impl.get_text()
        elif attr_type in ["Date Range", 'timestamp']:
            data_type = impl.get_timestamp()
        elif attr_type == "Checkbox":
            data_type = "varchar(256)"
        elif attr_type in ["Foreign Key", "foreign_key"]:
            data_type = "varchar(256)"
        elif attr_type in ["List", "list"]:
            data_type = "varchar(512)"
        elif attr_type == "Name/Code":
            data_type = "varchar(256)"
        elif attr_type == "Number":
            data_type = impl.get_int() 

        elif attr_type in ["currency", "scientific", "percent"]:
            data_type = "float"
        elif attr_type == "timecode":
            data_type = impl.get_int() 

        else:
            #data_type = "varchar(256)"
            data_type = impl.get_varchar()

        return data_type
Beispiel #32
0
    def execute(self):    
        search_type_obj = SearchType.get(self.search_type)
        database = search_type_obj.get_database()
        table = search_type_obj.get_table()

        alter = AlterTable(self.search_type)
        alter.drop(self.attr_name)

        # log it first before committing
        AlterTableUndo.log_drop(database,table, self.attr_name)
        alter.commit()  
Beispiel #33
0
    def execute(my):    
        search_type_obj = SearchType.get(my.search_type)
        database = search_type_obj.get_database()
        table = search_type_obj.get_table()

        alter = AlterTable(my.search_type)
        alter.drop(my.attr_name)

        # log it first before committing
        AlterTableUndo.log_drop(database,table, my.attr_name)
        alter.commit()  
Beispiel #34
0
    def check(my):
        my.search_type = my.kwargs.get("search_type")
        my.values = my.kwargs.get("values")

        my.db_resource = SearchType.get_db_resource_by_search_type(my.search_type)
        my.database = my.db_resource.get_database()
        my.search_type_obj = SearchType.get(my.search_type)
        if my.database != Project.get_project_code() and my.database !='sthpw':
            raise TacticException('You are not allowed to delete the sType [%s] from another project [%s].' %(my.search_type, my.database))
            return False
        
        return True
Beispiel #35
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()
Beispiel #36
0
    def do_search(my):
        '''this widget has its own search mechanism'''

        web = WebContainer.get_web()

        # get the sobject that is to be edited
        id = my.search_id

        # if no id is given, then create a new one for insert
        search = None
        sobject = None
        search_type_base = SearchType.get(my.search_type).get_base_key()
        if my.mode == "insert":
            sobject = SearchType.create(my.search_type)
            my.current_id = -1
            # prefilling default values if available
            value_keys = web.get_form_keys()
            if value_keys:

                for key in value_keys:
                    value = web.get_form_value(key)
                    sobject.set_value(key, value)
        else:
            search = Search(my.search_type)

            # figure out which id to search for
            if web.get_form_value("do_edit") == "Edit/Next":
                search_ids = web.get_form_value("%s_search_ids" %
                                                search_type_base)
                if search_ids == "":
                    my.current_id = id
                else:
                    search_ids = search_ids.split("|")
                    next = search_ids.index(str(id)) + 1
                    if next == len(search_ids):
                        next = 0
                    my.current_id = search_ids[next]

                    last_search = Search(my.search_type)
                    last_search.add_id_filter(id)
                    my.last_sobject = last_search.get_sobject()

            else:
                my.current_id = id

            search.add_id_filter(my.current_id)
            sobject = search.get_sobject()

        if not sobject and my.current_id != -1:
            raise EditException("No SObject found")

        # set all of the widgets to contain this sobject
        my.set_sobjects([sobject], search)
Beispiel #37
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()
Beispiel #38
0
    def check(my):
        my.search_type = my.kwargs.get("search_type")
        my.values = my.kwargs.get("values")

        my.db_resource = SearchType.get_db_resource_by_search_type(my.search_type)
        my.database = my.db_resource.get_database()
        my.search_type_obj = SearchType.get(my.search_type)
        if my.database != Project.get_project_code() and my.database !='sthpw':
            raise TacticException('You are not allowed to delete the sType [%s] from another project [%s].' %(my.search_type, my.database))
            return False
        
        return True
Beispiel #39
0
    def check(self):
        self.search_type = self.kwargs.get("search_type")
        self.values = self.kwargs.get("values")

        self.db_resource = SearchType.get_db_resource_by_search_type(self.search_type)
        self.database = self.db_resource.get_database()
        self.search_type_obj = SearchType.get(self.search_type)
        if self.database != Project.get_project_code() and self.database !='sthpw':
            raise TacticException('You are not allowed to delete the sType [%s] from another project [%s].' %(self.search_type, self.database))
            return False
        
        return True
Beispiel #40
0
    def do_search(my):
        '''this widget has its own search mechanism'''

        web = WebContainer.get_web()
        
        # get the sobject that is to be edited
        id = my.search_id

        # if no id is given, then create a new one for insert
        search = None
        sobject = None
        search_type_base = SearchType.get(my.search_type).get_base_key()
        if my.mode == "insert":
            sobject = SearchType.create(my.search_type)
            my.current_id = -1
            # prefilling default values if available
            value_keys = web.get_form_keys()
            if value_keys:
                
                for key in value_keys:
                    value = web.get_form_value(key)
                    sobject.set_value(key, value)
        else:
            search = Search(my.search_type)

            # figure out which id to search for
            if web.get_form_value("do_edit") == "Edit/Next":
                search_ids = web.get_form_value("%s_search_ids" %search_type_base)
                if search_ids == "":
                    my.current_id = id
                else:
                    search_ids = search_ids.split("|")
                    next = search_ids.index(str(id)) + 1
                    if next == len(search_ids):
                        next = 0
                    my.current_id = search_ids[next]

                    last_search = Search(my.search_type)
                    last_search.add_id_filter( id )
                    my.last_sobject = last_search.get_sobject()

            else:
                my.current_id = id

            search.add_id_filter( my.current_id )
            sobject = search.get_sobject()

        if not sobject and my.current_id != -1:
            raise EditException("No SObject found")

        # set all of the widgets to contain this sobject
        my.set_sobjects( [sobject], search )
Beispiel #41
0
    def get_items(self):
        if not self.item_sobj:
            return []
        search = Search(self.item_cls.SEARCH_TYPE)
        query = "%s in (select %s from %s where \
            %s = '%s')"                        % (self.item_sobj.get_primary_key(), \
            self.item_sobj.get_foreign_key(), \
            SearchType.get(self.grouping_cls.SEARCH_TYPE).get_table(),\
            self.group.get_foreign_key(),\
            self.group.get_value(self.group.get_primary_key()))

        search.add_where(query)
        return search.get_sobjects()
Beispiel #42
0
    def get_path_from_node(my, node):
        path = my.xml.get_attribute(node, "path")
        if not path:
            search_type = my.xml.get_attribute(node, "search_type")
            if search_type:
                search_type_obj = SearchType.get(search_type)
                search_type = search_type_obj.get_base_key()
                path = "%s.spt" % search_type.replace("/","_")

        if path:
            path = "%s/%s" % (my.plugin_dir, path)

        return path
Beispiel #43
0
    def get_items(my):
        if not my.item_sobj:
            return []
        search = Search(my.item_cls)
        query = "%s in (select %s from %s where \
            %s = '%s')"                        % (my.item_sobj.get_primary_key(), \
            my.item_sobj.get_foreign_key(), \
            SearchType.get(my.grouping_cls).get_table(),\
            my.group.get_foreign_key(),\
            my.group.get_value(my.group.get_primary_key()))

        search.add_where(query)
        return search.get_sobjects()
Beispiel #44
0
    def get_path_from_node(my, node):
        path = my.xml.get_attribute(node, "path")
        if not path:
            search_type = my.xml.get_attribute(node, "search_type")
            if search_type:
                search_type_obj = SearchType.get(search_type)
                search_type = search_type_obj.get_base_key()
                path = "%s.spt" % search_type.replace("/","_")

        if path:
            path = "%s/%s" % (my.plugin_dir, path)

        return path
Beispiel #45
0
    def execute(my):    
        search_type_obj = SearchType.get(my.search_type)
        database = search_type_obj.get_database()
        table = search_type_obj.get_table()

        alter = AlterTable(my.search_type)
        #TODO: check the varchar length and put it in
        alter.modify(my.attr_name, my.data_type, not_null=not my.nullable)

        # log it first before committing to get the corrent from and to data type
        AlterTableUndo.log_modify(database,table, my.attr_name, \
             my.data_type, not my.nullable)
        alter.commit()
Beispiel #46
0
 def get_items(my):
     if not my.item_sobj:
         return []
     search = Search( my.item_cls )
     query = "%s in (select %s from %s where \
         %s = '%s')" % (my.item_sobj.get_primary_key(), \
         my.item_sobj.get_foreign_key(), \
         SearchType.get(my.grouping_cls).get_table(),\
         my.group.get_foreign_key(),\
         my.group.get_value(my.group.get_primary_key()))
     
     search.add_where(query)    
     return search.get_sobjects()
Beispiel #47
0
    def execute(self):    
        search_type_obj = SearchType.get(self.search_type)
        database = search_type_obj.get_database()
        table = search_type_obj.get_table()

        alter = AlterTable(self.search_type)
        #TODO: check the varchar length and put it in
        alter.modify(self.attr_name, self.data_type, not_null=not self.nullable)

        # log it first before committing to get the corrent from and to data type
        AlterTableUndo.log_modify(database,table, self.attr_name, \
             self.data_type, not self.nullable)
        alter.commit()
Beispiel #48
0
 def _get_target_sobject_data(asset):
     '''get the info data for the Info column of the submission'''
     data = 'Unknown'
     if not asset:
         return data
     title = SearchType.get(asset.get_search_type()).get_title()
     data = ''
     if asset.has_value('code'):
         if asset.has_value('name'):
             data = '%s: %s_%s' % \
                     (title, asset.get_code(), asset.get_value('name'))
         else:
             data = '%s: %s' % (title, asset.get_code())
     return data
Beispiel #49
0
 def _get_target_sobject_data(asset):
     '''get the info data for the Info column of the submission'''
     data = 'Unknown'
     if not asset:
         return data
     title = SearchType.get(asset.get_search_type()).get_title()
     data = ''
     if asset.has_value('code'):
         if asset.has_value('name'):
             data = '%s: %s_%s' % \
                     (title, asset.get_code(), asset.get_value('name'))
         else:
             data = '%s: %s' % (title, asset.get_code())
     return data
Beispiel #50
0
    def get_sobject_wdg(self,
                        sobject,
                        search_type,
                        view="table",
                        title="",
                        show_count=True):

        key = search_type

        search_type_obj = SearchType.get(search_type)
        if not title:
            title = search_type_obj.get_title()

        content_id = 'sub_sobj_%s_%s' % (key, sobject.get_id())
        title_id = '%s_head_%s' % (key, sobject.get_id())

        div = DivWdg(id=content_id)
        div.add_style('display', 'none')
        #div.add_style('width','100%')

        head = DivWdg()
        head.add_style('height', '1.8em')
        title_span = self._get_title_span(title)

        dyn_load = AjaxLoader(display_id=content_id)

        args_dict = {'sobj_search_type': sobject.get_search_type()}
        args_dict['search_id'] = sobject.get_id()
        args_dict['search_type'] = search_type
        args_dict['view'] = view

        dyn_load.set_load_method('_get_sobject_wdg')
        dyn_load.set_load_class(Common.get_full_class_name(self),
                                load_args=args_dict)
        on_script = dyn_load.get_on_script(load_once=True)

        swap_wdg = self._get_swap_wdg(title_id)
        swap_wdg.add_action_script(on_script,
                                   "toggle_display('%s')" % content_id)

        head.add(swap_wdg)
        head.add(title_span)
        self.add_title_style(title_span, title_id, swap_wdg)

        if show_count:
            search = self._get_sobject_search(sobject, search_type)
            title_span.add(" ( %s )" % search.get_count())

        return head, div
Beispiel #51
0
    def extract_project_code(cls, search_type):
        base_search_type, data = SearchKey._get_data(search_type)
        project_code = data.get("project")
        if project_code == None:
            # this is specifically for project-specific sType
            search_type_obj = SearchType.get(search_type)
            database = search_type_obj.get_value("database")
            if database != "{project}":
                project_code = database
            else:
                # get the global project code
                project_code = Project.get_project_code()

            #project_code = cls.get_global_project_code()
        return project_code
Beispiel #52
0
    def init(my):

        my.is_refresh = my.kwargs.get('is_refresh') 
        my.file_path = my.kwargs.get('file_path') 
        my.search_type = my.kwargs.get('search_type')
        my.search_type_obj = SearchType.get(my.search_type)
        web = WebContainer.get_web()
        my.encoder = web.get_form_value('encoder')
        title_row_checkbox = CheckboxWdg("has_title")

        my.has_title = title_row_checkbox.is_checked()

        lowercase_title_checkbox = CheckboxWdg("lowercase_title")

        my.lowercase_title = lowercase_title_checkbox.is_checked()
Beispiel #53
0
    def init(my):

        my.is_refresh = my.kwargs.get('is_refresh') 
        my.file_path = my.kwargs.get('file_path') 
        my.search_type = my.kwargs.get('search_type')
        my.search_type_obj = SearchType.get(my.search_type)
        web = WebContainer.get_web()
        my.encoder = web.get_form_value('encoder')
        title_row_checkbox = CheckboxWdg("has_title")

        my.has_title = title_row_checkbox.is_checked()

        lowercase_title_checkbox = CheckboxWdg("lowercase_title")

        my.lowercase_title = lowercase_title_checkbox.is_checked()
Beispiel #54
0
    def extract_project_code(cls, search_type):
        base_search_type, data = SearchKey._get_data(search_type)
        project_code = data.get("project")
        if project_code == None:
            # this is specifically for project-specific sType
            search_type_obj = SearchType.get(search_type)
            database = search_type_obj.get_value("database")
            if database != "{project}":
                project_code = database
            else:
                # get the global project code
                project_code = Project.get_project_code()

            #project_code = cls.get_global_project_code()
        return project_code
Beispiel #55
0
    def get_next_job(job_search_type="sthpw/queue",
                     queue_type=None,
                     server_code=None):

        sql = DbContainer.get("sthpw")

        search_type_obj = SearchType.get(job_search_type)
        table = search_type_obj.get_table()

        # get the entire queue
        search = Search(job_search_type)
        if queue_type:
            search.add_filter("queue", queue_type)
        if server_code:
            search.add_filter("server_code", server_code)
        search.add_filter("state", "pending")

        search.add_order_by("priority")
        search.add_order_by("timestamp")

        chunk = 10
        search.add_limit(chunk)

        queues = search.get_sobjects()
        queue_id = 0

        for queue in queues:

            queue_id = queue.get_id()

            # attempt to lock this queue
            # have to do this manually
            update = """UPDATE "%s" SET state = 'locked' where id = '%s' and state = 'pending'""" % (
                table, queue_id)

            sql.do_update(update)
            row_count = sql.get_row_count()

            if row_count == 1:
                break
            else:
                queue_id = 0

        if queue_id:
            queue = Search.get_by_id(job_search_type, queue_id)
            return queue
        else:
            return None
Beispiel #56
0
    def execute(my):
        search_type_obj = SearchType.get(my.search_type)
        table = search_type_obj.get_table()

        db_resource = Project.get_db_resource_by_search_type(my.search_type)
        sql = DbContainer.get(db_resource)

        index_name = "%s_%s_idx" % (table, my.column)
        
        if my.constraint == "unique":
            statement = 'ALTER TABLE "%s" add constraint "%s" UNIQUE ("%s")' % (table, index_name, my.column)
        else:
            statement = 'CREATE INDEX "%s" ON "%s" ("%s")' % (index_name, table, my.column)

        sql.do_update(statement)
        sql.commit() 
Beispiel #57
0
    def check(self):
        self.search_type = self.kwargs.get("search_type")
        self.values = self.kwargs.get("values")

        self.db_resource = SearchType.get_db_resource_by_search_type(
            self.search_type)
        self.database = self.db_resource.get_database()
        self.search_type_obj = SearchType.get(self.search_type)
        if self.database != Project.get_project_code(
        ) and self.database != 'sthpw':
            raise TacticException(
                'You are not allowed to delete the sType [%s] from another project [%s].'
                % (self.search_type, self.database))
            return False

        return True
Beispiel #58
0
    def get_next_job(job_search_type="sthpw/queue", queue_type=None, server_code=None):

        sql = DbContainer.get("sthpw")

        search_type_obj = SearchType.get(job_search_type)
        table = search_type_obj.get_table()

        # get the entire queue
        search = Search(job_search_type)
        if queue_type:
            search.add_filter("queue", queue_type)
        if server_code:
            search.add_filter("server_code", server_code)
        search.add_filter("state", "pending")

        search.add_order_by("priority")
        search.add_order_by("timestamp")


        chunk = 10
        search.add_limit(chunk)

        queues = search.get_sobjects()
        queue_id = 0

        for queue in queues:

            queue_id = queue.get_id()

            # attempt to lock this queue
            # have to do this manually
            update = """UPDATE "%s" SET state = 'locked' where id = '%s' and state = 'pending'""" % (table, queue_id)

            sql.do_update(update)
            row_count = sql.get_row_count()

            if row_count == 1:
                break
            else:
                queue_id = 0

        if queue_id:
            queue = Search.get_by_id(job_search_type, queue_id)
            return queue
        else:
            return None
Beispiel #59
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)
Beispiel #60
0
    def get_database_by_search_type(cls, search_type):
        base_search_type, data = SearchKey._get_data(search_type)
        if base_search_type.startswith("sthpw/"):
            return "sthpw"

        project_code = data.get("project")

        # if no project is defined, get the global default
        if project_code == None:
            search_type_obj = SearchType.get(search_type)
            # this is more accurate specifically for project-specific sType
            project_code = search_type_obj.get_database()
            #project_code = cls.get_global_project_code()
       
        if project_code == 'admin':
            project_code = 'sthpw'

        return project_code