コード例 #1
0
ファイル: olvgroup.py プロジェクト: driscollis/MediaLocker
    def initOLV(self, desc, coldesc, table, distinct=None):
        """
        :param desc: the list title, e.g. _('Countries')
        :param coldesc: a dict of column name and column description
        :param table: the table name as a string e.g. 'Country_LV'
        :param distinct: a list of joins, e.g.
        [db.Recipeit, (db.Recipe, db.Recipe.recipeid==db.Recipeit.fk_recipeid)]
        """

        self.EmptyListMsg = (_('No %s are found for the entered search criteria') % desc)
        self.listMinMenuDesc = (_('Preview - %s List - minimal') % desc)
        self.listNormMenuDesc = (_('Preview - %s List - normal') % desc)
        self.listMinReportDesc = (_('%s - list') % desc)
        self.listNormReportDesc = (_('%s - list') % desc)

        self.tableName = table
        ds = wx.GetApp().session
        with no_autoflush(ds):
            if distinct:
                joinedQuery = ds.query(getattr(db, self.tableName))
                for item in distinct:
                    joinedQuery = joinedQuery.join(item)

                self.setOlvQuery(joinedQuery.distinct())
            else:
                self.setOlvQuery(ds.query(getattr(db, self.tableName)))

        cols = self.setColumnDef(coldesc, self.tableName)
        self.initObjectListView(None, cols)
        self.setGroupCols(0)

        xCols = len(cols)
        olvList = self.getList()
        olvList.SetFilter(Filter.TextSearch(olvList, olvList.columns[0:xCols]))
コード例 #2
0
ファイル: olvbase.py プロジェクト: driscollis/MediaLocker
    def getKeyValue(self, item, key):
        keyValue = item
        if key.find('.') == -1:
            # no relation in key
            colname = key
        else:
            rel, colname = key.rsplit('.', 1)
            comp = rel.split('.')
            for arel in comp:
                if keyValue:
                    with no_autoflush(wx.GetApp().session):
                        keyValue = getattr(keyValue, arel)

        if keyValue:
            with no_autoflush(wx.GetApp().session):
                return (getattr(keyValue, colname), )
        else:
            return (None, )
コード例 #3
0
ファイル: olvbase.py プロジェクト: driscollis/MediaLocker
    def getColumnDefFromTable(self, table):
        """Get the column definition from the Olvlist table"""
        listFilter = "tablename = '%s'" % table
        cols = []
        ds = wx.GetApp().session
        with no_autoflush(ds):
            cols = ds.query(db.Olvlist).filter(listFilter
                                    ).order_by('colno').all()

        return cols
コード例 #4
0
ファイル: olvbase.py プロジェクト: driscollis/MediaLocker
 def getRel(self, data, relation):
     """Resolve dotted relation entry"""
     baseAttr = data
     if not relation == None:
         comp = relation.split('.')
         for arel in comp:
             if baseAttr:
                 with no_autoflush(wx.GetApp().session):
                     baseAttr = getattr(baseAttr, arel)
     return baseAttr
コード例 #5
0
ファイル: olvbase.py プロジェクト: driscollis/MediaLocker
    def getRelInfo(self, data, relation, colname):
        """return value or blank"""
        try:
            baseAttr = self.getRel(data, relation)

            if baseAttr:
                with no_autoflush(wx.GetApp().session):
                    return getattr(baseAttr, colname)
            else:
                return ''
        except:
            # don't raise otherwise it takes a long time, might have to kill app
            msg = "Parent: %s, Grand Parent: %s\n" % (self.GetParent(),
                                                    self.GetGrandParent())
            msgR = "relation: %s, colname: %s, data: %s\n" % (relation,
                                                            colname,
                                                            data)
            logging.error(msg)
            logging.exception(msgR)