def model_post_save_callback(sender, instance, created, raw, using, update_fields, **kwargs): clearcache = False if isinstance(instance, LogEntry): return if 'get_full_url' in dir(instance): is_update_views = update_fields == {'views'} if not settings.TESTING and not is_update_views: try: notify_url = instance.get_full_url() SpiderNotify.baidu_notify([notify_url]) except Exception as ex: logger.error("notify sipder", ex) if not is_update_views: clearcache = True if isinstance(instance, Comment): path = instance.article.get_absolute_url() site = Site.objects.get_current().domain if site.find(':') > 0: site = site[0:site.find(':')] expire_view_cache(path, servername=site, serverport=80, key_prefix='blogdetail') if cache.get('seo_processor'): cache.delete('seo_processor') comment_cache_key = 'article_comments_{id}'.format(id=instance.article.id) cache.delete(comment_cache_key) delete_view_cache(instance.author.username) _thread.start_new(send_comment_email, (instance,)) if clearcache: cache.clear()
def model_post_save_callback(sender, instance, created, raw, using, update_fields, **kwargs): clearcache = False if isinstance(instance, LogEntry): return if 'get_full_url' in dir(instance): is_update_views = update_fields == {'views'} if not is_update_views: clearcache = True if isinstance(instance, Comment): path = instance.article.get_absolute_url() site = get_current_site().domain if site.find(':') > 0: site = site[0:site.find(':')] expire_view_cache(path, servername=site, serverport=80, key_prefix='blogdetail') if cache.get('seo_processor'): cache.delete('seo_processor') comment_cache_key = 'article_comments_{id}'.format( id=instance.article.id) cache.delete(comment_cache_key) delete_sidebar_cache(instance.author.username) delete_view_cache('article_comments', [str(instance.article.pk)]) _thread.start_new(send_comment_email, (instance, )) if clearcache: cache.clear()
def oauth_user_login_signal_handler(sender, **kwargs): id = kwargs['id'] oauthuser = OAuthUser.objects.get(id=id) site = Site.objects.get_current().domain if oauthuser.picture and not oauthuser.picture.find(site) >= 0: from DjangoBlog.utils import save_user_avatar oauthuser.picture = save_user_avatar(oauthuser.picture) oauthuser.save() delete_view_cache(oauthuser.author.username) cache.clear()
def user_auth_callback(sender, request, user, **kwargs): if user and user.username: logger.info(user) delete_view_cache(user.username) cache.clear()