def _ldap_attrs_user(obj, dn, attrs): newattrs = defaultdict(list) req = getattr(obj, '__req__', None) for loc in obj.locations: loc.__req__ = req for attr in AddressType.ldap_address_attrs(loc.type): newattrs[attr].append(loc.street_address if (loc.type == AddressType.work) else str(loc)) if loc.type == AddressType.work: if loc.country: newattrs['c'].append(loc.country) if loc.state_or_province: newattrs['st'].append(loc.state_or_province) if loc.city_address: newattrs['l'].append(loc.city_address) if loc.room: newattrs['roomNumber'].append(loc.room) if loc.postal_code: newattrs['postalCode'].append(loc.postal_code) if len(newattrs) > 0: attrs.update(newattrs)
def _ldap_attrs_user(obj, dn, attrs): newattrs = defaultdict(list) req = getattr(obj, '__req__', None) for loc in obj.locations: loc.__req__ = req for attr in AddressType.ldap_address_attrs(loc.type): newattrs[attr].append(loc.street_address if ( loc.type == AddressType.work) else str(loc)) if loc.type == AddressType.work: if loc.country: newattrs['c'].append(loc.country) if loc.state_or_province: newattrs['st'].append(loc.state_or_province) if loc.city_address: newattrs['l'].append(loc.city_address) if loc.room: newattrs['roomNumber'].append(loc.room) if loc.postal_code: newattrs['postalCode'].append(loc.postal_code) if len(newattrs) > 0: attrs.update(newattrs)
def add_to_vcard(self, card): data = dict() if self.country: data['country'] = self.country if self.state_or_province: data['region'] = self.state_or_province if self.postal_code: data['box'] = self.postal_code bit = self.city_address if bit: data['city'] = bit bit = self.street_address if bit: data['street'] = bit if len(data) > 0: obj = card.add('adr') obj.value = vobject.vcard.Address(**data) objtype = list(AddressType.vcard_types(self.type)) if self.primary: objtype.append('pref') obj.type_paramlist = objtype
class UserLocation(Base): """ Users' addresses. """ __tablename__ = 'users_locations' __table_args__ = ( Comment('User locations'), Index('users_locations_i_uid', 'uid'), Index('users_locations_i_houseid', 'houseid'), { 'mysql_engine' : 'InnoDB', 'mysql_charset' : 'utf8', 'info' : { 'cap_read' : 'USERS_LIST', 'cap_create' : 'USERS_EDIT', 'cap_edit' : 'USERS_EDIT', 'cap_delete' : 'USERS_EDIT', 'menu_name' : _('User Addresses'), 'default_sort' : ({ 'property': 'atype' ,'direction': 'ASC' },), 'grid_view' : ( 'ulocid', 'user', 'primary', 'atype', MarkupColumn( header_string=_('Address'), column_flex=3, template='{__str__}' ) ), 'grid_hidden' : ('ulocid',), 'form_view' : ( 'user', 'primary', 'atype', 'house', 'country', 'stprov', 'city', 'addr', 'entrance', 'floor', 'flat', 'room', 'entrycode', 'postindex', 'descr' ), 'detail_pane' : ('netprofile_core.views', 'dpane_simple'), 'create_wizard' : SimpleWizard(title=_('Add new user address')) } } ) id = Column( 'ulocid', UInt32(), Sequence('users_locations_ulocid_seq'), Comment('User location ID'), primary_key=True, nullable=False, info={ 'header_string' : _('ID') } ) user_id = Column( 'uid', UInt32(), ForeignKey('users.uid', name='users_locations_fk_uid', ondelete='CASCADE', onupdate='CASCADE'), Comment('User ID'), nullable=False, info={ 'header_string' : _('User'), 'filter_type' : 'none' } ) primary = Column( NPBoolean(), Comment('Primary flag'), nullable=False, default=False, server_default=npbool(False), info={ 'header_string' : _('Primary') } ) type = Column( 'atype', AddressType.db_type(), Comment('Address type'), nullable=False, default=AddressType.work, server_default=AddressType.work, info={ 'header_string' : _('Type'), 'column_flex' : 1 } ) country = Column( CHAR(2), Comment('ISO 3166-1 alpha-2 country code'), nullable=True, default=None, server_default=text('NULL'), info={ 'header_string' : _('Country'), 'choices' : countries_alpha2 } ) state_or_province = Column( 'stprov', Unicode(255), Comment('State or province name'), nullable=True, default=None, server_default=text('NULL'), info={ 'header_string' : _('State/province') } ) city = Column( Unicode(255), Comment('City name'), nullable=True, default=None, server_default=text('NULL'), info={ 'header_string' : _('City') } ) address = Column( 'addr', Unicode(255), Comment('Freeform address'), nullable=True, default=None, server_default=text('NULL'), info={ 'header_string' : _('Address') } ) house_id = Column( 'houseid', UInt32(), ForeignKey('addr_houses.houseid', name='users_locations_fk_houseid', ondelete='CASCADE', onupdate='CASCADE'), Comment('House ID'), nullable=True, default=None, server_default=text('NULL'), info={ 'header_string' : _('House'), 'filter_type' : 'none', 'column_flex' : 1 } ) entrance = Column( UInt8(), Comment('Entrance number'), nullable=True, default=None, server_default=text('NULL'), info={ 'header_string' : _('Entr.') } ) floor = Column( Int16(), Comment('Floor number'), nullable=True, default=None, server_default=text('NULL'), info={ 'header_string' : _('Floor') } ) flat = Column( UInt16(), Comment('Flat/office number'), nullable=True, default=None, server_default=text('NULL'), info={ 'header_string' : _('Flat') } ) room = Column( Unicode(8), Comment('Room identifier'), nullable=True, default=None, server_default=text('NULL'), info={ 'header_string' : _('Room') } ) entry_code = Column( 'entrycode', Unicode(8), Comment('Entry code'), nullable=True, default=None, server_default=text('NULL'), info={ 'header_string' : _('Entry Code') } ) postal_code = Column( 'postindex', Unicode(8), Comment('Postal code'), nullable=True, default=None, server_default=text('NULL'), info={ 'header_string' : _('Postal Code') } ) description = Column( 'descr', UnicodeText(), Comment('Address description'), nullable=True, default=None, server_default=text('NULL'), info={ 'header_string' : _('Description'), 'column_flex' : 2 } ) user = relationship( 'User', innerjoin=True, backref=backref( 'locations', cascade='all, delete-orphan', passive_deletes=True ) ) def __str__(self): req = self.__req__ or get_current_request() loc = req.localizer locale_cur = req.current_locale locale_en = req.locales['en'] ret = [] bit = self.country if bit: if bit in locale_cur.territories: bit = locale_cur.territories[bit] elif bit in locale_en.territories: bit = locale_en.territories[bit] ret.append(bit + ',') bit = self.city_address if bit: ret.append(bit + ',') bit = self.street_address if bit: ret.append(bit) if self.entrance: ret.extend(( loc.translate(_('entr.')), str(self.entrance) )) if self.floor: ret.extend(( loc.translate(_('fl.')), str(self.floor) )) if self.flat: pfx = _('app.') if self.type == AddressType.work: pfx = _('office') ret.extend(( loc.translate(pfx), str(self.flat) )) return ' '.join(ret) def add_to_vcard(self, card): data = dict() if self.country: data['country'] = self.country if self.state_or_province: data['region'] = self.state_or_province if self.postal_code: data['box'] = self.postal_code bit = self.city_address if bit: data['city'] = bit bit = self.street_address if bit: data['street'] = bit if len(data) > 0: obj = card.add('adr') obj.value = vobject.vcard.Address(**data) objtype = list(AddressType.vcard_types(self.type)) if self.primary: objtype.append('pref') obj.type_paramlist = objtype @property def city_address(self): if self.house and self.house.street: return str(self.house.street.city) return self.city @property def street_address(self): if self.house: return str(self.house) return self.address