Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Code adaption to run with python 3 #39

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 7 additions & 7 deletions geraldo/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,20 +43,20 @@
- tests - a package with automated doc tests.
"""

from version import VERSION, get_version
from .version import VERSION, get_version

__author__ = 'Marinho Brandao'
__license__ = 'GNU Lesser General Public License (LGPL)'
__url__ = 'http://geraldo.sourceforge.net/'
__version__ = get_version()

from base import Report, ReportBand, DetailBand, TableBand, ReportGroup,\
from .base import Report, ReportBand, DetailBand, TableBand, ReportGroup,\
SubReport, landscape, GeraldoObject, ManyElements, CROSS_COLS
from widgets import Label, ObjectValue, SystemField
from widgets import FIELD_ACTION_VALUE, FIELD_ACTION_COUNT, FIELD_ACTION_AVG,\
from .widgets import Label, ObjectValue, SystemField
from .widgets import FIELD_ACTION_VALUE, FIELD_ACTION_COUNT, FIELD_ACTION_AVG,\
FIELD_ACTION_MIN, FIELD_ACTION_MAX, FIELD_ACTION_SUM,\
FIELD_ACTION_DISTINCT_COUNT, BAND_WIDTH
from graphics import RoundRect, Rect, Line, Circle, Arc, Ellipse, Image
from exceptions import EmptyQueryset, ObjectNotFound, ManyObjectsFound, AbortEvent
from cross_reference import CrossReferenceMatrix
from .graphics import RoundRect, Rect, Line, Circle, Arc, Ellipse, Image
from .exceptions import EmptyQueryset, ObjectNotFound, ManyObjectsFound, AbortEvent
from .cross_reference import CrossReferenceMatrix

4 changes: 2 additions & 2 deletions geraldo/barcodes.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
"""Module with BarCodes functions on Geraldo."""

from graphics import Graphic
from utils import memoize, get_attr_value, cm
from .graphics import Graphic
from .utils import memoize, get_attr_value, cm

from reportlab.graphics.barcode import getCodeNames
from reportlab.graphics.barcode.common import Codabar, Code11, I2of5, MSI
Expand Down
57 changes: 27 additions & 30 deletions geraldo/base.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,15 @@
import copy, types, new

try:
set
except NameError:
from sets import Set as set # Python 2.3 fallback

from utils import calculate_size, get_attr_value, landscape, format_date, memoize,\
from .utils import calculate_size, get_attr_value, landscape, format_date, memoize,\
BAND_WIDTH, BAND_HEIGHT, CROSS_COLS, CROSS_ROWS, cm, A4, black, TA_LEFT, TA_CENTER,\
TA_RIGHT
from exceptions import EmptyQueryset, ObjectNotFound, ManyObjectsFound,\
from .exceptions import EmptyQueryset, ObjectNotFound, ManyObjectsFound,\
AttributeNotFound, NotYetImplemented
from cache import DEFAULT_CACHE_STATUS, CACHE_BACKEND, CACHE_FILE_ROOT
from .cache import DEFAULT_CACHE_STATUS, CACHE_BACKEND, CACHE_FILE_ROOT

class GeraldoObject(object):
"""Base class inherited by all report classes, including band, subreports,
Expand Down Expand Up @@ -238,21 +237,21 @@ def get_children(self):
ret = []

# Bands
ret.extend(filter(bool, [
ret.extend(list(filter(bool, [
self.band_begin,
self.band_summary,
self.band_page_header,
self.band_page_footer,
self.band_detail
]))
])))

# Groups
if isinstance(self.groups, (list, tuple)):
ret.extend(self.groups)

# Borders
if isinstance(self.borders, dict):
ret.extend(filter(lambda e: isinstance(e, Element),self.borders.values()))
ret.extend([e for e in list(self.borders.values()) if isinstance(e, Element)])

return ret

Expand All @@ -269,8 +268,8 @@ def remove_child(self, obj):
self.groups.remove(obj)

# Borders
if isinstance(self.borders, dict) and obj in self.borders.values():
for k,v in self.borders.items():
if isinstance(self.borders, dict) and obj in list(self.borders.values()):
for k,v in list(self.borders.items()):
if v == obj:
self.borders.pop(k)

Expand All @@ -289,7 +288,7 @@ def set_parent_on_children(self):

# Borders
if isinstance(self.borders, dict):
for v in self.borders.values():
for v in list(self.borders.values()):
if isinstance(v, GeraldoObject):
v.parent = self

Expand Down Expand Up @@ -360,16 +359,14 @@ def get_report_class_by_registered_id(reg_id):

return None

class Report(BaseReport):
class Report(BaseReport, metaclass=ReportMetaclass):
"""This class must be inherited to be used as a new report.

A report has bands and is driven by a QuerySet. It can have a title and
margins definitions.

Depends on ReportLab to work properly"""

__metaclass__ = ReportMetaclass

# Report properties
title = ''
author = ''
Expand Down Expand Up @@ -444,15 +441,15 @@ def generate_under_process_by(self, generator_class, *args, **kwargs):
It doesn't returns nothing because Process doesn't."""

import tempfile, random, os
from utils import run_under_process
from .utils import run_under_process

# Checks 'filename' argument
if 'filename' in kwargs and not isinstance(kwargs['filename'], basestring):
if 'filename' in kwargs and not isinstance(kwargs['filename'], str):
# Stores file-like object
filelike = kwargs.pop('filename')

# Make a randomic temporary filename
chars = map(chr, range(ord('a'), ord('z')) + range(ord('0'), ord('9')))
chars = list(map(chr, list(range(ord('a'), ord('z'))) + list(range(ord('0'), ord('9')))))
filename = ''.join([random.choice(chars) for c in range(40)])
kwargs['filename'] = os.path.join(tempfile.gettempdir(), filename)
else:
Expand Down Expand Up @@ -544,7 +541,7 @@ class SubReport(BaseReport):
get_queryset = None # This must be a lambda function

def __init__(self, **kwargs):
for k,v in kwargs.items():
for k,v in list(kwargs.items()):
# Validates backward incompatibility for 'detail_band'
if k == 'detail_band':
k = 'band_detail'
Expand Down Expand Up @@ -607,11 +604,11 @@ def _set_queryset_string(self, value):

def get_children(self):
ret = super(SubReport, self).get_children()
ret.extend(filter(bool, [
ret.extend(list(filter(bool, [
self.band_detail,
self.band_header,
self.band_footer,
]))
])))

return ret

Expand Down Expand Up @@ -652,7 +649,7 @@ class ReportBand(GeraldoObject):
after_print = None

def __init__(self, **kwargs):
for k,v in kwargs.items():
for k,v in list(kwargs.items()):
setattr(self, k, v)

# Default values for elements, child bands and default style lists
Expand Down Expand Up @@ -682,7 +679,7 @@ def get_children(self):

# Borders
if isinstance(self.borders, dict):
ret.extend(filter(lambda e: isinstance(e, Element),self.borders.values()))
ret.extend([e for e in list(self.borders.values()) if isinstance(e, Element)])

return ret

Expand All @@ -696,8 +693,8 @@ def remove_child(self, obj):
self.child_bands.remove(obj)

# Borders
if isinstance(self.borders, dict) and obj in self.borders.values():
for k,v in self.borders.items():
if isinstance(self.borders, dict) and obj in list(self.borders.values()):
for k,v in list(self.borders.items()):
if v == obj:
self.borders.pop(k)

Expand All @@ -714,7 +711,7 @@ def set_parent_on_children(self):

# Borders
if isinstance(self.borders, dict):
for v in self.borders.values():
for v in list(self.borders.values()):
if isinstance(v, GeraldoObject):
v.parent = self

Expand Down Expand Up @@ -758,7 +755,7 @@ class ReportGroup(GeraldoObject):
force_new_page = False

def __init__(self, **kwargs):
for k,v in kwargs.items():
for k,v in list(kwargs.items()):
setattr(self, k, v)

# Transforms band classes to band objects
Expand All @@ -779,10 +776,10 @@ def transform_classes_to_objects(self):
self.band_footer = self.band_footer()

def get_children(self):
return filter(bool, [
return list(filter(bool, [
self.band_header,
self.band_footer,
])
]))

def remove_child(self, obj):
# Bands
Expand Down Expand Up @@ -896,7 +893,7 @@ def do_after_print(self, generator):

_repr_for_cache_attrs = ('left','top','height','width','visible')
def repr_for_cache_hash_key(self):
return unicode(dict([(attr, getattr(self, attr)) for attr in self._repr_for_cache_attrs]))
return str(dict([(attr, getattr(self, attr)) for attr in self._repr_for_cache_attrs]))

class ManyElements(GeraldoObject):
"""Class that makes the objects creation more dynamic."""
Expand All @@ -923,7 +920,7 @@ def __init__(self, element_class, count, start_left=None, start_top=None,
def get_elements(self, cross_cols=None):
"""Returns the elements (or create them if they don't exist."""

from cross_reference import CrossReferenceMatrix
from .cross_reference import CrossReferenceMatrix

count = self.count

Expand All @@ -943,7 +940,7 @@ def get_elements(self, cross_cols=None):
kwargs = self.element_kwargs.copy()

# Set attributes before creation
for k,v in kwargs.items():
for k,v in list(kwargs.items()):
if v == CROSS_COLS:
try:
kwargs[k] = cross_cols[num]
Expand Down
8 changes: 4 additions & 4 deletions geraldo/cache.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

import os

from utils import memoize, get_attr_value
from .utils import memoize, get_attr_value

try:
set
Expand Down Expand Up @@ -66,7 +66,7 @@ def exists(self, hash_key):

@memoize
def get_report_cache_attributes(report):
from widgets import ObjectValue
from .widgets import ObjectValue

# Find widgets attributes
widgets = [widget.attribute_name for widget in report.find_by_type(ObjectValue)]
Expand Down Expand Up @@ -124,11 +124,11 @@ def make_hash_key(report, objects_list):

# Situation 2 - mostly queryset objects list
else:
result.append(u'/'.join([unicode(get_attr_value(obj, attr)) for attr in report_attrs()]))
result.append('/'.join([str(get_attr_value(obj, attr)) for attr in report_attrs()]))

# Makes the hash key
m = hash_constructor()
m.update(u'\n'.join(result))
m.update('\n'.join(result))

return '%s-%s'%(report.cache_prefix, m.hexdigest())

Expand Down
Loading