from sqlalchemy import Column, ForeignKey, Integer, String, Text

from model.base import Base


class SWTZ_TY(Base):
    __tablename__ = 'swtz_ty'

    class_name = '商务团组-团员'
    foreign_key = 'swtz_id'
    export_docx = False
    export_handle_file = ['identity']
    field = [
        'id', 'nickname', 'job', 'id_card', 'phone', 'remark', 'identity'
    ]
    combo_field = {
        'identity': {
            'exclude': False,
            'items': ['基层', '青年', '商界', '学界', '政界']
        }
    }

    template_start_row = 3

    swtz_id = Column(Integer, ForeignKey('swtz.id'))
    nickname = Column(String(100), comment='姓名')
    job = Column(String(100), comment='单位职务')
    id_card = Column(String(100), comment='身份证号')
    phone = Column(String(100), comment='联系电话')
    remark = Column(Text, comment='备注')
    identity_ = Column('identity', String(100), comment='身份')

    @property
    def identity(self):
        if self.identity_ is None:
            return []
        return self.identity_.split(' ')

    @identity.setter
    def identity(self, val):
        if isinstance(val, list):
            while '' in val:
                val.remove('')
            self.identity_ = ' '.join(val)
        else:
            self.identity_ = val


[((30, 13, 30, 43), 'sqlalchemy.Column', 'Column', (), '', False, 'from sqlalchemy import Column, ForeignKey, Integer, String, Text\n'), ((25, 30, 25, 51), 'sqlalchemy.ForeignKey', 'ForeignKey', ({(25, 41, 25, 50): '"""swtz.id"""'}, {}), "('swtz.id')", False, 'from sqlalchemy import Column, ForeignKey, Integer, String, Text\n'), ((26, 22, 26, 33), 'sqlalchemy.String', 'String', ({(26, 29, 26, 32): '100'}, {}), '(100)', False, 'from sqlalchemy import Column, ForeignKey, Integer, String, Text\n'), ((27, 17, 27, 28), 'sqlalchemy.String', 'String', ({(27, 24, 27, 27): '100'}, {}), '(100)', False, 'from sqlalchemy import Column, ForeignKey, Integer, String, Text\n'), ((28, 21, 28, 32), 'sqlalchemy.String', 'String', ({(28, 28, 28, 31): '100'}, {}), '(100)', False, 'from sqlalchemy import Column, ForeignKey, Integer, String, Text\n'), ((29, 19, 29, 30), 'sqlalchemy.String', 'String', ({(29, 26, 29, 29): '100'}, {}), '(100)', False, 'from sqlalchemy import Column, ForeignKey, Integer, String, Text\n'), ((31, 35, 31, 46), 'sqlalchemy.String', 'String', ({(31, 42, 31, 45): '100'}, {}), '(100)', False, 'from sqlalchemy import Column, ForeignKey, Integer, String, Text\n')]