コード例 #1
0
ファイル: browser.py プロジェクト: mgedmin/zodbbrowser
    def render(self):
        self._started = time.time()
        pruneTruncations()
        self.obj = self.selectObjectToView()
        # Not using IObjectHistory(self.obj) because LP#1185175
        self.history = ZodbObjectHistory(self.obj)
        self.latest = True
        if self.request.get('tid'):
            self.state = ZodbObjectState(self.obj,
                                         p64(int(self.request['tid'], 0)),
                                         _history=self.history)
            self.latest = False
        else:
            self.state = ZodbObjectState(self.obj, _history=self.history)

        if 'CANCEL' in self.request:
            self._redirectToSelf()
            return ''

        if 'ROLLBACK' in self.request:
            rtid = p64(int(self.request['rtid'], 0))
            self.requestedState = self._tidToTimestamp(rtid)
            if self.request.get('confirmed') == '1':
                self.history.rollback(rtid)
                transaction.get().note(u'Rollback to old state %s'
                                       % self.requestedState)
                self.made_changes = True
                self._redirectToSelf()
                return ''
            # will show confirmation prompt
            return self.confirmation_template()

        return self.template()
コード例 #2
0
    def render(self):
        self._started = time.time()
        pruneTruncations()
        self.obj = self.selectObjectToView()
        # Not using IObjectHistory(self.obj) because LP#1185175
        self.history = ZodbObjectHistory(self.obj)
        self.latest = True
        if self.request.get('tid'):
            self.state = ZodbObjectState(self.obj,
                                         p64(int(self.request['tid'], 0)),
                                         _history=self.history)
            self.latest = False
        else:
            self.state = ZodbObjectState(self.obj, _history=self.history)

        if 'CANCEL' in self.request:
            self._redirectToSelf()
            return ''

        if 'ROLLBACK' in self.request:
            rtid = p64(int(self.request['rtid'], 0))
            self.requestedState = self._tidToTimestamp(rtid)
            if self.request.get('confirmed') == '1':
                self.history.rollback(rtid)
                transaction.get().note(u'Rollback to old state %s' %
                                       self.requestedState)
                self.made_changes = True
                self._redirectToSelf()
                return ''
            # will show confirmation prompt
            return self.confirmation_template()

        return self.template()
コード例 #3
0
 def test_pruneTruncations(self):
     for n in range(MAX_CACHE_SIZE + 3):
         truncate('a string')
     pruneTruncations()
     self.assertEqual(len(TRUNCATIONS), MAX_CACHE_SIZE)
     self.assertEqual(len(TRUNCATIONS_IN_ORDER), MAX_CACHE_SIZE)
     self.assertEqual(sorted(TRUNCATIONS_IN_ORDER), sorted(TRUNCATIONS))
     self.assertEqual(TRUNCATIONS_IN_ORDER[0], 'tr4')
コード例 #4
0
 def test_pruneTruncations(self):
     for n in range(MAX_CACHE_SIZE + 3):
         truncate('a string')
     pruneTruncations()
     self.assertEquals(len(TRUNCATIONS), MAX_CACHE_SIZE)
     self.assertEquals(len(TRUNCATIONS_IN_ORDER), MAX_CACHE_SIZE)
     self.assertEquals(sorted(TRUNCATIONS_IN_ORDER), sorted(TRUNCATIONS))
     self.assertEquals(TRUNCATIONS_IN_ORDER[0], 'tr4')
コード例 #5
0
 def update(self):
     self._started = time.time()
     pruneTruncations()
     if 'page_size' in self.request:
         self.page_size = max(1, int(self.request['page_size']))
     self.history = IDatabaseHistory(self.jar)
     self.request.hold(Cleanup(self.history.cleanup))
     if 'page' in self.request:
         self.page = int(self.request['page'])
     elif 'tid' in self.request:
         tid = int(self.request['tid'], 0)
         self.page = self.findPage(p64(tid))
     else:
         self.page = 0
     self.last_page = max(0, len(self.history) - 1) // self.page_size
     if self.page > self.last_page:
         self.page = self.last_page
     self.last_idx = max(0, len(self.history) - self.page * self.page_size)
     self.first_idx = max(0, self.last_idx - self.page_size)
コード例 #6
0
ファイル: browser.py プロジェクト: mgedmin/zodbbrowser
 def update(self):
     self._started = time.time()
     pruneTruncations()
     if 'page_size' in self.request:
         self.page_size = max(1, int(self.request['page_size']))
     self.history = IDatabaseHistory(self.jar)
     self.request.hold(Cleanup(self.history.cleanup))
     if 'page' in self.request:
         self.page = int(self.request['page'])
     elif 'tid' in self.request:
         tid = int(self.request['tid'], 0)
         self.page = self.findPage(p64(tid))
     else:
         self.page = 0
     self.last_page = max(0, len(self.history) - 1) // self.page_size
     if self.page > self.last_page:
         self.page = self.last_page
     self.last_idx = max(0, len(self.history) - self.page * self.page_size)
     self.first_idx = max(0, self.last_idx - self.page_size)
コード例 #7
0
 def update(self):
     pruneTruncations()
     if 'page_size' in self.request:
         self.page_size = max(1, int(self.request['page_size']))
     self.debug_mark('Loading history')
     self.history = IDatabaseHistory(self.jar)
     self.request.hold(Cleanup(self.history.cleanup))
     if 'page' in self.request:
         self.page = int(self.request['page'])
     elif 'tid' in self.request:
         tid = int(self.request['tid'], 0)
         self.debug_mark('- finding transaction page')
         self.page = self.findPage(p64(tid))
     else:
         self.page = 0
     self.last_page = max(0, len(self.history) - 1) // self.page_size
     if self.page > self.last_page:
         self.page = self.last_page
     self.last_idx = max(0, len(self.history) - self.page * self.page_size)
     self.first_idx = max(0, self.last_idx - self.page_size)
コード例 #8
0
    def render(self):
        self.reset_mark(getFullRequestUrl(self.request))
        pruneTruncations()
        self.obj = self.selectObjectToView()
        self.debug_mark('- loading object history')
        # Not using IObjectHistory(self.obj) because LP: #1185175
        self.history = getObjectHistory(self.obj)
        self.latest = True
        self.debug_mark('- loading object state')
        if self.request.get('tid'):
            self.state = ZodbObjectState(self.obj,
                                         p64(int(self.request['tid'], 0)),
                                         _history=self.history)
            self.latest = False
        else:
            self.state = ZodbObjectState(self.obj, _history=self.history)

        if 'CANCEL' in self.request:
            self._redirectToSelf()
            return ''

        if 'ROLLBACK' in self.request:
            rtid = p64(int(self.request['rtid'], 0))
            self.requestedState = self._tidToTimestamp(rtid)
            if self.request.get('confirmed') == '1':
                self.history.rollback(rtid)
                transaction.get().note(u'Rollback to old state %s'
                                       % self.requestedState)
                self.made_changes = True
                self._redirectToSelf()
                return ''
            # will show confirmation prompt
            return self.confirmation_template()

        self.debug_mark('- rendering')
        try:
            return self.template()
        finally:
            self.debug_mark('- done (%s)' % formatTime(self.time_elapsed()))