Mercurial > libervia-web
comparison src/server/blog.py @ 880:ccbad50e1426
blog, themes(default): added <link> element referencing xmpp: uri of the item
author | Goffi <goffi@goffi.org> |
---|---|
date | Wed, 09 Mar 2016 17:56:19 +0100 |
parents | 2e0e9cf9efb4 |
children | 6bdee34fa2f4 |
comparison
equal
deleted
inserted
replaced
879:2e0e9cf9efb4 | 880:ccbad50e1426 |
---|---|
557 return sanitizeHtml(options[key]) if key in options else '' | 557 return sanitizeHtml(options[key]) if key in options else '' |
558 | 558 |
559 avatar = os.path.normpath('/{}'.format(getOption('avatar'))) | 559 avatar = os.path.normpath('/{}'.format(getOption('avatar'))) |
560 title = getOption(C.STATIC_BLOG_PARAM_TITLE) or user | 560 title = getOption(C.STATIC_BLOG_PARAM_TITLE) or user |
561 query_data = urllib.urlencode(getDefaultQueryData(request)).decode('utf-8') | 561 query_data = urllib.urlencode(getDefaultQueryData(request)).decode('utf-8') |
562 | |
563 xmpp_uri = metadata['uri'] | |
564 if len(items) == 1: | |
565 # FIXME: that's really not a good way to get item id | |
566 # this must be changed after static blog refactorisation | |
567 item_id = items[0][0]['id'] | |
568 xmpp_uri+=u";item={}".format(urllib.quote(item_id)) | |
569 | |
562 data = {'url_base': base_url, | 570 data = {'url_base': base_url, |
571 'xmpp_uri': xmpp_uri, | |
563 'url_query': u'?{}'.format(query_data) if query_data else '' , | 572 'url_query': u'?{}'.format(query_data) if query_data else '' , |
564 'keywords': getOption(C.STATIC_BLOG_PARAM_KEYWORDS), | 573 'keywords': getOption(C.STATIC_BLOG_PARAM_KEYWORDS), |
565 'description': getOption(C.STATIC_BLOG_PARAM_DESCRIPTION), | 574 'description': getOption(C.STATIC_BLOG_PARAM_DESCRIPTION), |
566 'title': title, | 575 'title': title, |
567 'favicon': avatar, | 576 'favicon': avatar, |
589 request.finish() | 598 request.finish() |
590 | 599 |
591 | 600 |
592 class NavigationLinks(object): | 601 class NavigationLinks(object): |
593 | 602 |
594 def __init__(self, request, items, rsm_data, base_url): | 603 def __init__(self, request, items, metadata, base_url): |
595 """Build the navigation links. | 604 """Build the navigation links. |
596 | 605 |
597 @param items (list): list of items | 606 @param items (list): list of items |
598 @param rsm_data (dict): rsm data | 607 @param metadata (dict): rsm data |
599 @param base_url (unicode): the base URL for this user's blog | 608 @param base_url (unicode): the base URL for this user's blog |
600 @return: dict | 609 @return: dict |
601 """ | 610 """ |
611 # FIXME: this code must be refactorized, it is fragile | |
612 # and difficult to maintain | |
613 | |
602 # query data which must be present in all links | 614 # query data which must be present in all links |
603 default_query_data = getDefaultQueryData(request) | 615 default_query_data = getDefaultQueryData(request) |
604 | 616 |
605 # which links we need to display | 617 # which links we need to display |
606 if request.display_single: | 618 if request.display_single: |
615 for key in links: | 627 for key in links: |
616 query_data = default_query_data.copy() | 628 query_data = default_query_data.copy() |
617 | 629 |
618 if key.startswith('later_message'): | 630 if key.startswith('later_message'): |
619 try: | 631 try: |
620 index = int(rsm_data['rsm_index']) | 632 index = int(metadata['rsm_index']) |
621 except (KeyError, ValueError): | 633 except (KeyError, ValueError): |
622 pass | 634 pass |
623 else: | 635 else: |
624 if index == 0: | 636 if index == 0: |
625 # we don't show this link on first page | 637 # we don't show this link on first page |
626 setattr(self, key, '') | 638 setattr(self, key, '') |
627 continue | 639 continue |
628 try: | 640 try: |
629 query_data['before'] = rsm_data['rsm_first'].encode('utf-8') | 641 query_data['before'] = metadata['rsm_first'].encode('utf-8') |
630 except KeyError: | 642 except KeyError: |
631 pass | 643 pass |
632 else: | 644 else: |
633 try: | 645 try: |
634 index = int(rsm_data['rsm_index']) | 646 index = int(metadata['rsm_index']) |
635 count = int(rsm_data.get('rsm_count')) | 647 count = int(metadata.get('rsm_count')) |
636 except (KeyError, ValueError): | 648 except (KeyError, ValueError): |
637 # XXX: if we don't have index or count, we can't know if we | 649 # XXX: if we don't have index or count, we can't know if we |
638 # are on the last page or not | 650 # are on the last page or not |
639 pass | 651 pass |
640 else: | 652 else: |
642 # on the last page | 654 # on the last page |
643 if index + len(items) >= count: | 655 if index + len(items) >= count: |
644 setattr(self, key, '') | 656 setattr(self, key, '') |
645 continue | 657 continue |
646 try: | 658 try: |
647 query_data['after'] = rsm_data['rsm_last'].encode('utf-8') | 659 query_data['after'] = metadata['rsm_last'].encode('utf-8') |
648 except KeyError: | 660 except KeyError: |
649 pass | 661 pass |
650 | 662 |
651 if request.display_single: | 663 if request.display_single: |
652 query_data['max'] = 1 | 664 query_data['max'] = 1 |