[Projeler-commits] r378 - in zangetsu: blog blog/templatetags templates/blog

projeler-commits at pardus.org.tr projeler-commits at pardus.org.tr
27 Nis 2007 Cum 21:16:13 EEST


Author: meren
Date: Fri Apr 27 21:16:13 2007
New Revision: 378

Modified:
   zangetsu/blog/templatetags/library.py
   zangetsu/blog/urls.py
   zangetsu/blog/views.py
   zangetsu/templates/blog/recent_comments.html
Log:

 son yorumlar sayfasını da paginator'dan geçirelim..

 boşa gitti templat'e tag ekleyeceğiz diye attığımız taklalar..



Modified: zangetsu/blog/templatetags/library.py
=================================================================
--- zangetsu/blog/templatetags/library.py	(original)
+++ zangetsu/blog/templatetags/library.py	Fri Apr 27 21:16:13 2007
@@ -6,7 +6,6 @@
 from django.template import Library,Node
 from zangetsu.blog import defaults
 from zangetsu.blog.models import Entry, Tag, Link
-from django.db.models import get_apps
 from zangetsu.settings import WEB_URL
 
 register = Library()
@@ -47,19 +46,6 @@
         context["blog_tags"] = Tag.objects.all()
         return ""
 
-class LatestContentNode(Node):
-    def __init__(self, model, num, varname):
-        self.num, self.varname = num, varname
-        for m in get_apps():
-            if m.__str__().find(model.split(".")[0]) > 0:
-                self.model = m
-        self.func = model.split(".")[1]
-
-    def render(self, context):
-        func = self.model.__getattribute__(self.func)
-        context[self.varname] = func._default_manager.all()[:self.num]
-        return ""
-
 def build_blog_name(parser, token):
     return BlogNameObject()
 
@@ -72,16 +58,7 @@
 def build_tag_list(parser, token):
     return TagMenuObject()
 
-def build_latest_comments(parser, token):
-    bits = token.contents.split()
-    if len(bits) != 5:
-        raise TemplateSyntaxError, "get_latest tag takes exactly four arguments"
-    if bits[3] != "as":
-        raise TemplateSyntaxError, "third argument to get_latest tag must be 'as'"
-    return LatestContentNode(bits[1], bits[2], bits[4])
-
 register.tag("build_blog_name", build_blog_name)
 register.tag("build_link_list", build_link_list)
 register.tag("build_month_list", build_month_list)
 register.tag("build_tag_list", build_tag_list)
-register.tag("build_latest_comments", build_latest_comments)

Modified: zangetsu/blog/urls.py
=================================================================
--- zangetsu/blog/urls.py	(original)
+++ zangetsu/blog/urls.py	Fri Apr 27 21:16:13 2007
@@ -23,6 +23,8 @@
 
     (r"^comments/$", "zangetsu.blog.views.recent_comments"),
 
+    (r"^comments/page/(?P<page>\d+)/$", "zangetsu.blog.views.recent_comments"),
+
     (r"^tag/(?P<slug>.*)/page/(?P<page>\d+)/$", "zangetsu.blog.views.tags"),
 
     (r"^tag/(?P<slug>.*)/$", "zangetsu.blog.views.tags"),

Modified: zangetsu/blog/views.py
=================================================================
--- zangetsu/blog/views.py	(original)
+++ zangetsu/blog/views.py	Fri Apr 27 21:16:13 2007
@@ -5,6 +5,7 @@
 # See the file http://www.gnu.org/copyleft/gpl.txt.
 
 from django.shortcuts import render_to_response
+from django.db.models import get_apps
 from zangetsu.blog.models import Entry, Tag
 from django.core.paginator import ObjectPaginator, InvalidPage
 
@@ -52,6 +53,13 @@
     response_dict.update(paginator_dict)
     return render_to_response("blog/tag_detail.html", response_dict)
 
-def recent_comments(request):
-    return render_to_response("blog/recent_comments.html")
-
+def recent_comments(request, page = 0):
+    for any_app in get_apps():
+        if any_app.__str__().find("comments") != -1:
+            app = any_app
+            break
+    recent_comments = app.FreeComment.objects.all()
+    paginator_dict = build_paginator_dict(recent_comments, int(page), 20)
+    response_dict = {'url_tip': '/comments/page/'}
+    response_dict.update(paginator_dict)
+    return render_to_response("blog/recent_comments.html", response_dict)

Modified: zangetsu/templates/blog/recent_comments.html
=================================================================
--- zangetsu/templates/blog/recent_comments.html	(original)
+++ zangetsu/templates/blog/recent_comments.html	Fri Apr 27 21:16:13 2007
@@ -1,18 +1,27 @@
 {% load library %}
 {% load i18n %}
-{% build_latest_comments comments.FreeComment 20 as recent_comments %}
 {% extends "base.html" %}
 {% block content %}
-    {% for comment in recent_comments %}
-        {% if comment.approved %}
-            {% if comment.is_public %}
-                <div class="comment_{% cycle odd,even %}" id="c{{ comment.id }}">
-                    <b>{{ comment.person_name }}</b> - <a href="{{comment.get_content_object.get_absolute_url}}">{{comment.get_content_object.title}}</a> {%trans "commented"%}
-                    <span class="date">{{ comment.submit_date|date:"d F y, l" }} @ {{ comment.submit_date|date:"H:i" }}</span>
-                    <br />
-                    {{ comment.comment|escape|urlizetrunc:40|linebreaks }}
-                </div>
-            {% endif %}
+
+{% if paginator %}
+    {% include "blog/paginator-top.html" %}
+{% endif %}
+
+{% for comment in results %}
+    {% if comment.approved %}
+        {% if comment.is_public %}
+            <div class="comment_{% cycle odd,even %}" id="c{{ comment.id }}">
+                <b>{{ comment.person_name }}</b> - <a href="{{comment.get_content_object.get_absolute_url}}">{{comment.get_content_object.title}}</a> {%trans "commented"%}
+                <span class="date">{{ comment.submit_date|date:"d F y, l" }} @ {{ comment.submit_date|date:"H:i" }}</span>
+                <br />
+                {{ comment.comment|escape|urlizetrunc:40|linebreaks }}
+            </div>
         {% endif %}
-    {% endfor %}
+    {% endif %}
+{% endfor %}
+
+{% if paginator %}
+    {% include "blog/paginator-bottom.html" %}
+{% endif %}
+
 {% endblock %}


Projeler-commits mesaj listesiyle ilgili daha fazla bilgi