def contains(self, principal): person = IPerson(principal, None) if person is None: return False relationships = ContactRelationship.bind(contact=IContact(person)) is_parent = bool(relationships.any(ACTIVE + PARENT)) return is_parent
def city_getter(contact, formatter): contact = IContact(contact) city = contact.city if city is not None: city += ',' state = contact.state postal_code = contact.postal_code return ' '.join(filter(None, [city, state, postal_code]))
def submitItems(self): int_ids = getUtility(IIntIds) catalog = self.view.getCatalog() index = catalog['form_keys'] for intid in self.view.getSelectedItemIds(): key = '%s.%s' % (self.button_prefix, index.documents_to_values[intid]) if key in self.request: self.view.remove(IContact(int_ids.getObject(intid)))
def items(self): result = [] for member in self.context.members: if self.has_address(IContact(member)): result.append(member) for contact in IContactable(member).contacts: if self.has_address(contact): result.append(contact) return result
def update(self): user = IPerson(self.request.principal) super(SendEmailView, self).update() if not IContact(user).email: url = absoluteURL(self.context, self.request) + \ '/noTeacherEmail.html' self.request.response.redirect(url) return self.updateDisplayWidgets()
def contains(self, principal): person = IPerson(principal, None) if person is None: return False target = self.child if target is None: return False relationships = ContactRelationship.bind(contact=IContact(person)) is_parent = target in relationships.any(ACTIVE + PARENT) return is_parent
def columns(self): title = table.column.LocaleAwareGetterColumn( name='title', title=_(u'Name'), getter=lambda i, f: i.title, subsort=True) address_1 = zc.table.column.GetterColumn( name='address_1', title=_(u'Address 1'), getter=lambda i, f: IContact(i).address_line_1) address_2 = zc.table.column.GetterColumn( name='address_2', title=_(u'Address 2'), getter=lambda i, f: IContact(i).address_line_2) city = zc.table.column.GetterColumn(name='city', title=_(u'City'), getter=city_getter) country = zc.table.column.GetterColumn( name='country', title=_(u'Country'), getter=lambda i, f: IContact(i).country) return [title, address_1, address_2, city, country]
def contactInfo(self, contact_context, title): contact = IContact(contact_context) return { 'link': absoluteURL(contact_context, self.request), 'relationship': title, 'name': " ".join(self._extract_attrs(contact, IContactPerson)), 'address': ", ".join(self._extract_attrs(contact, IAddress)), 'emails': ", ".join(self._extract_attrs(contact, IEmails)), 'phones': list(self._extract_attrs(contact, IPhones, add_title=True)), 'languages': ", ".join(self._extract_attrs(contact, ILanguages)), '__parent__': contact_context, }
def setUpSchool(app): sy = ISchoolYearContainer(app)['2005'] = SchoolYear( '2005', date(2005, 1, 1), date(2005, 1, 30)) term = sy['spring'] = Term('Spring', date(2005, 1, 1), date(2005, 1, 30)) term.addWeekdays(0, 1, 2, 3, 4) pc = app['persons'] teacher = pc['teacher'] = BasicPerson("teacher", "Mister", "T") s1 = pc['john'] = BasicPerson("john", "John", "Peterson") s2 = pc['pete'] = BasicPerson("pete", "Pete", "Johnson") contacts = IContactContainer(app) contact = Contact() contact.__name__ = 'pete_parent' contact.prefix = 'Ms.' contact.first_name = 'Susan' contact.middle_name = 'T.' contact.last_name = 'Johnson' contact.suffix = 'Jr.' contact.address_line_1 = '1 First St.' contact.address_line_2 = 'Apt. 1' contact.city = 'NY' contact.state = 'NY' contact.country = 'USA' contact.postal_code = '00000' contact.email = '*****@*****.**' contact.home_phone = '000-0000' contact.work_phone = '111-1111' contact.mobile_phone = '222-2222' contact.language = 'English' contacts['pete_parent'] = contact IContactable(s2).contacts.relate(contact, ACTIVE + PARENT, 'p') IContactable(s2).contacts.relate(IContact(teacher), ACTIVE + PARENT, 'p') d1 = IDemographics(s1) d1['ID'] = "112323" d1['ethnicity'] = u'Asian' d1['language'] = "English" d1['placeofbirth'] = "Humptington" d1['citizenship'] = "US" d2 = IDemographics(s2) d2['ID'] = "333655" d2['ethnicity'] = u'White' d2['language'] = "Brittish" d2['placeofbirth'] = "Providence" d2['citizenship'] = "UK" course = ICourseContainer(sy)['c1'] = Course("History")
def evolve(context): linkcatalogs.ensureEvolved(context) root = context.connection.root().get(ZopePublication.root_name, None) old_site = getSite() apps = findObjectsProviding(root, ISchoolToolApplication) for app in apps: setSite(app) # vivify person contact information persons = findObjectsProviding(app, IPerson) for person in persons: contact = IContact(person, None) setSite(old_site)
def update(self): context_url = absoluteURL(self.context, self.request) catalog = self.getCatalog() int_ids = getUtility(IIntIds) index = catalog['form_keys'] if 'ADD_ITEMS' in self.request: for intid in self.getAvailableItemIds(): key = 'add_item.%s' % index.documents_to_values[intid] if key in self.request: self.add(IContact(int_ids.getObject(intid))) elif 'REMOVE_ITEMS' in self.request: for intid in self.getSelectedItemIds(): key = 'remove_item.%s' % index.documents_to_values[intid] if key in self.request: self.remove(int_ids.getObject(intid)) elif 'CANCEL' in self.request: self.request.response.redirect(context_url) self.setUpTables()
def format_contact_persons(self): def contact_getter(attribute): def getter(contact): person = IBasicPerson(contact.__parent__, None) if person is None: return getattr(contact, attribute) if attribute == '__name__': return person.username return '' return getter fields = [('ID', Text, contact_getter('__name__')), ('Prefix', Text, contact_getter('prefix')), ('First Name', Text, contact_getter('first_name')), ('Middle Name', Text, contact_getter('middle_name')), ('Last Name', Text, contact_getter('last_name')), ('Suffix', Text, contact_getter('suffix')), ('Address line 1', Text, attrgetter('address_line_1')), ('Address line 2', Text, attrgetter('address_line_2')), ('City', Date, attrgetter('city')), ('State', Date, attrgetter('state')), ('Country', Date, attrgetter('country')), ('Postal code', Date, attrgetter('postal_code')), ('Home phone', Text, attrgetter('home_phone')), ('Work phone', Text, attrgetter('work_phone')), ('Mobile phone', Text, attrgetter('mobile_phone')), ('Email', Text, attrgetter('email')), ('Language', Text, attrgetter('language'))] items = [] for person in self.context['persons'].values(): items.append(IContact(person)) for contact in IContactContainer(self.context).values(): items.append(contact) return self.format_table(fields, items, importer='export_contacts', major_progress=(0, 2))
def add(self, person): name = person.username persons = ISchoolToolApplication(None)['persons'] persons[name] = person contact = removeSecurityProxy(self.contact) person.prefix = contact.prefix person.middle_name = contact.middle_name person.suffix = contact.suffix person.photo = contact.photo if person.photo is not None: person.photo.__parent__ = person self.copyContactInfo(contact, IContact(person)) del contact.__parent__[contact.__name__] self.added = person return person
def getOmmitedItemIds(self): int_ids = getUtility(IIntIds) self_contact = IContact(self.context) return self.getSelectedItemIds() + [int_ids.getId(self_contact)]
def bound_contact(self): return IContact(self.context)
def getOmmitedItems(self): for item in EditTemporalRelationships.getOmmitedItems(self): yield item self_contact = IContact(self.context) yield self_contact
def __call__(self): contact = IContact(self.object) dependable = IDependable(contact) dependable.removeDependent("") notify( ObjectRemovedEvent(contact, contact.__parent__, contact.__name__))
def __call__(self): contact = IContact(self.object) # notify about possible changes in contact information # note: we do not provide descriptions of changes notify(ObjectModifiedEvent(contact))
def __call__(self): # auto-vivification of bound contact contact = IContact(self.object)
def children(self): contact = IContact(self.person) relationships = ContactRelationship.bind(contact=contact) return list(relationships.any(ACTIVE+PARENT))
def from_address(self): user = IPerson(self.request.principal, None) if user is None: return u'' return IContact(user).email
def getPerson(self): bound = IContact(self.person) return self.buildInfo(bound)
def buildInfo(self, contact): contact = IContact(contact) title = get_relationship_title(self.person, contact) return self.contactInfo(contact, title)