diff --git a/geraldo/__init__.py b/geraldo/__init__.py index c9f0288..0c8423f 100644 --- a/geraldo/__init__.py +++ b/geraldo/__init__.py @@ -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 diff --git a/geraldo/barcodes.py b/geraldo/barcodes.py index 81425ff..c1eea3b 100644 --- a/geraldo/barcodes.py +++ b/geraldo/barcodes.py @@ -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 diff --git a/geraldo/base.py b/geraldo/base.py index ebf8e92..7702b93 100644 --- a/geraldo/base.py +++ b/geraldo/base.py @@ -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, @@ -238,13 +237,13 @@ 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)): @@ -252,7 +251,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 @@ -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) @@ -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 @@ -360,7 +359,7 @@ 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 @@ -368,8 +367,6 @@ class Report(BaseReport): Depends on ReportLab to work properly""" - __metaclass__ = ReportMetaclass - # Report properties title = '' author = '' @@ -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: @@ -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' @@ -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 @@ -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 @@ -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 @@ -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) @@ -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 @@ -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 @@ -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 @@ -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.""" @@ -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 @@ -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] diff --git a/geraldo/cache.py b/geraldo/cache.py index 2caa45a..f48bb4b 100644 --- a/geraldo/cache.py +++ b/geraldo/cache.py @@ -3,7 +3,7 @@ import os -from utils import memoize, get_attr_value +from .utils import memoize, get_attr_value try: set @@ -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)] @@ -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()) diff --git a/geraldo/charts.py b/geraldo/charts.py index eb665ff..a97aac8 100644 --- a/geraldo/charts.py +++ b/geraldo/charts.py @@ -12,9 +12,9 @@ from reportlab.graphics.charts.legends import Legend from reportlab.lib.colors import HexColor, getAllNamedColors -from utils import cm, memoize, get_attr_value -from cross_reference import CrossReferenceMatrix, CROSS_COLS, CROSS_ROWS -from graphics import Graphic +from .utils import cm, memoize, get_attr_value +from .cross_reference import CrossReferenceMatrix, CROSS_COLS, CROSS_ROWS +from .graphics import Graphic DEFAULT_TITLE_HEIGHT = 1*cm @@ -42,7 +42,7 @@ class BaseChart(Graphic): def __init__(self, **kwargs): # Set instance attributes - for k,v in kwargs.items(): + for k,v in list(kwargs.items()): if k == 'style': setattr(self, 'chart_style', v) else: @@ -102,7 +102,7 @@ def get_available_colors(self): colors.pop('black', None) # Returns only the colors values (without their names) - colors = colors.values() + colors = list(colors.values()) # Shuffle colors list random.shuffle(colors) @@ -160,7 +160,7 @@ def make_legend(self, drawing, chart): # Legend object legend = Legend() - legend.colorNamePairs = zip(self.colors[:len(labels)], labels) + legend.colorNamePairs = list(zip(self.colors[:len(labels)], labels)) legend.columnMaximum = len(legend.colorNamePairs) legend.deltay = 5 legend.alignment = 'right' @@ -169,7 +169,7 @@ def make_legend(self, drawing, chart): # Sets legend extra attributes if legend_labels is a dictionary if isinstance(self.legend_labels, dict): - for k,v in self.legend_labels.items(): + for k,v in list(self.legend_labels.items()): if k != 'labels' and v: setattr(legend, k, v) @@ -193,10 +193,10 @@ def get_legend_labels(self): # Calculated labels if callable(self.legend_labels): labels = [self.legend_labels(self, label, num) for num, label in enumerate(labels)] - elif isinstance(self.legend_labels, basestring): + elif isinstance(self.legend_labels, str): labels = [self.get_cross_data().first(self.legend_labels, col=label) for label in labels] - return map(unicode, labels) + return list(map(str, labels)) def get_axis_labels(self): # Base labels @@ -212,13 +212,13 @@ def get_axis_labels(self): # Calculated labels if callable(self.axis_labels): labels = [self.axis_labels(self, label, num) for num, label in enumerate(labels)] - elif isinstance(self.axis_labels, basestring): + elif isinstance(self.axis_labels, str): if self.summarize_by == CROSS_ROWS: labels = [self.get_cross_data().first(self.axis_labels, row=label) for label in labels] else: labels = [self.get_cross_data().first(self.axis_labels, col=label) for label in labels] - return map(unicode, labels) + return list(map(str, labels)) def make_title(self, drawing): if not self.title: @@ -243,7 +243,7 @@ def get_cross_data(self, data=None): data = data or self.data # Transforms data to cross-reference matrix - if isinstance(data, basestring): + if isinstance(data, str): data = get_attr_value(self.instance, data) if not isinstance(data, CrossReferenceMatrix): @@ -290,24 +290,24 @@ def round_values(value): if isinstance(value, (float, decimal.Decimal)): value = int(round(value)) elif isinstance(value, (list, tuple)): - value = map(int, map(round, value)) + value = list(map(int, list(map(round, value)))) return value # Replace None to Zero if self.replace_none_by_zero: - data = map(none_to_zero, data) + data = list(map(none_to_zero, data)) # Truncate decimal places if self.round_values: - data = map(round_values, data) + data = list(map(round_values, data)) # Stores major value in temporary variable to use it later if data: if isinstance(data[0], int): self._max_value = max(data) elif isinstance(data[0], (list, tuple)): - self._max_value = max(map(max, data)) + self._max_value = max(list(map(max, data))) return data @@ -323,7 +323,7 @@ def set_chart_attributes(self, chart): def set_chart_style(self, chart): # Setting additional chart attributes if self.chart_style: - for k,v in self.chart_style.items(): + for k,v in list(self.chart_style.items()): setattr(chart, k, v) def create_chart(self): @@ -520,7 +520,7 @@ def set_chart_attributes(self, chart): # Cells labels if isinstance(self.values_labels, dict): - for k,v in self.values_labels.items(): + for k,v in list(self.values_labels.items()): if k == 'labels' and v: chart.labels = v else: diff --git a/geraldo/cross_reference.py b/geraldo/cross_reference.py index 0775d7b..780f2c9 100644 --- a/geraldo/cross_reference.py +++ b/geraldo/cross_reference.py @@ -6,8 +6,8 @@ from sets import Set as set import random, decimal -from utils import get_attr_value, memoize -from base import ReportBand, GeraldoObject, CROSS_COLS, CROSS_ROWS +from .utils import get_attr_value, memoize +from .base import ReportBand, GeraldoObject, CROSS_COLS, CROSS_ROWS RANDOM_ROW_DEFAULT = RANDOM_COL_DEFAULT = ''.join([random.choice([chr(c) for c in range(48, 120)]) for i in range(100)]) @@ -120,7 +120,7 @@ def sum(self, cell, row=RANDOM_ROW_DEFAULT, col=RANDOM_COL_DEFAULT): @memoize def avg(self, cell, row=RANDOM_ROW_DEFAULT, col=RANDOM_COL_DEFAULT): - values = map(float, self.values(cell, row, col)) + values = list(map(float, self.values(cell, row, col))) if row == RANDOM_ROW_DEFAULT and col == RANDOM_COL_DEFAULT: count = len(values) diff --git a/geraldo/generators/__init__.py b/geraldo/generators/__init__.py index e8ea850..87896fb 100644 --- a/geraldo/generators/__init__.py +++ b/geraldo/generators/__init__.py @@ -1,7 +1,7 @@ -from base import ReportGenerator -from html import HTMLGenerator -from xmlstruct import XMLStructGenerator -from pdf import PDFGenerator -from text import TextGenerator -from csvgen import CSVGenerator +from .base import ReportGenerator +from .html import HTMLGenerator +from .xmlstruct import XMLStructGenerator +from .pdf import PDFGenerator +from .text import TextGenerator +from .csvgen import CSVGenerator diff --git a/geraldo/generators/base.py b/geraldo/generators/base.py index d87e5b2..4a2e2bd 100644 --- a/geraldo/generators/base.py +++ b/geraldo/generators/base.py @@ -804,16 +804,16 @@ def get_objects_in_group(self): """Returns objects filtered in the current group or all if there is no group""" - filter_dict = dict([(group.attribute_name, value) for group, value in self._groups_working_values.items()]) + filter_dict = dict([(group.attribute_name, value) for group, value in list(self._groups_working_values.items())]) def filter_object(obj): - for k,v in filter_dict.items(): + for k,v in list(filter_dict.items()): if get_attr_value(obj, k) != v: return False return obj - return filter(filter_object, self.report.queryset) + return list(filter(filter_object, self.report.queryset)) # SubReports @@ -895,7 +895,7 @@ def fetch_from_cache(self): return True # Write to file path - elif isinstance(self.filename, basestring): + elif isinstance(self.filename, str): fp = file(self.filename, 'w') fp.write(buffer) fp.close() diff --git a/geraldo/generators/csvgen.py b/geraldo/generators/csvgen.py index 4c244ed..ccdc152 100644 --- a/geraldo/generators/csvgen.py +++ b/geraldo/generators/csvgen.py @@ -1,5 +1,5 @@ import datetime, csv -from base import ReportGenerator +from .base import ReportGenerator from geraldo.utils import get_attr_value, calculate_size from geraldo.widgets import Widget, Label, SystemField, ObjectValue @@ -41,7 +41,7 @@ def __init__(self, report, cache_enabled=None, writer=None, first_row_with_colum self.first_row_with_column_names = first_row_with_column_names # Additional attributes - for k,v in kwargs.items(): + for k,v in list(kwargs.items()): setattr(self, k, v) def start_writer(self, filename=None): @@ -50,7 +50,7 @@ def start_writer(self, filename=None): filename = filename or self.filename - if isinstance(filename, basestring): + if isinstance(filename, str): filename = file(filename, 'w') # Default writer uses comma as separator and quotes only when necessary diff --git a/geraldo/generators/html.py b/geraldo/generators/html.py index e8fb92d..bf8e6c6 100644 --- a/geraldo/generators/html.py +++ b/geraldo/generators/html.py @@ -1,6 +1,6 @@ # TODO -from base import ReportGenerator +from .base import ReportGenerator class HTMLGenerator(ReportGenerator): """This is a generator to output a XHTML that uses CSS and best practices diff --git a/geraldo/generators/pdf.py b/geraldo/generators/pdf.py index 0b5b568..96666fc 100644 --- a/geraldo/generators/pdf.py +++ b/geraldo/generators/pdf.py @@ -1,5 +1,5 @@ import datetime, os -from base import ReportGenerator +from .base import ReportGenerator from reportlab.pdfgen.canvas import Canvas from reportlab.lib.styles import ParagraphStyle @@ -143,7 +143,7 @@ def store_in_cache(self): return # Gest canvas content to store in the cache - if isinstance(self.filename, basestring): + if isinstance(self.filename, str): fp = file(self.filename, 'rb') content = fp.read() fp.close() @@ -198,7 +198,7 @@ def append_pdf(input, output): append_pdf(reader, output) - if isinstance(self.filename, basestring): + if isinstance(self.filename, str): fp = file(self.filename, 'wb') else: fp = self.filename @@ -300,11 +300,11 @@ def make_paragraph_style(self, band, style=None): d_style = self.report.default_style.copy() if band.default_style: - for k,v in band.default_style.items(): + for k,v in list(band.default_style.items()): d_style[k] = v if style: - for k,v in style.items(): + for k,v in list(style.items()): d_style[k] = v return ParagraphStyle(name=datetime.datetime.now().strftime('%H%M%S'), **d_style) @@ -507,7 +507,7 @@ def prepare_additional_fonts(self): if not self.report.additional_fonts: return - for font_family_name, fonts_or_file in self.report.additional_fonts.iteritems(): + for font_family_name, fonts_or_file in self.report.additional_fonts.items(): # Supports font family with many styles (i.e: normal, italic, bold, bold-italic, etc.) if isinstance(fonts_or_file, (list, tuple, dict)): for font_item in fonts_or_file: diff --git a/geraldo/generators/text.py b/geraldo/generators/text.py index 54c166b..293cdd0 100644 --- a/geraldo/generators/text.py +++ b/geraldo/generators/text.py @@ -1,5 +1,5 @@ import datetime -from base import ReportGenerator +from .base import ReportGenerator from geraldo.base import cm, TA_CENTER, TA_RIGHT from geraldo.utils import get_attr_value, calculate_size @@ -87,7 +87,7 @@ def __init__(self, report, cache_enabled=None, **kwargs): self.cache_enabled = bool(self.report.cache_status) # Specific attributes - for k,v in kwargs.items(): + for k,v in list(kwargs.items()): setattr(self, k, v) self.update_escape_chars() @@ -132,7 +132,7 @@ def get_hash_key(self, objects): def calculate_size(self, size): """Uses the function 'calculate_size' to calculate a size""" - if isinstance(size, basestring): + if isinstance(size, str): if size.endswith('*cols') or size.endswith('*col'): return int(size.split('*')[0]) * self.character_width elif size.endswith('*rows') or size.endswith('*row'): @@ -157,11 +157,11 @@ def make_paragraph_style(self, band, style=None): d_style = self.report.default_style.copy() if band.default_style: - for k,v in band.default_style.items(): + for k,v in list(band.default_style.items()): d_style[k] = v if style: - for k,v in style.items(): + for k,v in list(style.items()): d_style[k] = v return dict(name=datetime.datetime.now().strftime('%H%m%s'), **d_style) @@ -176,7 +176,7 @@ def keep_in_frame(self, widget, width, height, paragraphs, mode): def generate_pages(self): """Specific method that generates the pages""" self._generation_datetime = datetime.datetime.now() - self._output = u'' + self._output = '' # Escapes self.add_escapes_report_start(); @@ -185,7 +185,7 @@ def generate_pages(self): # Escapes self.add_escapes_page_start(num); - _page_output = [u' ' * self.page_columns_count] * self.page_rows_count + _page_output = [' ' * self.page_columns_count] * self.page_rows_count self._current_page_number = num + 1 @@ -196,7 +196,7 @@ def generate_pages(self): self.generate_widget(element, _page_output, num) # Adds the page output to output string - self._output = ''.join([self._output, u'\n'.join(_page_output)]) + self._output = ''.join([self._output, '\n'.join(_page_output)]) # Escapes self.add_escapes_page_end(num); diff --git a/geraldo/generators/xmlstruct.py b/geraldo/generators/xmlstruct.py index b3aaaa5..58b8baa 100644 --- a/geraldo/generators/xmlstruct.py +++ b/geraldo/generators/xmlstruct.py @@ -1,6 +1,6 @@ # TODO -from base import ReportGenerator +from .base import ReportGenerator class XMLStructGenerator(ReportGenerator): """This is an **exporter** to output a XML format, with the goal to be diff --git a/geraldo/graphics.py b/geraldo/graphics.py index f207863..446f312 100644 --- a/geraldo/graphics.py +++ b/geraldo/graphics.py @@ -1,5 +1,5 @@ -from base import BAND_WIDTH, BAND_HEIGHT, Element -from utils import cm, black +from .base import BAND_WIDTH, BAND_HEIGHT, Element +from .utils import cm, black class Graphic(Element): """Base graphic class""" @@ -14,7 +14,7 @@ class Graphic(Element): 'stroke_color','stroke_width','fill','fill_color') def __init__(self, **kwargs): - for k,v in kwargs.items(): + for k,v in list(kwargs.items()): setattr(self, k, v) def set_rect(self, **kwargs): diff --git a/geraldo/utils.py b/geraldo/utils.py index 94ae3f2..12123d9 100644 --- a/geraldo/utils.py +++ b/geraldo/utils.py @@ -14,7 +14,7 @@ from reportlab.lib.enums import TA_LEFT, TA_CENTER, TA_RIGHT # Check this also from reportlab.lib.colors import black -from exceptions import AttributeNotFound +from .exceptions import AttributeNotFound try: from functools import wraps @@ -109,7 +109,7 @@ def get_attr_value(obj, attr_path): def calculate_size(size): """Calculates the informed size. If this is a string or unicode, it is converted to float using evaluation function""" - if isinstance(size, basestring): + if isinstance(size, str): return eval(size) # If you are thinking this is a semanthic bug, you must # be aware this 'eval' is necessary to calculate sizes # like '10*cm' or '15.8*rows' diff --git a/geraldo/version.py b/geraldo/version.py index 41aa544..f771670 100644 --- a/geraldo/version.py +++ b/geraldo/version.py @@ -1,5 +1,4 @@ -VERSION = (0, 4, 17) +VERSION = (0, 4, 17, 1) def get_version(): - return '%d.%d.%d'%VERSION - + return '%d.%d.%d.%d'%VERSION diff --git a/geraldo/widgets.py b/geraldo/widgets.py index de9b201..45e0f9c 100644 --- a/geraldo/widgets.py +++ b/geraldo/widgets.py @@ -5,11 +5,11 @@ except NameError: from sets import Set as set # Python 2.3 fallback -from base import BAND_WIDTH, BAND_HEIGHT, Element, SubReport -from utils import get_attr_value, SYSTEM_FIELD_CHOICES, FIELD_ACTION_VALUE, FIELD_ACTION_COUNT,\ +from .base import BAND_WIDTH, BAND_HEIGHT, Element, SubReport +from .utils import get_attr_value, SYSTEM_FIELD_CHOICES, FIELD_ACTION_VALUE, FIELD_ACTION_COUNT,\ FIELD_ACTION_AVG, FIELD_ACTION_MIN, FIELD_ACTION_MAX, FIELD_ACTION_SUM,\ FIELD_ACTION_DISTINCT_COUNT, cm, black -from exceptions import AttributeNotFound +from .exceptions import AttributeNotFound class Widget(Element): """A widget is a value representation on the report""" @@ -29,7 +29,7 @@ class Widget(Element): def __init__(self, **kwargs): """This initializer is prepared to set arguments informed as attribute values.""" - for k,v in kwargs.items(): + for k,v in list(kwargs.items()): setattr(self, k, v) def clone(self): @@ -148,7 +148,7 @@ def get_object_value(self, instance=None, attribute_name=None): # Checks this is an expression tokens = EXP_TOKENS.split(attribute_name) - tokens = filter(bool, tokens) # Cleans empty parts + tokens = list(filter(bool, tokens)) # Cleans empty parts if len(tokens) > 1: values = {} for token in tokens: @@ -172,7 +172,7 @@ def get_queryset_values(self, attribute_name=None): all objects in the objects list, as a list""" objects = self.generator.get_current_queryset() - return map(lambda obj: self.get_object_value(obj, attribute_name), objects) + return [self.get_object_value(obj, attribute_name) for obj in objects] def _clean_empty_values(self, values): def clean(val): @@ -185,7 +185,7 @@ def clean(val): return val - return map(clean, values) + return list(map(clean, values)) def action_value(self, attribute_name=None): return self.get_object_value(attribute_name=attribute_name) @@ -193,7 +193,7 @@ def action_value(self, attribute_name=None): def action_count(self, attribute_name=None): # Returns the total count of objects with valid values on informed attribute values = self.get_queryset_values(attribute_name) - return len(filter(lambda v: v is not None, values)) + return len([v for v in values if v is not None]) def action_avg(self, attribute_name=None): values = self.get_queryset_values(attribute_name) @@ -220,12 +220,12 @@ def action_sum(self, attribute_name=None): return sum(values) def action_distinct_count(self, attribute_name=None): - values = filter(lambda v: v is not None, self.get_queryset_values(attribute_name)) + values = [v for v in self.get_queryset_values(attribute_name) if v is not None] return len(set(values)) def action_coalesce(self, attribute_name=None, default=''): value = self.get_object_value(attribute_name=attribute_name) - return value or unicode(default) + return value or str(default) def _text(self): if not self.stores_text_in_cache or self._cached_text is None: @@ -239,11 +239,11 @@ def _text(self): if self.get_text: try: - self._cached_text = unicode(self.get_text(self, self.instance, value)) + self._cached_text = str(self.get_text(self, self.instance, value)) except TypeError: - self._cached_text = unicode(self.get_text(self.instance, value)) + self._cached_text = str(self.get_text(self.instance, value)) else: - self._cached_text = unicode(value) + self._cached_text = str(value) return self.display_format % self._cached_text @@ -295,7 +295,7 @@ def get_value_by_expression(self, expression=None): try: return eval(expression, global_vars) - except Exception, e: + except Exception as e: if not callable(self.on_expression_error): raise diff --git a/pyproject.toml b/pyproject.toml new file mode 100644 index 0000000..3705178 --- /dev/null +++ b/pyproject.toml @@ -0,0 +1,32 @@ +[tool.poetry] +name = "geraldo" +version = "0.4.17.1" +description = "Geraldo is a reports engine for Python and Django applications." +authors = [ + "Marinho Brandao ", + "SIG Informática Ltda " +] +license = "LGPL-3" +homepage = "http://geraldo.sourceforge.net/" +packages = [ + { include = "geraldo" }, +] +include = ["AUTHOR", "CHANGES", "LICENSE", "README", "pyproject.toml", "setup.py"] + +[tool.poetry.dependencies] +python = "^3.6" +Pillow = "^8.4.0" +reportlab = "^3.6.8" + +[tool.poetry.dev-dependencies] + +[build-system] +requires = ["poetry-core>=1.0.0"] +build-backend = "poetry.core.masonry.api" + +[tool.poetry.build] +generate-setup-file = false + +[[tool.poetry.source]] +name = "pyrepo" +url = "https://download.sigsolucoes.net.br/public/pyrepo/"