| 67 | | TAG_FEED_PREFIX = u"tag_" # The tag slug would be appended! |
| 68 | | |
| 69 | | # All file endings must be lower case and without "." ! |
| 70 | | RSS = u"rss" |
| 71 | | ATOM = u"atom" |
| 72 | | |
| 73 | | #______________________________________________________________________________ |
| 74 | | |
| 75 | | class FeedInfo(list): |
| 76 | | """ |
| 77 | | A list of feed information. |
| 78 | | I a normal list with one spectial add method. |
| 79 | | Contains a dict for every feed info. |
| 80 | | """ |
| 81 | | def add(self, title_info, url_parts): |
| 82 | | assert(isinstance(url_parts, (list,tuple))) #Needed? |
| 83 | | url_start = posixpath.join(*url_parts) |
| 84 | | |
| 85 | | list.append(self, { |
| 86 | | "feed_type": RSS, |
| 87 | | "title_info": title_info, |
| 88 | | "url": "%s.%s" % (url_start, RSS), |
| 89 | | }) |
| 90 | | list.append(self, { |
| 91 | | "feed_type": ATOM, |
| 92 | | "title_info": title_info, |
| 93 | | "url": "%s.%s" % (url_start, ATOM), |
| 94 | | }) |
| 95 | | |
| | 69 | TAG_FEED_PREFIX = u"tag-" # The tag slug would be appended! |
| 693 | | def _get_feeds_info(self): |
| 694 | | """ |
| 695 | | returns information about all available syndication feeds. |
| 696 | | """ |
| 697 | | feed_info = FeedInfo() |
| 698 | | |
| 699 | | # Add "normal" feeds |
| 700 | | feed_info.add( |
| 701 | | title_info = ENTRIES_FEED_NAME, |
| 702 | | url_parts = (self.feed_url_prefix, ENTRIES_FEED_NAME,) |
| 703 | | ) |
| 704 | | feed_info.add( |
| 705 | | title_info = COMMENTS_FEED_NAME, |
| 706 | | url_parts = (self.feed_url_prefix, COMMENTS_FEED_NAME,) |
| 707 | | ) |
| 708 | | |
| | 667 | def _feed_filenames(self): |
| | 668 | """ |
| | 669 | returns a list of all existing feed filenames |
| | 670 | """ |
| | 671 | filenames = [] |
| | 672 | filenames.extend([ENTRIES_FEED_NAME, COMMENTS_FEED_NAME]) |
| | 673 | |
| | 674 | tags = self._get_tags() |
| | 675 | filenames.extend([TAG_FEED_PREFIX + tag_slug for tag_slug, _ in tags]) |
| | 676 | |
| | 677 | return filenames |
| | 678 | |
| | 679 | def _get_tags(self): |
| | 680 | """ |
| | 681 | returns a list of all tags. |
| | 682 | """ |
| 712 | | tag_feeds = [TAG_FEED_PREFIX + i[0] for i in tags] |
| 713 | | #self.page_msg(tag_feeds) |
| 714 | | |
| | 686 | return tags |
| | 687 | |
| | 688 | def _get_feeds_info(self): |
| | 689 | """ |
| | 690 | returns information about all available syndication feeds. |
| | 691 | """ |
| | 692 | feeds = [] |
| | 693 | |
| | 694 | for feed_name in (ENTRIES_FEED_NAME, COMMENTS_FEED_NAME,): |
| | 695 | feeds.append({ |
| | 696 | "url": self.URLs.methodLink("select_feed_format", feed_name), |
| | 697 | "title_info": feed_name, |
| | 698 | "filename": feed_name |
| | 699 | }) |
| | 700 | |
| | 701 | #self.page_msg(feeds) |
| | 702 | return feeds |
| | 703 | |
| | 704 | def _get_tag_feeds_info(self): |
| | 705 | """ |
| | 706 | returns information about all available syndication feeds. |
| | 707 | """ |
| | 708 | tags = self._get_tags() |
| | 709 | |
| | 710 | feeds = [] |
| 718 | | |
| 719 | | feed_info.add( |
| 720 | | title_info = tag_name, |
| 721 | | url_parts = (self.feed_url_prefix, filename,) |
| 722 | | ) |
| 723 | | |
| 724 | | return feed_info |
| 725 | | |
| 726 | | |
| 727 | | def feed(self, raw_feed_name): |
| 728 | | """ |
| 729 | | Generate and return a syndication feeds. |
| | 714 | feeds.append({ |
| | 715 | "url": self.URLs.methodLink("select_feed_format", filename), |
| | 716 | "title_info": tag_name, |
| | 717 | "filename": filename |
| | 718 | }) |
| | 719 | |
| | 720 | #self.page_msg(feeds) |
| | 721 | return feeds |
| | 722 | |
| | 723 | def select_feed_format(self, raw_feed_name=None): |
| | 724 | """ |
| | 725 | Build a html page with all existing feed formats |
| | 726 | """ |
| | 727 | if raw_feed_name == None: |
| | 728 | return self.error(_("Wrong URL."), "No feed filename given in URL.") |
| | 729 | |
| | 730 | feed_name = raw_feed_name.strip("/") |
| | 731 | existing_filenames = self._feed_filenames() |
| | 732 | if feed_name not in existing_filenames: |
| | 733 | return self.error(_("Wrong URL."), "Feed filename doesn't exist") |
| | 734 | |
| | 735 | format_info = [] |
| | 736 | for feed_info in FEED_FORMAT_INFO: |
| | 737 | filename = "%s.%s" % (feed_name, feed_info["ext"]) |
| | 738 | format_info.append({ |
| | 739 | "filename": filename, |
| | 740 | "url": self.URLs.methodLink("feed", filename).rstrip("/"), |
| | 741 | "title": feed_info["title"], |
| | 742 | "info_link": feed_info["info_link"], |
| | 743 | "mime_type": feed_info["generator"].mime_type, |
| | 744 | }) |
| | 745 | |
| | 746 | context = { |
| | 747 | "back_url": self.index_url, |
| | 748 | "format_info": format_info, |
| | 749 | } |
| | 750 | |
| | 751 | self._render_template("select_feed_format", context, debug=0) |
| | 752 | |
| | 753 | def feed(self, raw_feed_name=None): |
| | 754 | """ |
| | 755 | Generate and return a syndication feed. |
| 811 | | feed.add_item( |
| 812 | | title = item.headline, |
| 813 | | link = self.URLs.make_absolute_url( |
| 814 | | self.URLs.methodLink("detail", item.id) |
| 815 | | ), |
| 816 | | description = item.html_content(self.context), |
| 817 | | ) |
| | 836 | if feed_name == COMMENTS_FEED_NAME: |
| | 837 | # Feed with all comments |
| | 838 | feed.add_item( |
| | 839 | title = _("Comment from '%s' for blog entry '%s'") % ( |
| | 840 | item.person_name, item.blog_entry.headline |
| | 841 | ), |
| | 842 | link = self.URLs.make_absolute_url( |
| | 843 | self.URLs.methodLink("detail", item.blog_entry.id) |
| | 844 | ), |
| | 845 | description = item.content, |
| | 846 | author_name=item.person_name, |
| | 847 | pubdate = item.createtime, |
| | 848 | ) |
| | 849 | else: |
| | 850 | # Feed with blog entries |
| | 851 | feed.add_item( |
| | 852 | title = item.headline, |
| | 853 | link = self.URLs.make_absolute_url( |
| | 854 | self.URLs.methodLink("detail", item.id) |
| | 855 | ), |
| | 856 | description = item.html_content(self.context), |
| | 857 | author_name=item.createby, |
| | 858 | pubdate = item.createtime, |
| | 859 | ) |