Login

Delicious Tag

Author:
alcides
Posted:
June 23, 2008
Language:
Python
Version:
.96
Score:
-5 (after 5 ratings)

Just add it in templatetags/delicious.py

In your template:

<h3>Del.icio.us</h3>

<ul class="list"> {% load delicious %} {% load_delicious_links %} {% for link in delicious_links %} <li><a href="{{link.link}}">{{link.title|safe}}</a></li> {% endfor %} </ul>

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
from django.template import Library,Node

register = Library()

def load_delicious_links(parser, token):
    """
    {% get_user_profile %}
    """
    return DeliciousObject()

class DeliciousObject(Node):
    def render(self, context):
		
		try:
			import feedparser
			d = feedparser.parse('http://del.icio.us/rss/alcidesfonseca')
			delicious=[]
			for entry in d['entries'][:min(8,len(d['entries']))]:
				title=str(entry['title'].encode('ascii', 'xmlcharrefreplace'))
				delicious.append({'title':title,'link':str(entry['links'][0]['href'])})
		except:
			delicious=[]
	
		context['delicious_links'] = delicious
		return ""

register.tag('load_delicious_links', load_delicious_links)

More like this

  1. Template tag - list punctuation for a list of items by shapiromatron 11 months, 2 weeks ago
  2. JSONRequestMiddleware adds a .json() method to your HttpRequests by cdcarter 11 months, 3 weeks ago
  3. Serializer factory with Django Rest Framework by julio 1 year, 6 months ago
  4. Image compression before saving the new model / work with JPG, PNG by Schleidens 1 year, 7 months ago
  5. Help text hyperlinks by sa2812 1 year, 7 months ago

Comments

Please login first before commenting.