Пример #1
0
 def update(self):
     if self.manager.prefix:
         self.name = "." + self.manager.prefix
     else:
         self.name = ""
     if self.manager.ignoreRequest:
         start = 0
         size = self.manager.batch_size
     else:
         start = int(self.request.get('start' + self.name, 0))
         size = int(
             self.request.get('size' + self.name, self.manager.batch_size))
     items = self.manager._items
     self.batch = TokenBatch(items, size=size, start=start)
Пример #2
0
 def update(self):
     if self.manager.prefix:
         self.name = "." + self.manager.prefix
     else:
         self.name = ""
     if self.manager.ignoreRequest:
         start = 0
         size = self.manager.batch_size
     else:
         start = int(self.request.get(
                 'start' + self.name, 0))
         size = int(self.request.get(
                 'size' + self.name, self.manager.batch_size))
     items = self.manager._items
     self.batch = TokenBatch(
         items, size=size, start=start)
Пример #3
0
class TableBatch(flourish.viewlet.Viewlet):

    before = ("table", )

    batch = None

    def __init__(self, context, request, view, manager):
        flourish.viewlet.Viewlet.__init__(
            self, context, request, view, manager)

    @property
    def html_id(self):
        return flourish.page.generic_viewlet_html_id(self)

    def __iter__(self):
        return iter(self.batch)

    def update(self):
        if self.manager.prefix:
            self.name = "." + self.manager.prefix
        else:
            self.name = ""
        if self.manager.ignoreRequest:
            start = 0
            size = self.manager.batch_size
        else:
            start = int(self.request.get(
                    'start' + self.name, 0))
            size = int(self.request.get(
                    'size' + self.name, self.manager.batch_size))
        items = self.manager._items
        self.batch = TokenBatch(
            items, size=size, start=start)

    @property
    def needsBatch(self):
        batch = self.batch
        return (batch.size < batch.full_size and batch.needsBatch)

    def extend_token(self, token, **kw):
        token = dict(token)
        script = "return ST.table.on_batch_link('%s', '%s', %d, %d);" % (
            self.manager.html_id,
            self.name, token['start'],
            token['size'])
        token['onclick'] = script
        token.update(kw)
        return token

    @property
    def start(self):
        return self.batch.start

    @property
    def size(self):
        return self.batch.size

    @property
    def length(self):
        return len(self.batch)

    @property
    def full_size(self):
        return self.batch.full_size

    @Lazy
    def previous(self):
        token = self.batch.previous()
        if token is None:
            return None
        return self.extend_token(token, css_class='previous')

    @Lazy
    def next(self):
        token = self.batch.next()
        if token is None:
            return None
        return self.extend_token(token, css_class='next')

    @Lazy
    def show_all(self):
        if self.batch.size >= self.batch.full_size:
            return None
        script = "return ST.table.on_batch_link('%s', '%s', %d, %d);" % (
            self.manager.html_id,
            self.name, 0, self.full_size)
        return {'start': 0,
                'size': self.full_size,
                'items': self.batch.items,
                'onclick': script,
                'css_class': 'all'}

    def tokens(self):
        tokens = []
        for token in self.batch.tokens():
            css_class = "batch_page"
            css_class += token['current'] and ' current' or ''
            token = self.extend_token(token, css_class=css_class)
            tokens.append(token)
        return tokens
Пример #4
0
class TableBatch(flourish.viewlet.Viewlet):

    before = ("table", )

    batch = None

    def __init__(self, context, request, view, manager):
        flourish.viewlet.Viewlet.__init__(self, context, request, view,
                                          manager)

    @property
    def html_id(self):
        return flourish.page.generic_viewlet_html_id(self)

    def __iter__(self):
        return iter(self.batch)

    def update(self):
        if self.manager.prefix:
            self.name = "." + self.manager.prefix
        else:
            self.name = ""
        if self.manager.ignoreRequest:
            start = 0
            size = self.manager.batch_size
        else:
            start = int(self.request.get('start' + self.name, 0))
            size = int(
                self.request.get('size' + self.name, self.manager.batch_size))
        items = self.manager._items
        self.batch = TokenBatch(items, size=size, start=start)

    @property
    def needsBatch(self):
        batch = self.batch
        return (batch.size < batch.full_size and batch.needsBatch)

    def extend_token(self, token, **kw):
        token = dict(token)
        script = "return ST.table.on_batch_link('%s', '%s', %d, %d);" % (
            self.manager.html_id, self.name, token['start'], token['size'])
        token['onclick'] = script
        token.update(kw)
        return token

    @property
    def start(self):
        return self.batch.start

    @property
    def size(self):
        return self.batch.size

    @property
    def length(self):
        return len(self.batch)

    @property
    def full_size(self):
        return self.batch.full_size

    @Lazy
    def previous(self):
        token = self.batch.previous()
        if token is None:
            return None
        return self.extend_token(token, css_class='previous')

    @Lazy
    def next(self):
        token = self.batch.next()
        if token is None:
            return None
        return self.extend_token(token, css_class='next')

    @Lazy
    def show_all(self):
        if self.batch.size >= self.batch.full_size:
            return None
        script = "return ST.table.on_batch_link('%s', '%s', %d, %d);" % (
            self.manager.html_id, self.name, 0, self.full_size)
        return {
            'start': 0,
            'size': self.full_size,
            'items': self.batch.items,
            'onclick': script,
            'css_class': 'all'
        }

    def tokens(self):
        tokens = []
        for token in self.batch.tokens():
            css_class = "batch_page"
            css_class += token['current'] and ' current' or ''
            token = self.extend_token(token, css_class=css_class)
            tokens.append(token)
        return tokens