Login

Snippets by svetlyak

Snippet List

Remove self links middleware

This simple middleware replaces all 'a href' links to the current page to the 'span' elements. This very usefule from the usability point of view. For example, user open in bowser page http://svetlyak.ru/blog/, and this middleware will replace all 'a' elements on this page, which refer to the '/blog/'. Because of this, link 'Blog' in the main menu, become a simple 'span'. Next, when user goes to the next page, a post with full comments list ('/blog/123/'), for example, the item 'Blog' in the main menu become a link again! To use this middleware, just add it to the list of middleware classes: MIDDLEWARE_CLASSES = ('utils.middleware.RemoveSelfLinks',)

  • middleware
  • html
  • output
  • usability
  • utils
Read More

True links in the admin list

Usually, you can add links in the admin using such code: class Pingback(models.Model): #... target_uri = models.URLField( _('Target URI')) #... def admin_target(self): return '<a href="%(targ)s">%(targ)s</a>' % {'targ': self.target_uri} admin_target.short_description = _('Target URI') admin_target.allow_tags = True #... class Admin: list_display = ('id', 'admin_target') But when you have two or more url fields, such approach becomes to expensive. Follow the DRY principe and use my code in such way: # Just add this line instead of the ugly four lines **def blabla** admin_target = link('target_uri', _('Target URI'))

  • admin
Read More

nofollow filter

This filter add extra attribute **rel="nofollow"** to any "<a ..." element in the value, which does not contain it already. I use this to filter comments text in my blog.

  • filter
Read More

svetlyak has posted 3 snippets.