Created
May 3, 2012 16:04
-
-
Save zzzeek/2586821 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Entry(Base): | |
# ... | |
@property | |
def public_children(self): | |
return set(c for c in self.children if c.public) | |
class Child(Base): | |
# ... | |
@property | |
def public_author(self): | |
if self.author.public: | |
return self.author | |
else: | |
return None | |
class Author(Base): | |
# ... | |
@property | |
def public_company(self): | |
if self.company.public: | |
return self.company | |
else: | |
return None | |
item = session.query(Entry).filter_by(public=True, id=item_id).scalar() | |
data = {‘id’: item.id, | |
‘title’: item.title, | |
‘date’: item.date, | |
‘body’: item.body} | |
data[‘children’] = children = [] | |
for child in item.public_children: | |
child_data = {‘id’: child.id, | |
‘title’: child.title, | |
‘data’: child.data, | |
‘body’: child.body} | |
if child.public_author: | |
child_data[‘author’] = author = {‘id’: child.author.id, | |
‘name’: child.author.name} | |
if child.author.public_company: | |
author[‘company’] = {‘id’: child.author.company.id, | |
‘title’: child.author.company.title} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment