# HG changeset patch # User souliane # Date 1392213693 -3600 # Node ID f1b9ec412769b154a652a0da0b2e9831de29c35c # Parent f488692c49030b4c26c15140ee5c3aedb272a8b7 browser_side: MicroblogEntry defines properties to access MicroblogItem attributes (instead of overwriting __getattr__) diff -r f488692c4903 -r f1b9ec412769 browser_side/panels.py --- a/browser_side/panels.py Wed Feb 12 14:58:11 2014 +0100 +++ b/browser_side/panels.py Wed Feb 12 15:01:33 2014 +0100 @@ -360,15 +360,17 @@ class MicroblogEntry(SimplePanel, ClickHandler, FocusHandler, KeyboardHandler): - def __init__(self, blog_panel, data={}): + def __init__(self, blog_panel, data): """ @param blog_panel: the parent panel @param data: dict containing the blog item data, or a MicroblogItem instance. """ - if isinstance(data, MicroblogItem): - self._base_item = data - else: - self._base_item = MicroblogItem(data) + self._base_item = data if isinstance(data, MicroblogItem) else MicroblogItem(data) + for attr in ['id', 'type', 'empty', 'title', 'title_xhtml', 'content', 'content_xhtml', + 'author', 'updated', 'published', 'comments', 'service', 'node', 'hash']: + getter = lambda attr: lambda inst: getattr(inst._base_item, attr) + setattr(MicroblogEntry, attr, property(getter(attr))) + SimplePanel.__init__(self) self._blog_panel = blog_panel @@ -399,13 +401,6 @@ self.pub_data = (self.hash[0], self.hash[1], self.id) self._setContent() - def __getattr__(self, name): - """This allows to directly use the attributes of MicroblogItem""" - if hasattr(self, name): - return self.__dict__[name] - else: - return getattr(self._base_item, name) - def _setContent(self): """Actually set the entry content (header, icons, bubble...)""" self.delete_label = self.update_label = self.comment_label = None