def jsondata(self): # json response header needed? soup = get_contacts_soup(self.context) aaData = list() size, result = self.query(soup) columns = self.columns colnames = [_['id'] for _ in columns] def record2list(record, bookings_quantity=None): result = list() for colname in colnames: coldef = self.column_def(colname) renderer = coldef.get('renderer') if renderer: value = renderer(colname, record) else: value = record.attrs.get(colname, '') result.append(value) return result for lazyrecord in self.slice(result): aaData.append(record2list(lazyrecord())) data = { "draw": int(self.request.form['draw']), "recordsTotal": size, "recordsFiltered": size, "data": aaData, } self.request.response.setHeader('Content-Type', 'application/json; charset=utf-8') return json.dumps(data)
def jsondata(self): # json response header needed? soup = get_contacts_soup(self.context) aaData = list() size, result = self.query(soup) columns = self.columns colnames = [_['id'] for _ in columns] def record2list(record, bookings_quantity=None): result = list() for colname in colnames: coldef = self.column_def(colname) renderer = coldef.get('renderer') if renderer: value = renderer(colname, record) else: value = record.attrs.get(colname, '') result.append(value) return result for lazyrecord in self.slice(result): aaData.append(record2list(lazyrecord())) data = { "draw": int(self.request.form['draw']), "recordsTotal": size, "recordsFiltered": size, "data": aaData, } self.request.response.setHeader( 'Content-Type', 'application/json; charset=utf-8' ) return json.dumps(data)
def fix_contacts_email(ctx=None): """Add email attribute to contact records. """ portal = getSite() soup = get_contacts_soup(portal) data = soup.storage.data need_rebuild = False for item in data.values(): update = False try: item.attrs['email'] except KeyError: update = True if not update: continue email = item.attrs.get('personal_data.email', 'n/a') item.attrs['email'] = email need_rebuild = True logging.info( u"Added email to contact {0}".format(item.attrs['uid']) ) if need_rebuild: soup.rebuild() logging.info("Rebuilt contacts catalog")
def fix_contacts_email(ctx=None): """Add email attribute to contact records. """ portal = getSite() soup = get_contacts_soup(portal) data = soup.storage.data need_rebuild = False for item in data.values(): update = False try: item.attrs['email'] except KeyError: update = True if not update: continue email = item.attrs.get('personal_data.email', 'n/a') item.attrs['email'] = email need_rebuild = True logging.info("Added email to contact {0}".format(item.attrs['uid'])) if need_rebuild: soup.rebuild() logging.info("Rebuilt contacts catalog")