Mercurial > libervia-web
comparison src/browser/sat_browser/blog.py @ 652:0262fee86375 frontends_multi_profiles
browser_side: MicroblogPanel.accepted_groups (set of unicode) is now built from QuickWidget.targets (set of tuple of unicode)
author | souliane <souliane@mailoo.org> |
---|---|
date | Fri, 27 Feb 2015 01:11:34 +0100 |
parents | 2df91d0308ac |
children | e1d067378ad3 |
comparison
equal
deleted
inserted
replaced
651:2df91d0308ac | 652:0262fee86375 |
---|---|
355 self._blog_panel.host.bridge.call('syntaxConvert', setBubble, text, C.SYNTAX_TEXT, C.SYNTAX_XHTML) | 355 self._blog_panel.host.bridge.call('syntaxConvert', setBubble, text, C.SYNTAX_TEXT, C.SYNTAX_XHTML) |
356 | 356 |
357 | 357 |
358 class MicroblogPanel(quick_widgets.QuickWidget, libervia_widget.LiberviaWidget): | 358 class MicroblogPanel(quick_widgets.QuickWidget, libervia_widget.LiberviaWidget): |
359 warning_msg_public = "This message will be <b>PUBLIC</b> and everybody will be able to see it, even people you don't know" | 359 warning_msg_public = "This message will be <b>PUBLIC</b> and everybody will be able to see it, even people you don't know" |
360 warning_msg_group = "This message will be published for all the people of the group <span class='warningTarget'>%s</span>" | 360 warning_msg_group = "This message will be published for all the people of the following groups: <span class='warningTarget'>%s</span>" |
361 # FIXME: all the generic parts must be moved to quick_frontends | 361 # FIXME: all the generic parts must be moved to quick_frontends |
362 | 362 |
363 def __init__(self, host, accepted_groups, profiles=None): | 363 def __init__(self, host, targets, profiles=None): |
364 """Panel used to show microblog | 364 """Panel used to show microblog |
365 | 365 |
366 @param accepted_groups: groups displayed in this panel, if empty, show all microblogs from all contacts | 366 @param targets (tuple(unicode)): contact groups displayed in this panel. |
367 """ | 367 If empty, show all microblogs from all contacts. |
368 self.setAcceptedGroup(accepted_groups) | 368 """ |
369 quick_widgets.QuickWidget.__init__(self, host, self.target, C.PROF_KEY_NONE) | 369 # do not mix self.targets (set of tuple of unicode) and self.accepted_groups (set of unicode) |
370 libervia_widget.LiberviaWidget.__init__(self, host, ", ".join(accepted_groups), selectable=True) | 370 quick_widgets.QuickWidget.__init__(self, host, targets, C.PROF_KEY_NONE) |
371 libervia_widget.LiberviaWidget.__init__(self, host, ", ".join(self.accepted_groups), selectable=True) | |
371 self.entries = {} | 372 self.entries = {} |
372 self.comments = {} | 373 self.comments = {} |
373 self.selected_entry = None | 374 self.selected_entry = None |
374 self.vpanel = VerticalPanel() | 375 self.vpanel = VerticalPanel() |
375 self.vpanel.setStyleName('microblogPanel') | 376 self.vpanel.setStyleName('microblogPanel') |
378 # FIXME: workaround for a pyjamas issue: calling hash on a class method always return a different value if that method is defined directly within the class (with the "def" keyword) | 379 # FIXME: workaround for a pyjamas issue: calling hash on a class method always return a different value if that method is defined directly within the class (with the "def" keyword) |
379 self.avatarListener = self.onAvatarUpdate | 380 self.avatarListener = self.onAvatarUpdate |
380 host.addListener('avatar', self.avatarListener, [C.PROF_KEY_NONE]) | 381 host.addListener('avatar', self.avatarListener, [C.PROF_KEY_NONE]) |
381 | 382 |
382 def __str__(self): | 383 def __str__(self): |
383 return u"Blog Widget [target: {}, profile: {}]".format(self.target, self.profile) | 384 return u"Blog Widget [target: {}, profile: {}]".format(', '.join(self.accepted_groups), self.profile) |
384 | |
385 @property | |
386 def target(self): | |
387 return tuple(self.accepted_groups) | |
388 | 385 |
389 def onDelete(self): | 386 def onDelete(self): |
390 quick_widgets.QuickWidget.onDelete(self) | 387 quick_widgets.QuickWidget.onDelete(self) |
391 self.host.removeListener('avatar', self.avatarListener) | 388 self.host.removeListener('avatar', self.avatarListener) |
392 | 389 |
452 widget.refresh() # FIXME: needed ? | 449 widget.refresh() # FIXME: needed ? |
453 return widget | 450 return widget |
454 | 451 |
455 @property | 452 @property |
456 def accepted_groups(self): | 453 def accepted_groups(self): |
457 return self._accepted_groups | 454 """Return a set of the accepted groups""" |
458 | 455 return set().union(*self.targets) |
459 def matchEntity(self, item): | |
460 """ | |
461 @param item: single group as a string, list of groups | |
462 (as an array) or None (for the meta group = "all groups") | |
463 @return: True if self matches the given entity | |
464 """ | |
465 groups = item if isinstance(item, list) else ([] if item is None else [item]) | |
466 groups.sort() # sort() do not return the sorted list: do it here, not on the "return" line | |
467 return self.accepted_groups == groups | |
468 | 456 |
469 def getWarningData(self, comment=None): | 457 def getWarningData(self, comment=None): |
470 """ | 458 """ |
471 @param comment: True if the composed message is a comment. If None, consider we are | 459 @param comment: True if the composed message is a comment. If None, consider we are |
472 composing from the unibox and guess the message type from self.selected_entry | 460 composing from the unibox and guess the message type from self.selected_entry |
476 log.error("an item without comment is selected") | 464 log.error("an item without comment is selected") |
477 return ("NONE", None) | 465 return ("NONE", None) |
478 comment = self.selected_entry is not None | 466 comment = self.selected_entry is not None |
479 if comment: | 467 if comment: |
480 return ("PUBLIC", "This is a <span class='warningTarget'>comment</span> and keep the initial post visibility, so it is potentialy public") | 468 return ("PUBLIC", "This is a <span class='warningTarget'>comment</span> and keep the initial post visibility, so it is potentialy public") |
481 elif not self._accepted_groups: | 469 elif not self.accepted_groups: |
482 # we have a meta MicroblogPanel, we publish publicly | 470 # we have a meta MicroblogPanel, we publish publicly |
483 return ("PUBLIC", self.warning_msg_public) | 471 return ("PUBLIC", self.warning_msg_public) |
484 else: | 472 else: |
485 # we only accept one group at the moment | |
486 # FIXME: manage several groups | 473 # FIXME: manage several groups |
487 return ("GROUP", self.warning_msg_group % self._accepted_groups[0]) | 474 return ("GROUP", self.warning_msg_group % ' '.join(self.accepted_groups)) |
488 | 475 |
489 def onTextEntered(self, text): | 476 def onTextEntered(self, text): |
490 if self.selected_entry: | 477 if self.selected_entry: |
491 # we are entering a comment | 478 # we are entering a comment |
492 comments_url = self.selected_entry.comments | 479 comments_url = self.selected_entry.comments |
493 if not comments_url: | 480 if not comments_url: |
494 raise Exception("ERROR: the comments URL is empty") | 481 raise Exception("ERROR: the comments URL is empty") |
495 target = ("COMMENT", comments_url) | 482 target = ("COMMENT", comments_url) |
496 elif not self._accepted_groups: | 483 elif not self.accepted_groups: |
497 # we are entering a public microblog | 484 # we are entering a public microblog |
498 target = ("PUBLIC", None) | 485 target = ("PUBLIC", None) |
499 else: | 486 else: |
500 # we are entering a microblog restricted to a group | 487 target = ("GROUP", self.accepted_groups) |
501 # FIXME: manage several groups | |
502 target = ("GROUP", self._accepted_groups[0]) | |
503 self.host.send([target], text) | 488 self.host.send([target], text) |
504 | 489 |
505 def accept_all(self): | 490 def accept_all(self): |
506 return not self._accepted_groups # we accept every microblog only if we are not filtering by groups | 491 return not self.accepted_groups # we accept every microblog only if we are not filtering by groups |
507 | 492 |
508 def getEntries(self): | 493 def getEntries(self): |
509 """Ask all the entries for the currenly accepted groups, | 494 """Ask all the entries for the currenly accepted groups, |
510 and fill the panel""" | 495 and fill the panel""" |
511 | 496 |
700 elif isinstance(child, VerticalPanel): | 685 elif isinstance(child, VerticalPanel): |
701 updateVPanel(child) | 686 updateVPanel(child) |
702 if type_ == 'avatar': | 687 if type_ == 'avatar': |
703 updateVPanel(self.vpanel) | 688 updateVPanel(self.vpanel) |
704 | 689 |
705 def setAcceptedGroup(self, group): | 690 def addAcceptedGroups(self, groups): |
706 """Add one or more group(s) which can be displayed in this panel. | 691 """Add one or more group(s) which can be displayed in this panel. |
707 | 692 |
708 Prevent from duplicate values and keep the list sorted. | 693 @param groups (tuple(unicode)): tuple of groups to add |
709 @param group: string of the group, or list of string | 694 """ |
710 """ | 695 # FIXME: update the widget's hash in QuickApp._widgets[MicroblogPanel] |
711 if isinstance(group, basestring): | 696 self.targets.update(groups) |
712 groups = [group] | |
713 else: | |
714 groups = list(group) | |
715 try: | |
716 self._accepted_groups.extend(groups) | |
717 except (AttributeError, TypeError): # XXX: should be AttributeError, but pyjamas bugs here | |
718 self._accepted_groups = groups | |
719 self._accepted_groups.sort() | |
720 | 697 |
721 def isJidAccepted(self, jid_): | 698 def isJidAccepted(self, jid_): |
722 """Tell if a jid is actepted and must be shown in this panel | 699 """Tell if a jid is actepted and must be shown in this panel |
723 | 700 |
724 @param jid_(jid.JID): jid to check | 701 @param jid_(jid.JID): jid to check |
725 @return: True if the jid is accepted | 702 @return: True if the jid is accepted |
726 """ | 703 """ |
727 assert isinstance(jid_, jid.JID) # FIXME temporary | 704 assert isinstance(jid_, jid.JID) # FIXME temporary |
728 if self.accept_all(): | 705 if self.accept_all(): |
729 return True | 706 return True |
730 for group in self._accepted_groups: | 707 for group in self.accepted_groups: |
731 if self.host.contact_lists[self.profile].isEntityInGroup(jid_, group): | 708 if self.host.contact_lists[self.profile].isEntityInGroup(jid_, group): |
732 return True | 709 return True |
733 return False | 710 return False |
734 | 711 |
735 | 712 |