Changeset 2538
- Timestamp:
- 02/24/10 10:00:22 (5 months ago)
- Location:
- branches/0.9/pylucid_project
- Files:
-
- 5 added
- 8 modified
-
pylucid_plugins/blog/preference_forms.py (modified) (1 diff)
-
pylucid_plugins/blog/templates/blog/detail_view.html (modified) (1 diff)
-
pylucid_plugins/blog/templates/blog/feed_description.html (added)
-
pylucid_plugins/blog/templates/blog/includes/add_tag_filter.html (added)
-
pylucid_plugins/blog/templates/blog/includes/tagcloud.html (modified) (1 diff)
-
pylucid_plugins/blog/templates/blog/includes/taglist.html (modified) (1 diff)
-
pylucid_plugins/blog/templates/blog/select_feed.html (added)
-
pylucid_plugins/blog/templates/blog/summary.html (modified) (2 diffs)
-
pylucid_plugins/blog/urls.py (modified) (1 diff)
-
pylucid_plugins/blog/views.py (modified) (9 diffs)
-
pylucid_plugins/update_journal/preference_forms.py (added)
-
pylucid_plugins/update_journal/views.py (modified) (3 diffs)
-
utils/safe_obtain.py (added)
Legend:
- Unmodified
- Added
- Removed
-
branches/0.9/pylucid_project/pylucid_plugins/blog/preference_forms.py
r2523 r2538 24 24 ), 25 25 ) 26 27 initial_feed_count = forms.IntegerField( 28 initial=5, min_value=1, 29 help_text=_("Default numbers of blog articles in RSS/Atom feed."), 30 ) 31 max_feed_count = forms.IntegerField( 32 initial=30, min_value=1, 33 help_text=_("The maximal numbers of blog articles in RSS/Atom feed."), 34 ) 26 35 class Meta: 27 36 app_label = 'blog' -
branches/0.9/pylucid_project/pylucid_plugins/blog/templates/blog/detail_view.html
r2443 r2538 21 21 <div class="content">{{ entry.get_html }}</div> 22 22 23 {% if entry.lastupdateby %} 23 24 <small><p class="date_info"> 24 {% if entry.lastupdateby %}(Last update: {{ entry.lastupdatetime|date:_("DATETIME_FORMAT") }} by {{ entry.lastupdateby }}.){% endif %}25 (Last update: {{ entry.lastupdatetime|date:_("DATETIME_FORMAT") }} by {{ entry.lastupdateby }}.) 25 26 </p></small> 27 {% endif %} 26 28 27 29 {% include "blog/includes/taglist.html" %} -
branches/0.9/pylucid_project/pylucid_plugins/blog/templates/blog/includes/tagcloud.html
r2113 r2538 2 2 {% for tag in tag_cloud %} 3 3 {% if not forloop.first %}|{% endif %} 4 <a href="{% url Blog-tag_view tag=tag.name %}" style="font-size:{{ tag.font_size }}em;">{{ tag.name }}</a> 4 5 {% if tag.name in used_tags %} 6 <strong style="font-size:{{ tag.font_size }}em;">{{ tag.name }}</strong> 7 {% else %} 8 <a href="{% url Blog-tag_view tags=tag.name %}" style="font-size:{{ tag.font_size }}em;">{{ tag.name }}</a> 9 {% endif %} 10 11 {% if add_tag_filter_link %} 12 {% include "blog/includes/add_tag_filter.html" %} 13 {% endif %} 5 14 {% endfor %} 6 15 </fieldset> -
branches/0.9/pylucid_project/pylucid_plugins/blog/templates/blog/includes/taglist.html
r2250 r2538 5 5 {% for tag in tags %} 6 6 {% if not forloop.first %}|{% endif %} 7 <a href="{% url Blog-tag_view tag=tag.name %}">{{ tag.name }}</a> 7 {% if tag.name in used_tags %} 8 <strong>{{ tag.name }}</strong> 9 {% else %} 10 <a href="{% url Blog-tag_view tags=tag.name %}">{{ tag.name }}</a> 11 {% endif %} 12 {% if add_tag_filter_link %} 13 {% include "blog/includes/add_tag_filter.html" %} 14 {% endif %} 8 15 {% endfor %} 9 16 </fieldset> -
branches/0.9/pylucid_project/pylucid_plugins/blog/templates/blog/summary.html
r2523 r2538 22 22 <div class="content">{{ entry.get_html }}</div> 23 23 24 {% if entry.lastupdateby %} 24 25 <small><p class="date_info"> 25 {% if entry.lastupdateby %}(Last update: {{ entry.lastupdatetime|date:_("DATETIME_FORMAT") }} by {{ entry.lastupdateby }}.){% endif %}26 (Last update: {{ entry.lastupdatetime|date:_("DATETIME_FORMAT") }} by {{ entry.lastupdateby }}.) 26 27 </p></small> 28 {% endif %} 27 29 28 30 {% include "blog/includes/taglist.html" %} … … 34 36 {% endfor %} 35 37 </div> 38 39 <fieldset class="feed_selection"><legend>{% trans "Syndication feed format:" %}</legend> 40 <ul> 41 {% for feed in feeds %} 42 <li> 43 {% if tags %} 44 <a href="{% url Blog-tag_feed tags feed.filename %}">{% url Blog-tag_feed tags feed.filename %}</a> 45 {% else %} 46 <a href="{% url Blog-feed feed.filename %}">{% url Blog-feed feed.filename %}</a> 47 {% endif %} 48 <small>( 49 {% if feed.filename == "feed.rss" %} 50 <a href="{% trans "http://en.wikipedia.org/wiki/RSS" %}">Really Simple Syndication</a> v2.01rev2 51 {% endif %} 52 {% if feed.filename == "feed.atom" %} 53 <a href="{% trans "http://en.wikipedia.org/wiki/Atom_(standard)" %}">Atom Syndication Format</a> v1.0 54 {% endif %} 55 ) 56 </small> 57 </li> 58 {% endfor %} 59 </lu> 60 </fieldset> 36 61 37 62 <div class="pagination"> -
branches/0.9/pylucid_project/pylucid_plugins/blog/urls.py
r2417 r2538 3 3 from django.conf.urls.defaults import patterns, url 4 4 5 from blog.views import summary, tag_view, detail_view 5 from blog.views import summary, tag_view, detail_view, feed, select_feed 6 6 7 7 urlpatterns = patterns('', 8 url(r'^/tags/(?P<tag >.*?)/$', tag_view, name='Blog-tag_view'),8 url(r'^/tags/(?P<tags>.+?)/$', tag_view, name='Blog-tag_view'), 9 9 url(r'^/(?P<id>\d+?)/(?P<title>.*)/$', detail_view, name='Blog-detail_view'), 10 11 url(r'^/feed/(?P<tags>.+)/(?P<filename>.+?)$', feed, name='Blog-tag_feed'), 12 url(r'^/feed/(?P<filename>.+?)$', feed, name='Blog-feed'), 13 url(r'^/feed/', select_feed, name='Blog-select_feed'), 14 10 15 url(r'^', summary, name='Blog-summary'), 11 16 ) -
branches/0.9/pylucid_project/pylucid_plugins/blog/views.py
r2527 r2538 27 27 28 28 from django.conf import settings 29 from django.contrib.syndication.views import Feed 29 30 from django.utils.translation import ugettext as _ 30 31 from django.views.decorators.csrf import csrf_protect 31 32 from django.contrib.comments.views.comments import post_comment 33 from django.utils.feedgenerator import Rss201rev2Feed, Atom1Feed 32 34 33 35 from pylucid_project.apps.pylucid.decorators import render_to 36 from pylucid_project.utils.safe_obtain import safe_pref_get_integer 34 37 35 38 from pylucid_project.pylucid_plugins.blog.models import BlogEntry 39 from pylucid_project.pylucid_plugins.blog.preference_forms import BlogPrefForm 36 40 37 41 # from django-tagging … … 48 52 49 53 54 def _get_queryset(request, tags=None): 55 # Get all blog entries, that the current user can see 56 queryset = BlogEntry.objects.all_accessible(request) 57 58 if tags is not None: 59 # filter by tags 60 queryset = TaggedItem.objects.get_by_model(queryset, tags) 61 62 return queryset 63 64 65 def _split_tags(raw_tags): 66 "simple split tags from url" 67 tags = raw_tags.strip("/").split("/") 68 return tags 69 70 71 class RssFeed(Feed): 72 feed_type = Rss201rev2Feed 73 filename = "feed.rss" 74 title = _("Blog - RSS feed") 75 link = "/" 76 description_template = "blog/feed_description.html" 77 78 def __init__(self, request, tags=None): 79 self.request = request 80 81 if tags is not None: 82 tags = _split_tags(tags) 83 self.tags = tags 84 85 # Get max number of feed entries from request.GET["count"] 86 # Validate/Limit it with information from DBPreferences 87 self.count, error = safe_pref_get_integer( 88 request, "count", BlogPrefForm, 89 default_key="initial_feed_count", default_fallback=5, 90 min_key="initial_feed_count", min_fallback=5, 91 max_key="max_feed_count", max_fallback=30 92 ) 93 94 def description(self): 95 if self.tags is None: 96 return _("Last %s blog articles") % self.count 97 else: 98 return _( 99 "Last %(count)s blog articles tagged with: %(tags)s" 100 ) % {"count":self.count, "tags": ",".join(self.tags)} 101 102 def items(self): 103 queryset = _get_queryset(self.request, self.tags) 104 return queryset[:self.count] 105 106 def item_title(self, item): 107 return item.headline 108 109 def item_author_name(self, item): 110 return item.createby 111 112 def item_link(self, item): 113 return item.get_absolute_url() 114 115 116 class AtomFeed(RssFeed): 117 """ 118 http://docs.djangoproject.com/en/dev/ref/contrib/syndication/#publishing-atom-and-rss-feeds-in-tandem 119 """ 120 feed_type = Atom1Feed 121 filename = "feed.atom" 122 title = _("Blog - Atom feed") 123 subtitle = RssFeed.description 124 125 126 # The last class is the fallback class, if filename doesn't match 127 FEEDS = [AtomFeed, RssFeed] 128 129 130 50 131 @render_to("blog/summary.html") 51 132 def summary(request): … … 54 135 """ 55 136 # Get all blog entries, that the current user can see 56 queryset = BlogEntry.objects.all_accessible(request)137 queryset = _get_queryset(request) 57 138 58 139 # Limit the queryset with django Paginator … … 65 146 "tag_cloud": tag_cloud, 66 147 "CSS_PLUGIN_CLASS_NAME": settings.PYLUCID.CSS_PLUGIN_CLASS_NAME, 148 "feeds": FEEDS, 67 149 } 68 150 return context … … 70 152 71 153 @render_to("blog/summary.html") 72 def tag_view(request, tag): 73 """ 74 Display summary list with blog entries filtered by the giben tag. 75 """ 76 tags = tag.strip("/").split("/") 77 78 # Get all blog entries, that the current user can see 79 queryset = BlogEntry.objects.all_accessible(request) 80 81 queryset = TaggedItem.objects.get_by_model(queryset, tags) 154 def tag_view(request, tags): 155 """ 156 Display summary list with blog entries filtered by the given tags. 157 """ 158 tags = _split_tags(tags) 159 160 # Get all blog entries, that the current user can see 161 queryset = _get_queryset(request, tags) 82 162 83 163 # Limit the queryset with django Paginator … … 85 165 86 166 # Add link to the breadcrumbs ;) 87 _add_breadcrumb(request, title=_("All '%s' tagged items" % ",".join(tags)), url=request.path)167 _add_breadcrumb(request, title=_("All items tagged with: %s" % ", ".join(tags)), url=request.path) 88 168 89 169 tag_cloud = BlogEntry.objects.get_tag_cloud(request) … … 92 172 "entries": paginator, 93 173 "tag_cloud": tag_cloud, 174 "add_tag_filter_link": True, # Add + tag filter link 94 175 "CSS_PLUGIN_CLASS_NAME": settings.PYLUCID.CSS_PLUGIN_CLASS_NAME, 176 "used_tags": tags, 177 "tags": "/".join(tags), 178 "feeds": FEEDS, 95 179 } 96 180 return context … … 104 188 """ 105 189 # Get all blog entries, that the current user can see 106 queryset = BlogEntry.objects.all_accessible(request)190 queryset = _get_queryset(request) 107 191 108 192 try: … … 133 217 return context 134 218 219 #------------------------------------------------------------------------------ 220 221 222 @render_to("blog/select_feed.html") 223 def select_feed(request): 224 """ Display a list with existing feed filenames. """ 225 context = {"feeds": FEEDS} 226 return context 227 228 229 def feed(request, filename, tags=None): 230 """ 231 return RSS/Atom feed for all blog entries and filtered by tags. 232 Feed format is selected by filename. 233 """ 234 for feed_class in FEEDS: 235 if filename == feed_class.filename: 236 break 237 238 feed = feed_class(request, tags) 239 response = feed(request) 240 return response 241 -
branches/0.9/pylucid_project/pylucid_plugins/update_journal/views.py
r2536 r2538 27 27 from django.core.urlresolvers import NoReverseMatch 28 28 29 from pylucid_project.apps.pylucid.models import Language30 29 from pylucid_project.apps.pylucid.decorators import render_to 30 from pylucid_project.utils.safe_obtain import safe_pref_get_integer 31 from pylucid_project.apps.pylucid.models import Language, PluginPage 31 32 32 33 from pylucid_project.pylucid_plugins.update_journal.models import UpdateJournal 33 from pylucid_project.apps.pylucid.models import PluginPage 34 from pylucid_project.pylucid_plugins.update_journal.preference_forms import UpdateJournalPrefForm 35 34 36 35 37 def _get_queryset(request, count): … … 76 78 filename = "feed.rss" 77 79 78 title = "Update Journal"80 title = _("Update Journal - RSS feed") 79 81 link = "/" 80 description = "Updates and changes"81 82 description_template = "update_journal/feed_description.html" 82 83 83 84 def __init__(self, request): 84 self.count = 10 # FIXME: use GET parameter?85 85 self.request = request 86 87 # Get max number of feed entries from request.GET["count"] 88 # Validate/Limit it with information from DBPreferences 89 self.count, error = safe_pref_get_integer( 90 request, "count", UpdateJournalPrefForm, 91 default_key="initial_feed_count", default_fallback=5, 92 min_key="initial_feed_count", min_fallback=5, 93 max_key="max_feed_count", max_fallback=30 94 ) 95 96 def description(self): 97 return _("Last %s updates and changes") % self.count 86 98 87 99 def items(self): … … 101 113 feed_type = Atom1Feed 102 114 filename = "feed.atom" 115 title = _("Update Journal - Atom feed") 103 116 subtitle = RssFeed.description 104 117