Mercurial > libervia-web
comparison browser_side/panels.py @ 350:f1b9ec412769
browser_side: MicroblogEntry defines properties to access MicroblogItem attributes (instead of overwriting __getattr__)
author | souliane <souliane@mailoo.org> |
---|---|
date | Wed, 12 Feb 2014 15:01:33 +0100 |
parents | f488692c4903 |
children | c943fd54c90e |
comparison
equal
deleted
inserted
replaced
349:f488692c4903 | 350:f1b9ec412769 |
---|---|
358 self.comments = False | 358 self.comments = False |
359 | 359 |
360 | 360 |
361 class MicroblogEntry(SimplePanel, ClickHandler, FocusHandler, KeyboardHandler): | 361 class MicroblogEntry(SimplePanel, ClickHandler, FocusHandler, KeyboardHandler): |
362 | 362 |
363 def __init__(self, blog_panel, data={}): | 363 def __init__(self, blog_panel, data): |
364 """ | 364 """ |
365 @param blog_panel: the parent panel | 365 @param blog_panel: the parent panel |
366 @param data: dict containing the blog item data, or a MicroblogItem instance. | 366 @param data: dict containing the blog item data, or a MicroblogItem instance. |
367 """ | 367 """ |
368 if isinstance(data, MicroblogItem): | 368 self._base_item = data if isinstance(data, MicroblogItem) else MicroblogItem(data) |
369 self._base_item = data | 369 for attr in ['id', 'type', 'empty', 'title', 'title_xhtml', 'content', 'content_xhtml', |
370 else: | 370 'author', 'updated', 'published', 'comments', 'service', 'node', 'hash']: |
371 self._base_item = MicroblogItem(data) | 371 getter = lambda attr: lambda inst: getattr(inst._base_item, attr) |
372 setattr(MicroblogEntry, attr, property(getter(attr))) | |
373 | |
372 SimplePanel.__init__(self) | 374 SimplePanel.__init__(self) |
373 self._blog_panel = blog_panel | 375 self._blog_panel = blog_panel |
374 | 376 |
375 self.panel = FlowPanel() | 377 self.panel = FlowPanel() |
376 self.panel.setStyleName('mb_entry') | 378 self.panel.setStyleName('mb_entry') |
396 ClickHandler.__init__(self) | 398 ClickHandler.__init__(self) |
397 self.addClickListener(self) | 399 self.addClickListener(self) |
398 | 400 |
399 self.pub_data = (self.hash[0], self.hash[1], self.id) | 401 self.pub_data = (self.hash[0], self.hash[1], self.id) |
400 self._setContent() | 402 self._setContent() |
401 | |
402 def __getattr__(self, name): | |
403 """This allows to directly use the attributes of MicroblogItem""" | |
404 if hasattr(self, name): | |
405 return self.__dict__[name] | |
406 else: | |
407 return getattr(self._base_item, name) | |
408 | 403 |
409 def _setContent(self): | 404 def _setContent(self): |
410 """Actually set the entry content (header, icons, bubble...)""" | 405 """Actually set the entry content (header, icons, bubble...)""" |
411 self.delete_label = self.update_label = self.comment_label = None | 406 self.delete_label = self.update_label = self.comment_label = None |
412 self.bubble = self.editbox = self._current_comment = None | 407 self.bubble = self.editbox = self._current_comment = None |