class ItemQueryScrollingFragment(IndexingModel, ScrollableView, LiveElement): """ An L{ItemQueryScrollingFragment} is an Athena L{LiveElement} that can display an Axiom query using an inefficient, but precise, method for counting rows and getting data at given offsets when requested. New code which wants to display a scrollable list of data should probably use L{ScrollingElement} instead. """ def __init__(self, store, itemType, baseConstraint, columns, defaultSortColumn=None, defaultSortAscending=True, webTranslator=None, *a, **kw): self.store = store self.itemType = itemType self.baseConstraint = baseConstraint IndexingModel.__init__( self, _webTranslator(store, webTranslator), columns, defaultSortColumn, defaultSortAscending) LiveElement.__init__(self, *a, **kw) def _cannotDetermineSort(self, defaultSortColumn): """ In this old, index-based way of doing things, we can do even more implicit horrible stuff to determine the sort column, or even give up completely and accept an implicit sort. NB: this is still terrible behavior, but lots of old code relied on it, and since this class is legacy anyway it won't be deprecated or removed. We can also accept a sort column in this table that is not actually displayed or sent to the client at all. """ if defaultSortColumn is not None: self.currentSortColumn = IColumn(defaultSortColumn) def getInitialArguments(self): return [self.getTableMetadata()] def performCount(self): return self.store.query(self.itemType, self.baseConstraint).count() def performQuery(self, rangeBegin, rangeEnd): if self.isAscending: sort = self.currentSortColumn.sortAttribute().ascending else: sort = self.currentSortColumn.sortAttribute().descending return list(self.store.query(self.itemType, self.baseConstraint, offset=rangeBegin, limit=rangeEnd - rangeBegin, sort=sort))
class ItemQueryScrollingFragment(IndexingModel, ScrollableView, LiveElement): """ An L{ItemQueryScrollingFragment} is an Athena L{LiveElement} that can display an Axiom query using an inefficient, but precise, method for counting rows and getting data at given offsets when requested. New code which wants to display a scrollable list of data should probably use L{ScrollingElement} instead. """ def __init__(self, store, itemType, baseConstraint, columns, defaultSortColumn=None, defaultSortAscending=True, webTranslator=None, *a, **kw): self.store = store self.itemType = itemType self.baseConstraint = baseConstraint IndexingModel.__init__(self, _webTranslator(store, webTranslator), columns, defaultSortColumn, defaultSortAscending) LiveElement.__init__(self, *a, **kw) def _cannotDetermineSort(self, defaultSortColumn): """ In this old, index-based way of doing things, we can do even more implicit horrible stuff to determine the sort column, or even give up completely and accept an implicit sort. NB: this is still terrible behavior, but lots of old code relied on it, and since this class is legacy anyway it won't be deprecated or removed. We can also accept a sort column in this table that is not actually displayed or sent to the client at all. """ if defaultSortColumn is not None: self.currentSortColumn = IColumn(defaultSortColumn) def getInitialArguments(self): return [self.getTableMetadata()] def performCount(self): return self.store.query(self.itemType, self.baseConstraint).count() def performQuery(self, rangeBegin, rangeEnd): if self.isAscending: sort = self.currentSortColumn.sortAttribute().ascending else: sort = self.currentSortColumn.sortAttribute().descending return list( self.store.query(self.itemType, self.baseConstraint, offset=rangeBegin, limit=rangeEnd - rangeBegin, sort=sort))
def _cannotDetermineSort(self, defaultSortColumn): """ In this old, index-based way of doing things, we can do even more implicit horrible stuff to determine the sort column, or even give up completely and accept an implicit sort. NB: this is still terrible behavior, but lots of old code relied on it, and since this class is legacy anyway it won't be deprecated or removed. We can also accept a sort column in this table that is not actually displayed or sent to the client at all. """ if defaultSortColumn is not None: self.currentSortColumn = IColumn(defaultSortColumn)
def getInitialArguments(self): """ Return the constructor arguments required for the JavaScript client class, Mantissa.ScrollTable.ScrollTable. @return: a 3-tuple of:: - The unicode attribute ID of my current sort column - A list of dictionaries with 'name' and 'type' keys which are strings describing the name and type of all the columns in this table. - A bool indicating whether the sort direction is initially ascending. """ ic = IColumn(self.currentSortColumn) return [ ic.attributeID.decode('ascii'), self._getColumnList(), self.isAscending ]
def __init__(self, webTranslator, columns, defaultSortColumn, defaultSortAscending): self.webTranslator = webTranslator self.columns = {} self.columnNames = [] for col in columns: # see comment in TimestampAttributeColumn if isinstance(col, timestamp): col = TimestampAttributeColumn(col) else: col = IColumn(col) if defaultSortColumn is None: defaultSortColumn = col.sortAttribute() if (defaultSortColumn is not None and col.sortAttribute() is defaultSortColumn): self.currentSortColumn = col attributeID = unicode(col.attributeID, 'ascii') self.columns[attributeID] = col self.columnNames.append(attributeID) self.isAscending = defaultSortAscending if self.currentSortColumn is None: self._cannotDetermineSort(defaultSortColumn)