Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

added biblion_extras for featured post functionality and re-factored …

…out AsNode
  • Loading branch information...
commit 5c15d84ee62f522e9b8ecee92e6ddcfca82c1a2c 1 parent 9abdcd2
@brosner brosner authored
View
0  pinaxsite_project/apps/biblion_extras/__init__.py
No changes.
View
7 pinaxsite_project/apps/biblion_extras/admin.py
@@ -0,0 +1,7 @@
+from django.contrib import admin
+
+from biblion_extras.models import FeaturedPost
+
+
+
+admin.site.register(FeaturedPost)
View
15 pinaxsite_project/apps/biblion_extras/models.py
@@ -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"]
View
0  pinaxsite_project/apps/biblion_extras/templatetags/__init__.py
No changes.
View
21 pinaxsite_project/apps/biblion_extras/templatetags/biblion_extras_tags.py
@@ -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""
View
25 pinaxsite_project/apps/downloads/templatetags/downloads_tags.py
@@ -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):
View
1  pinaxsite_project/settings.py
@@ -141,6 +141,7 @@
"downloads",
"example_sites",
"quotes",
+ "biblion_extras",
]
MESSAGE_STORAGE = "django.contrib.messages.storage.session.SessionStorage"
View
21 pinaxsite_project/utils.py
@@ -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
Please sign in to comment.
Something went wrong with that request. Please try again.