Login

Snippets by arthurfurlan

Snippet List

Signal to notify new saved comments

Signal to notify new saved comments. **Example:** from django.contrib.comment import models, signals signals.comment_was_posted.connect(new_comment_notifier, sender=models.Comment)

  • django
  • python
  • comments
  • signals
Read More

Template tag "ifregex" and "ifnotregex"

Outputs the contents of the block if the second argument matches (or not, depending on the tag) the regular expression represented by the first argument. Usage: {% ifregex "^/comments/" request.path %} ... {% endifregex %} {% ifnotregex "^/comments/" request.path %} ... {% else %} ... {% endifnotregex %}

  • template
  • templatetag
  • regex
  • ifregex
Read More

Default to a static template.

Default to a static template. **Example:** urlpatterns = patterns('', ... # this rule SHOULD BE the last one (r'^(?P<template>[a-z-_/]+/?)?$', 'myproj.apps.myapp.views.static_template'), )

  • template
  • static
  • default
Read More

Get the referer view of a request

Get the referer view of a request. **Example:** def some_view(request): ... referer_view = get_referer_view(request) return HttpResponseRedirect(referer_view, '/accounts/login/')

  • view
  • referer
  • request
  • path
Read More

Signal to post new saved objects to Twitter

Post new saved objects to Twitter. **Example:** from django.db import models class MyModel(models.Model): text = models.CharField(max_length=255) link = models.CharField(max_length=255) def __unicode__(self): return u'%s' % self.text def get_absolute_url(self): return self.link # the following method is optional def get_twitter_message(self): return u'my-custom-twitter-message: %s - %s' % (self.text, self.link) models.signals.post_save.connect(post_to_twitter, sender=MyModel)

  • twitter
  • signal
Read More

arthurfurlan has posted 5 snippets.