# Path: damvitool/db.py
# def generate_orm_classes(db_conn_str):
# 
# Path: damvitool/users.py
# class Login:
#     pass
# 
# class Logout:
#     pass
# 
# Path: damvitool/utils.py
# def to_json_type(value):
#     if isinstance(value, (Decimal, datetime, date)):
#         return str(value)
#     return value


from morepath import Response
from sqlalchemy import func, or_, and_, not_, sql
from sqlalchemy.orm import class_mapper, aliased
from damvitool.db import Base, orm_classes, Session
from json import loads
from damvitool.users import Login, Logout
from damvitool.utils import to_json_type
                self.query = query

            def __iter__(self):
                return QueryIterator(self.query)

        class QueryIterator(object):
            offset = 0
            chunk_size = 10000

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

            def __iter__(self):
                return self

            def next(self):
                chunk = query.offset(self.offset).limit(self.chunk_size).all()
                self.offset += self.chunk_size
                if not chunk:
                    raise StopIteration
                return bytes('\n'.join([';'.join([str(f) for f in r]) for r in chunk]) + '\n', 'utf-8')

            __next__ = next  # py3 compat

        res = Response(content_type='text/csv', headerlist=[('Content-disposition', 'attachment;filename=export.csv')])
        res.app_iter = QueryIterable(query)
        return res

    @classmethod
    def _process_entity_attrs(cls, entity, fields, entities, parent_cls=None):

# Path: damvitool/db.py
# def generate_orm_classes(db_conn_str):
# 
# Path: damvitool/users.py
# class Login:
#     pass
# 
# class Logout:
#     pass
# 
# Path: damvitool/utils.py
# def to_json_type(value):
#     if isinstance(value, (Decimal, datetime, date)):
#         return str(value)
#     return value


# Path: damvitool/model.py
from morepath import Response
from sqlalchemy import func, or_, and_, not_, sql
from sqlalchemy.orm import class_mapper, aliased
from damvitool.db import Base, orm_classes, Session
from json import loads
from damvitool.users import Login, Logout
from damvitool.utils import to_json_type

                self.query = query

            def __iter__(self):
                return QueryIterator(self.query)

        class QueryIterator(object):
            offset = 0
            chunk_size = 10000

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

            def __iter__(self):
                return self

            def next(self):
                chunk = query.offset(self.offset).limit(self.chunk_size).all()
                self.offset += self.chunk_size
                if not chunk:
                    raise StopIteration
                return bytes('\n'.join([';'.join([str(f) for f in r]) for r in chunk]) + '\n', 'utf-8')

            __next__ = next  # py3 compat

        res = Response(content_type='text/csv', headerlist=[('Content-disposition', 'attachment;filename=export.csv')])
        res.app_iter = QueryIterable(query)
        return res

    @classmethod
    def _process_entity_attrs(cls, entity, fields, entities, parent_cls=None):

        child_cls = orm_classes[entity['id']]