Django Aware

« | Home | »

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:

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.

blog_icon.py


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.

item.html

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 %}

{{ b.description }}

{{ b.title }}

{% 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:


Screenshot of the code above.  Sorry not very useful as an image, live example at PeerIt.
Live example at PeerIt.


Topics: Code Snippets, Peer It, Template Tags | Comments

  • Not sure how I got here but interesting read...just started using Digg myself!
  • rich2nit
    thanks,
  • Digg one of the most favourite my sites.
    There it is possible to find interesting articles always.
    Sometimes I and itself send there articles.
  • Great stuff. I must say I only recently started paying attention to tags and they do work a treat if used correctly.
  • Canvas art blog that critiques a new piece of artwork each day including traditional, abstract, large, famous, modern, and canvas wall art.
  • Social Networking Website Designer. Social Networking Website Design Services. Social Network Design.
  • The developers and designers at Jupiter labs will not only help your business keep pace with change but we do it with flair.
  • I have a number of blog entries on my seo blog that contain the ability to submit to all the different social networking sites. Does your tool allow to submit a compilation of all post to all of these site? I'm trying to figure out a way to submit all articles to all social sites like this without having to do each one individually.. Thanks for any advice.
blog comments powered by Disqus