Changeset 1705
- Timestamp:
- 07/23/08 12:30:40 (12 months ago)
- Location:
- trunk/pylucid
- Files:
-
- 2 added
- 4 modified
-
media/PyLucid/internal_page/blog/display_blog.css (modified) (2 diffs)
-
media/PyLucid/internal_page/blog/display_blog.html (modified) (2 diffs)
-
media/PyLucid/internal_page/blog/select_feed_format.css (added)
-
media/PyLucid/internal_page/blog/select_feed_format.html (added)
-
PyLucid/plugins_internal/blog/blog.py (modified) (12 diffs)
-
PyLucid/plugins_internal/blog/blog_cfg.py (modified) (6 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/pylucid/media/PyLucid/internal_page/blog/display_blog.css
r1701 r1705 33 33 } 34 34 /* -------------------------------------------------------------------------- */ 35 . action_link,.admin_info_line {35 .blog .action_link, .blog .admin_info_line { 36 36 color: #fff; 37 37 display:block; 38 38 background-color: #09C; 39 39 } 40 . admin_info_line {40 .blog .admin_info_line { 41 41 text-align: center; 42 42 background-color: #33CC99; … … 151 151 margin: 0px; 152 152 } 153 .feed _type, .feed_typeli {153 .feeds, .feeds li { 154 154 display:inline; 155 155 } -
trunk/pylucid/media/PyLucid/internal_page/blog/display_blog.html
r1701 r1705 1 {% if back_url %}<p><a href="{{ back_url }}" class="action_link"> Display all blog entries</a></p>{% endif %}1 {% if back_url %}<p><a href="{{ back_url }}" class="action_link">« Display all blog entries</a></p>{% endif %} 2 2 {% if create_url %}<p><a href="{{ create_url }}" class="action_link">create a new blog entry</a></p>{% endif %} 3 3 … … 97 97 98 98 <fieldset class="feeds"><legend>{% trans 'available syndication feeds' %}</legend> 99 {% regroup feed_info|dictsort:"feed_type" by feed_type as feeds_grouped %} 100 <ul> 101 {% for feed in feeds_grouped %} 102 <li class="grouper"><strong>{{ feed.grouper }}:</strong> 103 <ul class="feed_type"> 104 {% for item in feed.list %} 105 <li><a href="{{ item.url }}">{{ item.title_info }}</a></li> 106 {% endfor %} 107 </ul> 108 </li> 99 <ul>{% trans 'normal feeds:' %} 100 {% for feed in feed_info %} 101 <li><a href="{{ feed.url }}">{{ feed.title_info }}</a></li> 102 {% endfor %} 103 </ul> 104 <ul>{% trans 'tag feeds:' %} 105 {% for feed in tag_feed_info %} 106 <li><a href="{{ feed.url }}">{{ feed.title_info }}</a></li> 109 107 {% endfor %} 110 108 </ul> 111 109 </fieldset> 112 110 113 {% if back_url %}<p><a href="{{ back_url }}" class="action_link"> Display all blog entries</a></p>{% endif %}111 {% if back_url %}<p><a href="{{ back_url }}" class="action_link">« Display all blog entries</a></p>{% endif %} 114 112 {% if create_url %}<p><a href="{{ create_url }}" class="action_link">create a new blog entry</a></p>{% endif %} -
trunk/pylucid/PyLucid/plugins_internal/blog/blog.py
r1701 r1705 27 27 from django.conf import settings 28 28 from django.http import HttpResponse 29 from django.utils import feedgenerator30 29 from django.core.mail import send_mail 31 from django.utils.safestring import mark_safe32 from django.utils.encoding import force_unicode30 #from django.utils.safestring import mark_safe 31 #from django.utils.encoding import force_unicode 33 32 from django.utils.translation import ugettext as _ 34 from django.utils import feedgenerator 35 from django.contrib.syndication.feeds import Feed, FeedDoesNotExist 33 #from django import newforms as forms 34 #from django.newforms import ValidationError 35 #from django.contrib.syndication.feeds import Feed, FeedDoesNotExist 36 36 37 37 # from PyLucid … … 40 40 from PyLucid.tools.utils import escape_django_tags 41 41 from PyLucid.system.page_msg import PageMessages 42 #from PyLucid.tools.newforms_utils import InternalURLField 43 from PyLucid.tools.syndication_feed import FeedFormat, FEED_FORMAT_INFO 42 44 43 45 # from blog plugin … … 65 67 ENTRIES_FEED_NAME = u"entries" 66 68 COMMENTS_FEED_NAME = u"comments" 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! 96 70 97 71 #______________________________________________________________________________ … … 111 85 ) 112 86 87 # URLs 88 self.index_url = self.current_page.get_absolute_url() 89 self.feed_url_prefix = self.URLs.methodLink("feed") 90 113 91 # Get the default preference entry. 114 92 self.preferences = self.get_preferences() … … 116 94 # Change the page title. 117 95 self.current_page.title = self.preferences["blog_title"] 118 119 # The absolute url to the page witch contains the blog120 self.index_url = "FIXME"121 122 self.feed_url_prefix = self.URLs.methodLink("feed")123 96 124 97 … … 176 149 # Add all available syndication feeds information 177 150 context["feed_info"] = self._get_feeds_info() 151 context["tag_feed_info"] = self._get_tag_feeds_info() 178 152 179 153 self._render_template("display_blog", context, debug=0) … … 256 230 #"blog_entry": blog_entry, 257 231 "add_comment_form": form, 258 "back_url": self. URLs.methodLink("lucidTag"),232 "back_url": self.index_url, 259 233 } 260 234 … … 691 665 self._render_template("mod_comments", context)#, debug=2) 692 666 693 def _ get_feeds_info(self):694 """ 695 returns information about all available syndication feeds.696 """ 697 f eed_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 """ 709 683 # Build a list of tag feeds 710 684 limit = self.preferences.get("max_tag_feed", 10) 711 685 tags = BlogTag.objects.values_list("slug", "name").all()[:limit] 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 = [] 715 711 # Add tag feeds 716 712 for tag_slug, tag_name in tags: 717 713 filename = TAG_FEED_PREFIX + tag_slug 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. 730 756 731 757 feed_name e.g.: … … 735 761 comments .rss/.atom 736 762 """ 763 if raw_feed_name == None: 764 return self.error(_("Wrong URL."), "No feed filename given in URL.") 765 737 766 title = self.preferences["blog_title"] 738 767 768 feed_info = FeedFormat() 739 769 try: 740 feed_name, feed_type = os.path.splitext(raw_feed_name) 741 feed_type = feed_type.lstrip(".") 770 feed_info.parse_filename(raw_feed_name) 742 771 except Exception, err: 772 if self.request.debug: raise 743 773 return self.error(_("Wrong URL."), err) 744 774 745 if feed_type == RSS: 746 FeedGenerator = feedgenerator.Rss201rev2Feed 747 elif feed_type == ATOM: 748 FeedGenerator = feedgenerator.Atom1Feed 749 else: 750 return self.error( 751 _("Wrong URL."), " feed type '%s' unknown." % feed_type 752 ) 775 feed_name = feed_info["feed_name"] 776 format_info = feed_info["format_info"] 777 FeedGenerator = format_info["generator"] 753 778 754 779 limit = self._get_max_count() … … 780 805 items = entries.filter(is_public=True).all()[:limit] 781 806 782 feed = self._get_feed(FeedGenerator, items, title )807 feed = self._get_feed(FeedGenerator, items, title, feed_name) 783 808 feed_content = feed.writeString('utf8') 784 809 content_type = "%s; charset=utf-8" % feed.mime_type … … 798 823 799 824 800 def _get_feed(self, FeedGenerator, items, title ):825 def _get_feed(self, FeedGenerator, items, title, feed_name): 801 826 """ 802 827 returns the generated feed. … … 805 830 title = title, 806 831 link = self.URLs.make_absolute_url(self.index_url), 807 description = self.preferences.get("description", ""), # XXX808 language = self.preferences.get("language", u"en"), # XXX832 description = self.preferences.get("description", ""), 833 language = self.preferences.get("language", u"en"), 809 834 ) 810 835 for item in items: 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 ) 818 860 819 861 return feed -
trunk/pylucid/PyLucid/plugins_internal/blog/blog_cfg.py
r1701 r1705 5 5 __author__ = "Jens Diemer" 6 6 __url__ = "http://www.PyLucid.org" 7 __description__ = "A simple blog system (extermental)"7 __description__ = "A simple blog system" 8 8 __long_description__ = """ 9 More information: http://www.pylucid.org/_goto/165/blog/ 9 10 """ 10 11 … … 12 13 # preferences 13 14 14 from django.conf import settings15 15 from django import newforms as forms 16 16 from django.contrib.auth.models import User … … 35 35 'mod_keywords' and 'spam_keywords' are case-insensitive and matches on every 36 36 partial word. Be carefull with 'spam_keywords'. 37 38 More information: http://www.pylucid.org/_goto/165/blog/ 37 39 """ 38 40 blog_title = forms.CharField( … … 43 45 ) 44 46 description = forms.CharField( 45 initial = "", 47 initial = "", required=False, 46 48 help_text = _( 47 49 "The blog description (Used for RSS/Atom feeds)." … … 132 134 ) 133 135 134 # Optional, this Plugin can't have multiple preferences 136 137 # They can only exist one blog in a PyLucid instance 135 138 multiple_pref = False 136 139 … … 150 153 "add_comment": anonymous_rights, 151 154 "detail": anonymous_rights, 152 "feed": anonymous_rights, 155 156 "select_feed_format": anonymous_rights, 157 "feed": anonymous_rights, 153 158 154 159 #__________________________________________________________________________
