Permalink
Browse files

added biblion_extras for featured post functionality and re-factored …

…out AsNode
  • Loading branch information...
1 parent 9abdcd2 commit 5c15d84ee62f522e9b8ecee92e6ddcfca82c1a2c @brosner brosner committed Jan 24, 2010
@@ -0,0 +1,7 @@
+from django.contrib import admin
+
+from biblion_extras.models import FeaturedPost
+
+
+
+admin.site.register(FeaturedPost)
@@ -0,0 +1,15 @@
+from datetime import datetime
+
+from django.db import models
+
+from biblion.models import Post
+
+
+
+class FeaturedPost(models.Model):
+
+ post = models.ForeignKey(Post)
+ timestamp = models.DateTimeField(default=datetime.now)
+
+ class Meta:
+ ordering = ["-timestamp"]
@@ -0,0 +1,21 @@
+from django import template
+
+from biblion_extras.models import FeaturedPost
+
+from pinaxsite_project.utils import AsNode
+
+
+
+register = template.Library()
+
+
+
+class FeaturedBlogPostNode(AsNode):
+
+ def render(self, context):
+ try:
+ post = FeaturedBlogPost.objects.all()[0]
+ except IndexError:
+ post = None
+ context[self.context_var] = post
+ return u""
@@ -2,29 +2,15 @@
from downloads.models import Release
+from pinaxsite_project.utils import AsNode
-register = template.Library()
-
+register = template.Library()
-class BaseReleaseNode(template.Node):
-
- @classmethod
- def handle_token(cls, parser, token, **kwargs):
- bits = token.split_contents()
-
- if len(bits) != 3:
- raise template.TemplateSyntaxError("%r takes exactly two arguments "
- "(first argument must be 'as')" % bits[0])
- if bits[1] != "as":
- raise template.TemplateSyntaxError("Second argument to %r must be "
- "'as'" % bits[0])
-
- return cls(bits[2], **kwargs)
-class LatestReleaseNode(BaseReleaseNode):
+class LatestReleaseNode(AsNode):
def __init__(self, context_var, kind):
self.context_var = context_var
@@ -42,10 +28,7 @@ def render(self, context):
return u""
-class OlderReleasesNode(BaseReleaseNode):
-
- def __init__(self, context_var):
- self.context_var = context_var
+class OlderReleasesNode(AsNode):
def render(self, context):
@@ -141,6 +141,7 @@
"downloads",
"example_sites",
"quotes",
+ "biblion_extras",
]
MESSAGE_STORAGE = "django.contrib.messages.storage.session.SessionStorage"
@@ -0,0 +1,21 @@
+from django import template
+
+
+
+class AsNode(template.Node):
+
+ @classmethod
+ def handle_token(cls, parser, token, **kwargs):
+ bits = token.split_contents()
+
+ if len(bits) != 3:
+ raise template.TemplateSyntaxError("%r takes exactly two arguments "
+ "(first argument must be 'as')" % bits[0])
+ if bits[1] != "as":
+ raise template.TemplateSyntaxError("Second argument to %r must be "
+ "'as'" % bits[0])
+
+ return cls(bits[2], **kwargs)
+
+ def __init__(self, context_var):
+ self.context_var = context_var

0 comments on commit 5c15d84

Please sign in to comment.