def test_postcommit_middleware(self): from film20.core.signals import post_commit from film20.core.models import User post_commit.connect(on_postcommit, sender=User) global postcommit_cnt postcommit_cnt = 0 # object saved inside view response = self.client.get('/test/postcommit/') self.assertEquals(response.status_code, 200) self.assertEquals(postcommit_cnt, 1) # object saved outside of view, postcommit signal should be sent instantly User.objects.create(username='******') self.assertEquals(postcommit_cnt, 2)
'user': assoc.user, 'fb_user': assoc.fb_user, 'network': 'Facebook', 'profile_url': abs_reverse('show_profile', args=[assoc.user.username]), }) for friend in friends: assoc.user.followers.follow(friend) @classmethod def post_commit(cls, sender, instance, created, *args, **kw): if created: from film20.core.deferred import defer defer(instance._sync_with_fb, instance.id) from film20.core.signals import post_commit post_commit.connect(FBAssociation.post_commit, sender=FBAssociation, dispatch_uid=FBAssociation.post_commit) from django.contrib.contenttypes import generic from django.contrib.contenttypes.models import ContentType import json import urllib2 from urllib import urlencode class LikeCounter(models.Model): likes = models.IntegerField(null=True, blank=True) shares = models.IntegerField(null=True, blank=True) like_count = models.IntegerField(default=0, null=True, blank=True) share_count = models.IntegerField(default=0, null=True, blank=True) comment_count = models.IntegerField(default=0, null=True, blank=True)
'profile_url': abs_reverse('show_profile', args=[assoc.user.username]), }) for friend in friends: assoc.user.followers.follow(friend) @classmethod def post_commit(cls, sender, instance, created, *args, **kw): if created: from film20.core.deferred import defer defer(instance._sync_with_fb, instance.id) from film20.core.signals import post_commit post_commit.connect(FBAssociation.post_commit, sender=FBAssociation, dispatch_uid=FBAssociation.post_commit) from django.contrib.contenttypes import generic from django.contrib.contenttypes.models import ContentType import json import urllib2 from urllib import urlencode class LikeCounter(models.Model): likes = models.IntegerField(null=True, blank=True) shares = models.IntegerField(null=True, blank=True) like_count = models.IntegerField(default=0, null=True, blank=True)