reporter: Python3 fixes
This commit is contained in:
		
							parent
							
								
									3ec90f4b66
								
							
						
					
					
						commit
						61c78fe3e7
					
				
					 6 changed files with 32 additions and 115 deletions
				
			
		|  | @ -23,9 +23,9 @@ then provide a listing of persons... | ||||||
|   >>> from cybertools.organize.party import Person |   >>> from cybertools.organize.party import Person | ||||||
| 
 | 
 | ||||||
|   >>> from datetime import date |   >>> from datetime import date | ||||||
|   >>> pdata = ((u'John', u'Smith', '1956-08-01'), |   >>> pdata = (('John', 'Smith', '1956-08-01'), | ||||||
|   ...          (u'David', u'Waters', '1972-12-24'), |   ...          ('David', 'Waters', '1972-12-24'), | ||||||
|   ...          (u'Carla', u'Myers', '1981-10-11')) |   ...          ('Carla', 'Myers', '1981-10-11')) | ||||||
|   >>> persons = DataSource([Person(f, s, date(*[int(d) for d in b.split('-')])) |   >>> persons = DataSource([Person(f, s, date(*[int(d) for d in b.split('-')])) | ||||||
|   ...                         for f, s, b in pdata]) |   ...                         for f, s, b in pdata]) | ||||||
| 
 | 
 | ||||||
|  | @ -41,18 +41,18 @@ then provide a listing of persons... | ||||||
|   >>> component.provideAdapter(DateFieldInstance, name='date') |   >>> component.provideAdapter(DateFieldInstance, name='date') | ||||||
| 
 | 
 | ||||||
|   >>> rset = IResultSet(persons) |   >>> rset = IResultSet(persons) | ||||||
|   >>> rset.schema = Schema(Field(u'firstName'), Field(u'lastName'), |   >>> rset.schema = Schema(Field('firstName'), Field('lastName'), | ||||||
|   ...                      Field(u'birthDate', fieldType='date')) |   ...                      Field('birthDate', fieldType='date')) | ||||||
| 
 | 
 | ||||||
|   >>> rows = list(rset.getRows()) |   >>> rows = list(rset.getRows()) | ||||||
|   >>> len(rows) |   >>> len(rows) | ||||||
|   3 |   3 | ||||||
| 
 | 
 | ||||||
|   >>> for r in rows: |   >>> for r in rows: | ||||||
|   ...     print r.applyTemplate() |   ...     print(r.applyTemplate()) | ||||||
|   {u'lastName': u'John', u'birthDate': '1956-08-01', u'firstName': u'Smith'} |   {'firstName': 'Smith', 'lastName': 'John', 'birthDate': '1956-08-01'} | ||||||
|   {u'lastName': u'David', u'birthDate': '1972-12-24', u'firstName': u'Waters'} |   {'firstName': 'Waters', 'lastName': 'David', 'birthDate': '1972-12-24'} | ||||||
|   {u'lastName': u'Carla', u'birthDate': '1981-10-11', u'firstName': u'Myers'} |   {'firstName': 'Myers', 'lastName': 'Carla', 'birthDate': '1981-10-11'} | ||||||
| 
 | 
 | ||||||
| For the browser presentation we can also use a browser view providing | For the browser presentation we can also use a browser view providing | ||||||
| the result set with extended attributes: | the result set with extended attributes: | ||||||
|  | @ -72,7 +72,7 @@ Batching | ||||||
| 
 | 
 | ||||||
| We'll use a fairly simple Iterable: | We'll use a fairly simple Iterable: | ||||||
| 
 | 
 | ||||||
|   >>> it = xrange(14) |   >>> it = range(14) | ||||||
| 
 | 
 | ||||||
|   >>> from cybertools.reporter.batch import Batch |   >>> from cybertools.reporter.batch import Batch | ||||||
|   >>> b = Batch(it, size=5, overlap=1, orphan=2) |   >>> b = Batch(it, size=5, overlap=1, orphan=2) | ||||||
|  | @ -99,8 +99,7 @@ We are now ready to use the corresponding browser view: | ||||||
|   >>> bview.items() |   >>> bview.items() | ||||||
|   [3, 4, 5, 6] |   [3, 4, 5, 6] | ||||||
|   >>> bview.last |   >>> bview.last | ||||||
|   {'url': 'http://127.0.0.1?b_size=4&b_overlap=1&b_page=5&b_orphan=0', |   {'title': 5, 'url': 'http://127.0.0.1?b_page=5&b_size=4&b_overlap=1&b_orphan=0', | ||||||
|    'navOnClick': "dojo.io.updateNode(...); return false;", |    'navOnClick': "dojo.io.updateNode(...); return false;"} | ||||||
|    'title': 5} |  | ||||||
| 
 | 
 | ||||||
| 
 | 
 | ||||||
|  |  | ||||||
|  | @ -1,30 +1,9 @@ | ||||||
| # | # cybertools.reporter.batch | ||||||
| #  Copyright (c) 2006 Helmut Merz helmutm@cy55.de |  | ||||||
| # |  | ||||||
| #  This program is free software; you can redistribute it and/or modify |  | ||||||
| #  it under the terms of the GNU General Public License as published by |  | ||||||
| #  the Free Software Foundation; either version 2 of the License, or |  | ||||||
| #  (at your option) any later version. |  | ||||||
| # |  | ||||||
| #  This program is distributed in the hope that it will be useful, |  | ||||||
| #  but WITHOUT ANY WARRANTY; without even the implied warranty of |  | ||||||
| #  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the |  | ||||||
| #  GNU General Public License for more details. |  | ||||||
| # |  | ||||||
| #  You should have received a copy of the GNU General Public License |  | ||||||
| #  along with this program; if not, write to the Free Software |  | ||||||
| #  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA |  | ||||||
| # |  | ||||||
| 
 | 
 | ||||||
| """ | """ Batching implementation. | ||||||
| Batching implementation. |  | ||||||
| 
 |  | ||||||
| $Id$ |  | ||||||
| """ | """ | ||||||
| 
 | 
 | ||||||
| import itertools | import itertools | ||||||
| from zope.interface import implements |  | ||||||
| from interfaces import IBatch |  | ||||||
| 
 | 
 | ||||||
| 
 | 
 | ||||||
| class Batch(object): | class Batch(object): | ||||||
|  | @ -36,7 +15,7 @@ class Batch(object): | ||||||
|             iterable = list(iterable) |             iterable = list(iterable) | ||||||
|         self.iterable = iterable |         self.iterable = iterable | ||||||
|         length = len(self.iterable) |         length = len(self.iterable) | ||||||
|         self.pages = range(0, length, size-overlap) |         self.pages = list(range(0, length, size-overlap)) | ||||||
|         if pageIndex >= len(self.pages): |         if pageIndex >= len(self.pages): | ||||||
|             pageIndex = len(self.pages) - 1 |             pageIndex = len(self.pages) - 1 | ||||||
|         if pageIndex < 0: |         if pageIndex < 0: | ||||||
|  |  | ||||||
|  | @ -1,29 +1,10 @@ | ||||||
| # | # cybertools.reporter.browser.batch | ||||||
| #  Copyright (c) 2006 Helmut Merz helmutm@cy55.de |  | ||||||
| # |  | ||||||
| #  This program is free software; you can redistribute it and/or modify |  | ||||||
| #  it under the terms of the GNU General Public License as published by |  | ||||||
| #  the Free Software Foundation; either version 2 of the License, or |  | ||||||
| #  (at your option) any later version. |  | ||||||
| # |  | ||||||
| #  This program is distributed in the hope that it will be useful, |  | ||||||
| #  but WITHOUT ANY WARRANTY; without even the implied warranty of |  | ||||||
| #  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the |  | ||||||
| #  GNU General Public License for more details. |  | ||||||
| # |  | ||||||
| #  You should have received a copy of the GNU General Public License |  | ||||||
| #  along with this program; if not, write to the Free Software |  | ||||||
| #  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA |  | ||||||
| # |  | ||||||
| 
 | 
 | ||||||
| """ | """ A browser view class for batching to be used by a macro or some other | ||||||
| A browser view class for batching to be used by a macro or some other |  | ||||||
| HTML providing template. | HTML providing template. | ||||||
| 
 |  | ||||||
| $Id$ |  | ||||||
| """ | """ | ||||||
| 
 | 
 | ||||||
| import urllib | import urllib.parse | ||||||
| from zope.cachedescriptors.property import Lazy | from zope.cachedescriptors.property import Lazy | ||||||
| from cybertools.reporter.batch import Batch | from cybertools.reporter.batch import Batch | ||||||
| 
 | 
 | ||||||
|  | @ -81,7 +62,7 @@ class BatchView(object): | ||||||
|                 v = form.get(p) |                 v = form.get(p) | ||||||
|                 if v: |                 if v: | ||||||
|                     params[p] = v |                     params[p] = v | ||||||
|         return '?' + urllib.urlencode(params) |         return '?' + urllib.parse.urlencode(params) | ||||||
| 
 | 
 | ||||||
|     def url(self, page): |     def url(self, page): | ||||||
|         return str(self.request.URL) + self.urlParams(page) |         return str(self.request.URL) + self.urlParams(page) | ||||||
|  | @ -90,7 +71,7 @@ class BatchView(object): | ||||||
|         try: |         try: | ||||||
|             url = self.request.URL[-1] |             url = self.request.URL[-1] | ||||||
|         except KeyError: # make DocTest/TestRequest happy |         except KeyError: # make DocTest/TestRequest happy | ||||||
|             url = `self.request.URL` |             url = 'self.request.URL' | ||||||
|         return ''.join((url, '/@@ajax.inner.html', self.urlParams(page))) |         return ''.join((url, '/@@ajax.inner.html', self.urlParams(page))) | ||||||
| 
 | 
 | ||||||
|     def navOnClick(self, page): |     def navOnClick(self, page): | ||||||
|  |  | ||||||
|  | @ -1,35 +1,15 @@ | ||||||
| # | # cybertools.reporter.data | ||||||
| #  Copyright (c) 2006 Helmut Merz helmutm@cy55.de |  | ||||||
| # |  | ||||||
| #  This program is free software; you can redistribute it and/or modify |  | ||||||
| #  it under the terms of the GNU General Public License as published by |  | ||||||
| #  the Free Software Foundation; either version 2 of the License, or |  | ||||||
| #  (at your option) any later version. |  | ||||||
| # |  | ||||||
| #  This program is distributed in the hope that it will be useful, |  | ||||||
| #  but WITHOUT ANY WARRANTY; without even the implied warranty of |  | ||||||
| #  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the |  | ||||||
| #  GNU General Public License for more details. |  | ||||||
| # |  | ||||||
| #  You should have received a copy of the GNU General Public License |  | ||||||
| #  along with this program; if not, write to the Free Software |  | ||||||
| #  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA |  | ||||||
| # |  | ||||||
| 
 | 
 | ||||||
| """ | """ Basic data / data source implementations. | ||||||
| Basic data / data source implementations. |  | ||||||
| 
 |  | ||||||
| $Id$ |  | ||||||
| """ | """ | ||||||
| 
 | 
 | ||||||
| from zope.interface import implements | from zope.interface import implementer | ||||||
| from cybertools.reporter.interfaces import IDataSource | from cybertools.reporter.interfaces import IDataSource | ||||||
| 
 | 
 | ||||||
| 
 | 
 | ||||||
|  | @implementer(IDataSource) | ||||||
| class DataSource(object): | class DataSource(object): | ||||||
| 
 | 
 | ||||||
|     implements(IDataSource) |  | ||||||
| 
 |  | ||||||
|     def __init__(self, iterable): |     def __init__(self, iterable): | ||||||
|         self.data = iterable |         self.data = iterable | ||||||
| 
 | 
 | ||||||
|  |  | ||||||
|  | @ -1,35 +1,16 @@ | ||||||
| # | # cybertools.reporter.resultset | ||||||
| #  Copyright (c) 2010 Helmut Merz helmutm@cy55.de |  | ||||||
| # |  | ||||||
| #  This program is free software; you can redistribute it and/or modify |  | ||||||
| #  it under the terms of the GNU General Public License as published by |  | ||||||
| #  the Free Software Foundation; either version 2 of the License, or |  | ||||||
| #  (at your option) any later version. |  | ||||||
| # |  | ||||||
| #  This program is distributed in the hope that it will be useful, |  | ||||||
| #  but WITHOUT ANY WARRANTY; without even the implied warranty of |  | ||||||
| #  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the |  | ||||||
| #  GNU General Public License for more details. |  | ||||||
| # |  | ||||||
| #  You should have received a copy of the GNU General Public License |  | ||||||
| #  along with this program; if not, write to the Free Software |  | ||||||
| #  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA |  | ||||||
| # |  | ||||||
| 
 | 
 | ||||||
| """ | """ Result set and related classes for reporting. | ||||||
| Result set and related classes for reporting. |  | ||||||
| 
 | 
 | ||||||
| Now obsolete (but still used in some projects), | Now obsolete (but still used in some projects), | ||||||
| use cybertools.composer.report.result instead. | use cybertools.composer.report.result instead. | ||||||
| 
 |  | ||||||
| $Id$ |  | ||||||
| """ | """ | ||||||
| 
 | 
 | ||||||
| # TODO: move the generic stuff to cybertools.reporter.result | # TODO: move the generic stuff to cybertools.reporter.result | ||||||
| 
 | 
 | ||||||
| from zope.cachedescriptors.property import Lazy | from zope.cachedescriptors.property import Lazy | ||||||
| from zope.component import adapts | from zope.component import adapts | ||||||
| from zope.interface import Interface, implements | from zope.interface import Interface, implementer | ||||||
| 
 | 
 | ||||||
| from cybertools.composer.schema import Schema | from cybertools.composer.schema import Schema | ||||||
| from cybertools.composer.schema.instance import Instance | from cybertools.composer.schema.instance import Instance | ||||||
|  | @ -37,11 +18,10 @@ from cybertools.reporter.interfaces import IDataSource | ||||||
| from cybertools.reporter.interfaces import IResultSet, IRow, ICell | from cybertools.reporter.interfaces import IResultSet, IRow, ICell | ||||||
| 
 | 
 | ||||||
| 
 | 
 | ||||||
|  | @implementer(ICell) | ||||||
| class Cell(object): | class Cell(object): | ||||||
|     # TODO: replace Cell by FieldInstance |     # TODO: replace Cell by FieldInstance | ||||||
| 
 | 
 | ||||||
|     implements(ICell) |  | ||||||
| 
 |  | ||||||
|     def __init__(self, field, value, row): |     def __init__(self, field, value, row): | ||||||
|         self.field = field |         self.field = field | ||||||
|         self.value = value |         self.value = value | ||||||
|  | @ -66,10 +46,9 @@ class Cell(object): | ||||||
|     url = urlTitle = u'' |     url = urlTitle = u'' | ||||||
| 
 | 
 | ||||||
| 
 | 
 | ||||||
|  | @implementer(IRow) | ||||||
| class Row(Instance): | class Row(Instance): | ||||||
| 
 | 
 | ||||||
|     implements(IRow) |  | ||||||
| 
 |  | ||||||
|     def __init__(self, context, resultSet): |     def __init__(self, context, resultSet): | ||||||
|         self.context = context |         self.context = context | ||||||
|         self.resultSet = resultSet |         self.resultSet = resultSet | ||||||
|  | @ -89,11 +68,11 @@ class Row(Instance): | ||||||
|             yield rf(f, getattr(self.context, f.name), self) |             yield rf(f, getattr(self.context, f.name), self) | ||||||
| 
 | 
 | ||||||
| 
 | 
 | ||||||
|  | @implementer(IRow) | ||||||
| class ContentRow(Instance): | class ContentRow(Instance): | ||||||
|     """ A row adapter for standard content objects. |     """ A row adapter for standard content objects. | ||||||
|     """ |     """ | ||||||
| 
 | 
 | ||||||
|     implements(IRow) |  | ||||||
|     adapts(Interface) |     adapts(Interface) | ||||||
| 
 | 
 | ||||||
|     @Lazy |     @Lazy | ||||||
|  | @ -101,9 +80,9 @@ class ContentRow(Instance): | ||||||
|         return self.template.fields |         return self.template.fields | ||||||
| 
 | 
 | ||||||
| 
 | 
 | ||||||
|  | @implementer(IResultSet) | ||||||
| class ResultSet(object): | class ResultSet(object): | ||||||
| 
 | 
 | ||||||
|     implements(IResultSet) |  | ||||||
|     adapts(IDataSource) |     adapts(IDataSource) | ||||||
| 
 | 
 | ||||||
|     view = None |     view = None | ||||||
|  |  | ||||||
|  | @ -1,9 +1,8 @@ | ||||||
| # $Id$ | # cybertools.reporter.tests | ||||||
| 
 | 
 | ||||||
| import unittest, doctest | import unittest, doctest | ||||||
| from zope.app.testing import ztapi | from zope.app.testing import ztapi | ||||||
| from zope.interface.verify import verifyClass | from zope.interface.verify import verifyClass | ||||||
| from zope.interface import implements |  | ||||||
| 
 | 
 | ||||||
| from cybertools.reporter.interfaces import IResultSet, IRow, ICell | from cybertools.reporter.interfaces import IResultSet, IRow, ICell | ||||||
| 
 | 
 | ||||||
|  |  | ||||||
		Loading…
	
	Add table
		
		Reference in a new issue