Changeset - 5ea06f5ce235
[Not reviewed]
0 12 0
Lance Edgar (lance) - 7 years ago 2017-07-06 16:50:47
lance@edbob.org
Cleanup some unicode stuff per py3k effort
12 files changed with 55 insertions and 38 deletions:
0 comments (0 inline, 0 general)
rattail/batch/labels.py
Show inline comments
 
# -*- coding: utf-8 -*-
 
# -*- coding: utf-8; -*-
 
################################################################################
 
#
 
#  Rattail -- Retail Software Framework
 
#  Copyright © 2010-2016 Lance Edgar
 
#  Copyright © 2010-2017 Lance Edgar
 
#
 
#  This file is part of Rattail.
 
#
 
#  Rattail is free software: you can redistribute it and/or modify it under the
 
#  terms of the GNU Affero General Public License as published by the Free
 
#  Software Foundation, either version 3 of the License, or (at your option)
 
@@ -26,12 +26,13 @@ Handler for label batches
 

	
 
from __future__ import unicode_literals, absolute_import
 

	
 
import csv
 
import logging
 

	
 
import six
 
import sqlalchemy as sa
 
from sqlalchemy import orm
 

	
 
from rattail import enum
 
from rattail.db import model, api
 
from rattail.gpc import GPC
 
@@ -157,13 +158,13 @@ class LabelBatchHandler(BatchHandler):
 
            row.product = api.get_product_by_upc(session, row.upc)
 
        if not row.product:
 
            row.status_code = row.STATUS_PRODUCT_NOT_FOUND
 
            return
 

	
 
        product = row.product
 
        row.brand_name = unicode(product.brand or '')
 
        row.brand_name = six.text_type(product.brand or '')
 
        row.description = product.description
 
        row.size = product.size
 
        department = product.department
 
        row.department_number = department.number if department else None
 
        row.department_name = department.name if department else None
 
        category = product.category
rattail/batch/pricing.py
Show inline comments
 
# -*- coding: utf-8 -*-
 
# -*- coding: utf-8; -*-
 
################################################################################
 
#
 
#  Rattail -- Retail Software Framework
 
#  Copyright © 2010-2017 Lance Edgar
 
#
 
#  This file is part of Rattail.
 
@@ -23,12 +23,13 @@
 
"""
 
Handler for pricing batches
 
"""
 

	
 
from __future__ import unicode_literals, absolute_import
 

	
 
import six
 
from sqlalchemy import orm
 

	
 
from rattail.db import model
 
from rattail.batch import BatchHandler
 

	
 

	
 
@@ -61,13 +62,13 @@ class PricingBatchHandler(BatchHandler):
 
        Inspect a row from the source data and populate additional attributes
 
        for it, according to what we find in the database.
 
        """
 
        product = row.product
 
        assert product
 

	
 
        row.brand_name = unicode(product.brand or '')
 
        row.brand_name = six.text_type(product.brand or '')
 
        row.description = product.description
 
        row.size = product.size
 
        department = product.department
 
        row.department_number = department.number if department else None
 
        row.department_name = department.name if department else None
 

	
rattail/batch/purchase.py
Show inline comments
 
# -*- coding: utf-8 -*-
 
# -*- coding: utf-8; -*-
 
################################################################################
 
#
 
#  Rattail -- Retail Software Framework
 
#  Copyright © 2010-2016 Lance Edgar
 
#  Copyright © 2010-2017 Lance Edgar
 
#
 
#  This file is part of Rattail.
 
#
 
#  Rattail is free software: you can redistribute it and/or modify it under the
 
#  terms of the GNU Affero General Public License as published by the Free
 
#  Software Foundation, either version 3 of the License, or (at your option)
 
@@ -23,12 +23,13 @@
 
"""
 
Handler for purchase order batches
 
"""
 

	
 
from __future__ import unicode_literals, absolute_import
 

	
 
import six
 
from sqlalchemy import orm
 

	
 
from rattail.db import model, api
 
from rattail.batch import BatchHandler
 
from rattail.time import make_utc
 

	
 
@@ -97,13 +98,13 @@ class PurchaseBatchHandler(BatchHandler):
 
                return
 
            row.product = product
 

	
 
        cost = row.product.cost_for_vendor(batch.vendor) or row.product.cost
 
        row.upc = product.upc
 
        row.item_id = product.item_id
 
        row.brand_name = unicode(product.brand or '')
 
        row.brand_name = six.text_type(product.brand or '')
 
        row.description = product.description
 
        row.size = product.size
 
        if product.department:
 
            row.department_number = product.department.number
 
            row.department_name = product.department.name
 
        else:
rattail/bouncer/handler.py
Show inline comments
 
# -*- coding: utf-8 -*-
 
# -*- coding: utf-8; -*-
 
################################################################################
 
#
 
#  Rattail -- Retail Software Framework
 
#  Copyright © 2010-2015 Lance Edgar
 
#  Copyright © 2010-2017 Lance Edgar
 
#
 
#  This file is part of Rattail.
 
#
 
#  Rattail is free software: you can redistribute it and/or modify it under the
 
#  terms of the GNU Affero General Public License as published by the Free
 
#  Software Foundation, either version 3 of the License, or (at your option)
 
@@ -21,18 +21,19 @@
 
#
 
################################################################################
 
"""
 
Email Bounce Handlers
 
"""
 

	
 
from __future__ import unicode_literals
 
from __future__ import unicode_literals, absolute_import
 

	
 
import os
 
import datetime
 
from email.utils import parsedate_tz, mktime_tz
 

	
 
import six
 
from sqlalchemy import orm
 
from flufl.bounce import all_failures
 

	
 
from rattail.db import model
 
from rattail.core import Object
 
from rattail.util import load_object
 
@@ -133,15 +134,15 @@ class BounceHandler(object):
 
    def make_links(self, session, recipient):
 

	
 
        url = self.config.require('tailbone', 'url.customer')
 
        emails = session.query(model.CustomerEmailAddress).filter_by(address=recipient)
 
        for email in emails:
 
            yield self.make_link(type="Rattail Customer",
 
                                 title=unicode(email.customer),
 
                                 title=six.text_type(email.customer),
 
                                 url=url.format(uuid=email.parent_uuid))
 

	
 
        url = self.config.require('tailbone', 'url.person')
 
        emails = session.query(model.PersonEmailAddress).filter_by(address=recipient)
 
        for email in emails:
 
            yield self.make_link(type="Rattail Person",
 
                                 title=unicode(email.person),
 
                                 title=six.text_type(email.person),
 
                                 url=url.format(uuid=email.parent_uuid))
rattail/data/new-batch/webview.py
Show inline comments
 
@@ -3,12 +3,14 @@
 
"""
 
Views for ${model_title} batches
 
"""
 

	
 
from __future__ import unicode_literals, absolute_import
 

	
 
import six
 

	
 
from rattail.db import model
 

	
 
from tailbone.views.batch import FileBatchMasterView
 

	
 
from .handler import ${model_name}Handler
 

	
 
@@ -23,13 +25,13 @@ class ${model_name}View(FileBatchMasterView):
 
    model_title = "${model_title} Batch"
 
    model_title_plural = "${model_title} Batches"
 
    route_prefix = 'batch.${model_name.lower()}s'
 
    url_prefix = '/batch/${table_name.replace('_', '-')}'
 

	
 
    def get_instance_title(self, batch):
 
        return unicode(batch.vendor)
 
        return six.text_type(batch.vendor)
 

	
 
    def configure_grid(self, g):
 
        g.joiners['vendor'] = lambda q: q.join(model.Vendor)
 
        g.filters['vendor'] = g.make_filter('vendor', model.Vendor.name,
 
                                            default_active=True, default_verb='contains')
 
        g.sorters['vendor'] = g.make_sorter(model.Vendor.name)
rattail/importing/handlers.py
Show inline comments
 
# -*- coding: utf-8 -*-
 
# -*- coding: utf-8; -*-
 
################################################################################
 
#
 
#  Rattail -- Retail Software Framework
 
#  Copyright © 2010-2016 Lance Edgar
 
#  Copyright © 2010-2017 Lance Edgar
 
#
 
#  This file is part of Rattail.
 
#
 
#  Rattail is free software: you can redistribute it and/or modify it under the
 
#  terms of the GNU Affero General Public License as published by the Free
 
#  Software Foundation, either version 3 of the License, or (at your option)
 
@@ -26,12 +26,13 @@ Import Handlers
 

	
 
from __future__ import unicode_literals, absolute_import
 

	
 
import sys
 
import logging
 

	
 
import six
 
import humanize
 

	
 
from rattail.time import make_utc
 
from rattail.util import OrderedDict
 
from rattail.mail import send_email
 

	
 
@@ -371,13 +372,13 @@ class RecordRenderer(object):
 
    def get_label(self, record):
 
        key = record.__class__.__name__.lower()
 
        label = getattr(self, 'label_{}'.format(key), self.label)
 
        return label(record)
 

	
 
    def label(self, record):
 
        return unicode(record)
 
        return six.text_type(record)
 

	
 
    def get_url(self, record):
 
        """
 
        Fetch / generate a URL for the given data record.  You should *not*
 
        override this method, but do :meth:`url()` instead.
 
        """
rattail/importing/postgresql.py
Show inline comments
 
# -*- coding: utf-8 -*-
 
# -*- coding: utf-8; -*-
 
################################################################################
 
#
 
#  Rattail -- Retail Software Framework
 
#  Copyright © 2010-2016 Lance Edgar
 
#  Copyright © 2010-2017 Lance Edgar
 
#
 
#  This file is part of Rattail.
 
#
 
#  Rattail is free software: you can redistribute it and/or modify it under the
 
#  terms of the GNU Affero General Public License as published by the Free
 
#  Software Foundation, either version 3 of the License, or (at your option)
 
@@ -27,12 +27,14 @@ PostgreSQL data importers
 
from __future__ import unicode_literals, absolute_import
 

	
 
import os
 
import datetime
 
import logging
 

	
 
import six
 

	
 
from rattail.importing import BulkImporter, ToSQLAlchemy
 
from rattail.time import make_utc
 

	
 

	
 
log = logging.getLogger(__name__)
 

	
 
@@ -78,13 +80,13 @@ class BulkToPostgreSQL(BulkImporter, ToSQLAlchemy):
 
        elif isinstance(value, basestring):
 
            value = value.replace('\\', '\\\\')
 
            value = value.replace('\r', '\\r')
 
            value = value.replace('\n', '\\n')
 
            value = value.replace('\t', '\\t') # TODO: add test for this
 

	
 
        return unicode(value)
 
        return six.text_type(value)
 

	
 
    def flush_create_update(self):
 
        pass
 

	
 
    def flush_create_update_final(self):
 
        log.info("copying {} data from buffer to PostgreSQL".format(self.model_name))
rattail/mail.py
Show inline comments
 
@@ -176,13 +176,13 @@ class Email(object):
 
        return self.config.getbool('rattail.mail', 'send_emails', default=True)
 

	
 
    def get_sender(self):
 
        """
 
        Returns the value for the message's ``From:`` header.
 

	
 
        :rtype: unicode
 
        :rtype: str
 
        """
 
        sender = self.config.get('rattail.mail', '{0}.from'.format(self.key))
 
        if not sender:
 
            sender = self.config.get('rattail.mail', 'default.from')
 
            if not sender:
 
                raise exceptions.SenderNotFound(self.key)
 
@@ -218,13 +218,13 @@ class Email(object):
 
        return recips
 

	
 
    def get_prefix(self, data={}, magic=True):
 
        """
 
        Returns a string to be used as the subject prefix for the message.
 

	
 
        :rtype: unicode
 
        :rtype: str
 
        """
 
        prefix = self.config.get('rattail.mail', '{0}.prefix'.format(self.key))
 
        if not prefix:
 
            prefix = self.config.get('rattail.mail', 'default.prefix')
 
        prefix = prefix or self.default_prefix
 
        if magic and not self.config.production():
 
@@ -233,13 +233,13 @@ class Email(object):
 

	
 
    def get_subject(self, data={}, render=True):
 
        """
 
        Returns the base value for the message's subject header, i.e. minus
 
        prefix.
 

	
 
        :rtype: unicode
 
        :rtype: str
 
        """
 
        subject = self.config.get('rattail.mail', '{0}.subject'.format(self.key),
 
                                  default=self.default_subject)
 
        if not subject:
 
            subject = self.config.get('rattail.mail', 'default.subject')
 
        if subject and render:
 
@@ -250,13 +250,13 @@ class Email(object):
 
        """
 
        Returns the value for the message's ``Subject:`` header, i.e. the base
 
        subject with the prefix applied.  Note that config may provide the
 
        complete subject also, in which case the prefix and base subject are
 
        not considered.
 

	
 
        :rtype: unicode
 
        :rtype: str
 
        """
 
        return "{} {}".format(self.get_prefix(data), self.get_subject(data, render=render))
 

	
 
    def get_template(self, type_):
 
        """
 
        Locate and return the Mako email template of the given type
rattail/tests/importing/test_rattail.py
Show inline comments
 
# -*- coding: utf-8 -*-
 
# -*- coding: utf-8; -*-
 

	
 
from __future__ import unicode_literals, absolute_import
 

	
 
from unittest import TestCase
 

	
 
import six
 
import sqlalchemy as sa
 
from mock import patch
 
from fixture import TempIO
 

	
 
from rattail.db import model, Session, SessionBase, auth
 
from rattail.importing import rattail as rattail_importing
 
@@ -21,13 +22,13 @@ class DualRattailMixin(RattailMixin):
 

	
 
        if 'host' not in self.config.rattail_engines:
 
            self.config.rattail_engines['host'] = sa.create_engine('sqlite://')
 

	
 
        self.host_engine = self.config.rattail_engines['host']
 
        self.config.setdefault('rattail.db', 'keys', 'default, host')
 
        self.config.setdefault('rattail.db', 'host.url', unicode(self.host_engine.url))
 
        self.config.setdefault('rattail.db', 'host.url', six.text_type(self.host_engine.url))
 
        model = self.get_rattail_model()
 
        model.Base.metadata.create_all(bind=self.host_engine)
 
        self.host_session = Session(bind=self.host_engine)
 
        
 
    def teardown_rattail(self):
 
        super(DualRattailMixin, self).teardown_rattail()
rattail/tests/importing/test_sqlalchemy.py
Show inline comments
 
# -*- coding: utf-8 -*-
 
# -*- coding: utf-8; -*-
 

	
 
from __future__ import unicode_literals, absolute_import
 

	
 
from unittest import TestCase
 

	
 
import six
 
from mock import patch
 

	
 
import sqlalchemy as sa
 
from sqlalchemy import orm
 
from sqlalchemy.orm.exc import MultipleResultsFound
 

	
 
@@ -35,13 +36,13 @@ class TestFromSQLAlchemy(TestCase):
 

	
 
    def test_query(self):
 
        Session = orm.sessionmaker(bind=sa.create_engine('sqlite://'))
 
        session = Session()
 
        importer = saimport.FromSQLAlchemy(host_session=session,
 
                                           host_model_class=Widget)
 
        self.assertEqual(unicode(importer.query()),
 
        self.assertEqual(six.text_type(importer.query()),
 
                         "SELECT widgets.id AS widgets_id, widgets.description AS widgets_description \n"
 
                         "FROM widgets")
 

	
 

	
 
class TestToSQLAlchemy(TestCase):
 

	
rattail/vendors/catalogs.py
Show inline comments
 
# -*- coding: utf-8 -*-
 
# -*- coding: utf-8; -*-
 
################################################################################
 
#
 
#  Rattail -- Retail Software Framework
 
#  Copyright © 2010-2015 Lance Edgar
 
#  Copyright © 2010-2017 Lance Edgar
 
#
 
#  This file is part of Rattail.
 
#
 
#  Rattail is free software: you can redistribute it and/or modify it under the
 
#  terms of the GNU Affero General Public License as published by the Free
 
#  Software Foundation, either version 3 of the License, or (at your option)
 
@@ -21,16 +21,18 @@
 
#
 
################################################################################
 
"""
 
Vendor Catalogs
 
"""
 

	
 
from __future__ import unicode_literals
 
from __future__ import unicode_literals, absolute_import
 

	
 
from decimal import Decimal
 

	
 
import six
 

	
 
from rattail.exceptions import RattailError
 
from rattail.util import load_entry_points
 

	
 

	
 
class CatalogParser(object):
 
    """
 
@@ -86,23 +88,24 @@ class CatalogParser(object):
 
        Convert a value to an integer.
 
        """
 
        value = value.strip() or 0
 
        return int(value)
 

	
 

	
 
@six.python_2_unicode_compatible
 
class CatalogParserNotFound(RattailError):
 
    """
 
    Exception raised when a vendor catalog parser is required, but cannot be
 
    located.
 
    """
 

	
 
    def __init__(self, key):
 
        self.key = key
 

	
 
    def __unicode__(self):
 
        return "Vendor catalog parser with key {0} cannot be located.".format(self.key)
 
    def __str__(self):
 
        return "Vendor catalog parser with key {} cannot be located.".format(self.key)
 

	
 

	
 
def get_catalog_parsers():
 
    """
 
    Returns a dictionary of installed vendor catalog parser classes.
 
    """
rattail/vendors/invoices.py
Show inline comments
 
# -*- coding: utf-8 -*-
 
# -*- coding: utf-8; -*-
 
################################################################################
 
#
 
#  Rattail -- Retail Software Framework
 
#  Copyright © 2010-2015 Lance Edgar
 
#  Copyright © 2010-2017 Lance Edgar
 
#
 
#  This file is part of Rattail.
 
#
 
#  Rattail is free software: you can redistribute it and/or modify it under the
 
#  terms of the GNU Affero General Public License as published by the Free
 
#  Software Foundation, either version 3 of the License, or (at your option)
 
@@ -21,16 +21,18 @@
 
#
 
################################################################################
 
"""
 
Vendor Invoices
 
"""
 

	
 
from __future__ import unicode_literals
 
from __future__ import unicode_literals, absolute_import
 

	
 
from decimal import Decimal
 

	
 
import six
 

	
 
from rattail.exceptions import RattailError
 
from rattail.util import load_entry_points
 

	
 

	
 
class InvoiceParser(object):
 
    """
 
@@ -84,23 +86,24 @@ class InvoiceParser(object):
 
        Convert a value to an integer.
 
        """
 
        value = value.strip() or 0
 
        return int(value)
 

	
 

	
 
@six.python_2_unicode_compatible
 
class InvoiceParserNotFound(RattailError):
 
    """
 
    Exception raised when a vendor invoice parser is required, but cannot be
 
    located.
 
    """
 

	
 
    def __init__(self, key):
 
        self.key = key
 

	
 
    def __unicode__(self):
 
        return "Vendor invoice parser with key {0} cannot be located.".format(self.key)
 
    def __str__(self):
 
        return "Vendor invoice parser with key {} cannot be located.".format(self.key)
 

	
 

	
 
def get_invoice_parsers():
 
    """
 
    Returns a dictionary of installed vendor invoice parser classes.
 
    """
0 comments (0 inline, 0 general)