Changeset 365d679 in pycorepos


Ignore:
Timestamp:
07/21/2020 03:07:28 PM (3 years ago)
Author:
Lance Edgar <lance@…>
Branches:
master
Children:
4c7b208
Parents:
13b8380
Message:

Add split_street() method for MemberInfo?

File:
1 edited

Legend:

Unmodified
Added
Removed
  • corepos/db/office_op/model.py

    r13b8380 r365d679  
    2525"""
    2626
     27import logging
     28
    2729import sqlalchemy as sa
    2830from sqlalchemy import orm
     
    3032from sqlalchemy.ext.associationproxy import association_proxy
    3133
     34
     35log = logging.getLogger(__name__)
    3236
    3337Base = declarative_base()
     
    10571061        return self.full_name
    10581062
     1063    def split_street(self):
     1064        """
     1065        Tries to split the :attr:`street` attribute into 2 separate lines, e.g.
     1066        "street1" and "street2" style.  Always returns a 2-tuple even if the
     1067        second line would be empty.
     1068        """
     1069        address = (self.street or '').strip()
     1070        lines = address.split('\n')
     1071        street1 = lines[0].strip() or None
     1072        street2 = None
     1073        if len(lines) > 1:
     1074            street2 = lines[1].strip() or None
     1075            if len(lines) > 2:
     1076                log.warning("member #%s has %s address lines: %s",
     1077                            self.card_number, len(lines), self)
     1078        return (street1, street2)
     1079
    10591080
    10601081class MemberDate(Base):
Note: See TracChangeset for help on using the changeset viewer.