« Implementing CNN Style Votes In Django, Episode II | Home | Scraping Amazon Items Using Django Mash-Up »
Digg Technorati Delicious Blink List Furl Reddit Blog Submission Tag
By Paul Kenjora | April 26, 2007
Submitting your pages to popular blog sites like, Digg, Technorati, Delicious, Blink List, Furl, and Reddit is almost a standard feature on all sites today. In response I present a quick Django template tag that easily allows you to insert the submission links for each blog. The links are pre-formatted to match the API of each site. All you provide is:
- Item title – The article name you would like to appear on Digg for example.
- Item category – The category needs to match what each site provides, Digg is most picky. Leave this blank if not sure.
- Item url – The site relative url of your page. The tag uses the Site database table to assemble the full URL.
- Image url – The full url to the image associated with each blog site. Don’t hijack images, copy to your site then use.
We use this code on several of our sites, for an example see PeerIt. Every item on the site has a this feature embedded in the lower right hand side of the page.
Tag
The tag code contains no ouside dependencies. It is assembles a list of blog site submission urls based on the parameters described above. If you would like to customize the list only modify the "icons.append(…)" list. This should be a copy and paste.
import urllib
from django import template
from django.template import Library, Node
from django.contrib.sites.models import Site
register = template.Library()
class Icon_Struct:
def __init__(self, title, link, image):
self.title = title
self.link = link
self.image = image
self.description = 'Submit this page to ' + title
class BlogContentNode(Node):
def __init__(self, url, title, description, category, varname):
self.url_var, self.title_var, self.description_var, self.category_var, self.varname = url, title, description, category, varname
def render(self, context):
self.url = urllib.quote_plus('http://' + Site.objects.get_current().domain + str(template.resolve_variable(self.url_var, context)))
self.title = urllib.quote_plus(str(template.resolve_variable(self.title_var, context)))
self.description = urllib.quote_plus(str(template.resolve_variable(self.description_var, context)))
self.category = urllib.quote_plus(str(template.resolve_variable(self.category_var, context)))
icons = []
icons.append(Icon_Struct('Delicious', 'http://del.icio.us/post?url=' + self.url + '&title=' + self.title, 'http://www.exploding-boy.com/images/logos/delicious.gif'))
icons.append(Icon_Struct('Digg', 'http://digg.com/submit?phase=2&URL=' + self.url + '&title=' + self.title + '&bodytext=' + self.description + '&topic=' + self.category, 'http://www.exploding-boy.com/images/logos/digg.gif'))
icons.append(Icon_Struct('Technorati', 'http://technorati.com/cosmos/search.html?url=' + self.url, 'http://www.exploding-boy.com/images/logos/technorati.gif'))
icons.append(Icon_Struct('Blink List', 'http://blinklist.com/index.php?Action=Blink/addblink.php&URL=' + self.url + '&Title=' + self.title, 'http://www.exploding-boy.com/images/logos/blinklist.gif'))
icons.append(Icon_Struct('Furl', 'http://furl.net/storeIt.jsp?t=' + self.title + '&u=' + self.url, 'http://www.exploding-boy.com/images/logos/furl.gif'))
icons.append(Icon_Struct('Reddit', 'http://reddit.com/submit?url=' + self.url + '&title=' + self.title, 'http://www.exploding-boy.com/images/logos/reddit.gif'))
context[self.varname] = icons;
return ''
def blog_icon(parser, token):
bits = token.contents.split()
if len(bits) != 7:
raise TemplateSyntaxError, "blog_icon tag takes exactly six arguments"
if bits[5] != 'as':
raise TemplateSyntaxError, "fourth argument to blog_icon tag must be 'as'"
return BlogContentNode(bits[1], bits[2], bits[3], bits[4], bits[6])
register.tag('blog_icon', blog_icon)
Template
Using the tag is relatively quick. Just load the tag, pass it the item/page details, and loop through list of results. You have the ability to modify your tags completely.
Submit To Blog
{% load blog_icon %}
{% blog_icon item.get_absolute_url item.title item.description item.get_category_name as blogs %}
{% for b in blogs %}
{% endfor %}
Example
The code above has been implemented on www.peerit.com. Navigate to any item and you should see the tags on the right side of the page. We stylized our tags with a style sheet to look like the following:
|
|
| Live example at PeerIt. |
More from Aware Labs
- Implementing CNN Style Votes In Django, Episode II
- Auto Adjusting Pagination As A Template Tag Plus Include
- Digg For Django Is Here
- Simple Character Truncate Filter And Dot Dot Dot Variant
- Digg Re-Written In Django With A Twist
Aware Labs Recommends
- An Interview with Jacob Kaplan-Moss – Creator of Django (USwaretech)
- Five Things I Hate About Django. (USwaretech)
- An interview with Michael Trier (USwaretech)
Topics: Code Snippets, Peer It, Template Tags | Comments
-
Canvas Art
-
rich2nit
-
emo boys
-
ilia seo
-
Canvas
-
Jonathan Mac
-
Marc
-
Troy Perkins