def flat_object(self, doc, attributes={}): blitem = dict() fields = [] elements = [] if doc is not None: blitem_id = str(doc.get('_id', '')) blitem['_id'] = blitem_id blitem['_parent'] = str(doc.get('b', '')) blitem['_num_comments'] = doc.get('cc', '') blitem['_url_id'] = doc.get('si', '') if 'c' in doc: blitem['_created'] = date_to_str(doc['c']) i = doc.get('i', False) if i: for r in i: s = r.get('s', '') t = r.get('t', '') field = t + '-' + s if field not in fields: fields.append(field) blitem[r['s']] = r['cv'] if 'cv' in r else r['v'] blitem['fields'] = fields if attributes.get('elements', False): blitem['elements'] = elements if attributes.get('tags', False): blitem['tags'] = doc.get('tg', '') if attributes.get('comments', False): blitem['comments'] = self.get_comments(blitem_id) return blitem
def flat_object(self, doc): buf = dict() if doc: buf['id'] = str(doc['_id']) if 't' in doc: buf['template'] = doc['t'] if 'f' in doc: buf['fields'] = doc['f'] if 'n' in doc: buf['name'] = doc['n'] if 'd' in doc: buf['description'] = doc['d'] if 'c' in doc: buf['date'] = date_to_str(doc['c']) if 'u' in doc: buf['owner'] = doc['u'] if 's' in doc: buf['slug'] = doc['s'] if 'ni' in doc: buf['num_items'] = doc.get('ni', 0) if 'st' in doc: stats = doc.get('st') nv = {'num_views': stats.get('v', 0)} nw = {'num_writes': stats.get('nw', 0)} ni = {'num_items': stats.get('ni', 0)} buf['stats'] = [nv, nw, ni] if 'a' in doc: buf['access'] = { 'read': ACL.get_access(doc.get('a').get('read')), 'write': ACL.get_access(doc.get('a').get('write')) } if 'img' in doc: img = doc['img'] if 'id' in img: buf['img'] = img['id'] else: buf['img'] = img if 'tg' in doc: buf['tags'] = doc['tg'] if 'at' in doc: buf['app_token'] = doc['at'] return buf