All pastes #211811 Raw Edit

Anonymous

public text v1 · immutable
#211811 ·published 2006-10-20 14:27 UTC
rendered paste body
def update_favorites(sender, instance, signal, *args, **kwargs):
	print "favorites signal received for %s" % str(instance)

	if instance.__class__.__name__ is 'ChangeLog' or not hasattr(instance, 'History'): 
		return 0

	if ((kwargs['signal_name'] is 'post_save') and instance.id):
		try:
			ContentTypeManager().get_for_model(instance.__class__)
			cursor = connection.cursor()
			cursor.execute("UPDATE `favorites_favorite` SET `last_update` = NOW() WHERE `content_type_id` = '%d' AND `object_id` = '%d'" % (content_type.id, instance.id))
			print "Updated favorites for %s" % instance.__class__.__name__
		except:
			return 1

dispatcher.connect(update_favorites, signal=signals.post_save)