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 save(self, *args, **kwargs): if not self.slug or self.slug == 'no-slug' or not self.id: # Only set the slug when the object is created. slug = self.title if 'title' in self.__dict__ else self.name self.slug = slugify(slug) super().save(*args, **kwargs) if 'update_fields' in kwargs and len( kwargs['update_fields'] ) == 1 and kwargs['update_fields'][0] == 'views': return try: if not settings.TESTING: notify_url = self.get_full_url() SpiderNotify.baidu_notify([notify_url]) except Exception as ex: logger.error("notify sipder", ex) print(ex)
def test_validate_article(self): site = Site.objects.get_current().domain user = BlogUser.objects.get_or_create(email="*****@*****.**", username="******")[0] user.set_password("liangliangyy") user.save() response = self.client.get(user.get_absolute_url()) self.assertEqual(response.status_code, 200) category = Category() category.name = "category" category.created_time = datetime.datetime.now() category.last_mod_time = datetime.datetime.now() category.save() tag = Tag() tag.name = "nicetag" tag.save() article = Article() article.title = "nicetitle" article.body = "nicecontent" article.author = user article.category = category article.type = 'a' article.status = 'p' article.save() self.assertEqual(0, article.tags.count()) article.tags.add(tag) article.save() self.assertEqual(1, article.tags.count()) response = self.client.get(article.get_absolute_url()) self.assertEqual(response.status_code, 200) response = self.client.get(tag.get_absolute_url()) self.assertEqual(response.status_code, 200) response = self.client.get(category.get_absolute_url()) self.assertEqual(response.status_code, 200) from DjangoBlog.spider_notify import SpiderNotify SpiderNotify.baidu_notify([article.get_full_url()])
def handle(self, *args, **options): type = options['data_type'] self.stdout.write('start get %s' % type) urls = [] if type == 'article' or type == 'all': for article in Article.objects.filter(status='p'): urls.append(article.get_full_url()) if type == 'tag' or type == 'all': for tag in Tag.objects.all(): url = tag.get_absolute_url() urls.append(self.get_full_url(url)) if type == 'category' or type == 'all': for category in Category.objects.all(): url = category.get_absolute_url() urls.append(self.get_full_url(url)) self.stdout.write(self.style.SUCCESS('start notify %d urls' % len(urls))) SpiderNotify.baidu_notify(urls) self.stdout.write(self.style.SUCCESS('finish notify'))
def article_save_callback(sender, **kwargs): id = kwargs['id'] is_update_views = kwargs['is_update_views'] type = sender.__name__ obj = None from blog.models import Article, Category, Tag if type == 'Article': obj = Article.objects.get(id=id) elif type == 'Category': obj = Category.objects.get(id=id) elif type == 'Tag': obj = Tag.objects.get(id=id) if obj is not None: # if not settings.TESTING and not is_update_views: # 超哥修改 取消test测试 try: notify_url = obj.get_full_url() SpiderNotify.baidu_notify([notify_url]) except Exception as ex: logger.error("notify sipder", ex) print(ex)
def article_save_callback(sender, **kwargs): id = kwargs['id'] is_update_views = kwargs['is_update_views'] type = sender.__name__ obj = None from blog.models import Article, Category, Tag if type == 'Article': obj = Article.objects.get(id=id) elif type == 'Category': obj = Category.objects.get(id=id) elif type == 'Tag': obj = Tag.objects.get(id=id) if obj is not None: if not settings.TESTING and not is_update_views: try: notify_url = obj.get_full_url() SpiderNotify.baidu_notify([notify_url]) except Exception as ex: logger.error("notify sipder", ex) print(ex)
def test_validate_article(self): site = Site.objects.get_current().domain user = BlogUser.objects.get_or_create(email="*****@*****.**", username="******")[0] user.set_password("systemsgt.cn") user.is_staff = True user.is_superuser = True user.save() response = self.client.get(user.get_absolute_url()) self.assertEqual(response.status_code, 200) category = Category() category.name = "category" category.created_time = datetime.datetime.now() category.last_mod_time = datetime.datetime.now() category.save() tag = Tag() tag.name = "nicetag" tag.save() article = Article() article.title = "nicetitle" article.body = "nicecontent" article.author = user article.category = category article.type = 'a' article.status = 'p' article.save() self.assertEqual(0, article.tags.count()) article.tags.add(tag) article.save() self.assertEqual(1, article.tags.count()) response = self.client.get(article.get_absolute_url()) self.assertEqual(response.status_code, 200) from DjangoBlog.spider_notify import SpiderNotify SpiderNotify.notify(article.get_absolute_url()) response = self.client.get(tag.get_absolute_url()) self.assertEqual(response.status_code, 200) response = self.client.get(category.get_absolute_url()) self.assertEqual(response.status_code, 200) response = self.client.get('/search', {'q': 'django'}) self.assertEqual(response.status_code, 200) s = load_articletags(article) self.assertIsNotNone(s) p = Paginator(Article.objects.all(), 2) s = load_pagination_info(p.page(1), '', '') self.assertIsNotNone(s) p = Paginator(Tag.objects.all(), 2) s = load_pagination_info(p.page(1), '分类标签归档', 'tagname') self.assertIsNotNone(s) p = Paginator(BlogUser.objects.all(), 2) s = load_pagination_info(p.page(1), '作者文章归档', 'username') self.assertIsNotNone(s) p = Paginator(Category.objects.all(), 2) s = load_pagination_info(p.page(1), '分类目录归档', 'categoryname') self.assertIsNotNone(s) f = BlogSearchForm() f.search() self.client.login(username='******', password='******') from DjangoBlog.spider_notify import SpiderNotify SpiderNotify.baidu_notify([article.get_full_url()]) rsp = self.client.get('/refresh/') self.assertEqual(rsp.status_code, 200) from blog.templatetags.blog_tags import gravatar_url, gravatar u = gravatar_url('*****@*****.**') u = gravatar('*****@*****.**')
def test_validate_article(self): site = get_current_site().domain user = BlogUser.objects.get_or_create(email="*****@*****.**", username="******")[0] user.set_password("superstrongz") user.is_staff = True user.is_superuser = True user.save() response = self.client.get(user.get_absolute_url()) self.assertEqual(response.status_code, 200) response = self.client.get('admin/admin/logentry/') s = SideBar() s.sequence = 1 s.name = 'test' s.content = 'test content' s.is_enable = True s.save() category = Category() category.name = "category" category.created_time = datetime.datetime.now() category.last_mod_time = datetime.datetime.now() category.save() tag = Tag() tag.name = "nicetag" tag.save() article = Article() article.title = "nicetitle" article.body = "nicecontent" article.author = user article.category = category article.type = 'a' article.status = 'p' article.save() self.assertEqual(0, article.tags.count()) article.tags.add(tag) article.save() self.assertEqual(1, article.tags.count()) for i in range(20): article = Article() article.title = "nicetitle" + str(i) article.body = "nicetitle" + str(i) article.author = user article.category = category article.type = 'a' article.status = 'p' article.save() article.tags.add(tag) article.save() response = self.client.get(article.get_absolute_url()) self.assertEqual(response.status_code, 200) from DjangoBlog.spider_notify import SpiderNotify SpiderNotify.notify(article.get_absolute_url()) response = self.client.get(tag.get_absolute_url()) self.assertEqual(response.status_code, 200) response = self.client.get(category.get_absolute_url()) self.assertEqual(response.status_code, 200) response = self.client.get('/search', {'q': 'django'}) self.assertEqual(response.status_code, 200) s = load_articletags(article) self.assertIsNotNone(s) rsp = self.client.get('/refresh') self.assertEqual(rsp.status_code, 302) self.client.login(username='******', password='******') rsp = self.client.get('/refresh') self.assertEqual(rsp.status_code, 200) response = self.client.get(reverse('blog:archives')) self.assertEqual(response.status_code, 200) p = Paginator(Article.objects.all(), 2) self.__check_pagination__(p, '', '') p = Paginator(Article.objects.filter(tags=tag), 2) self.__check_pagination__(p, '分类标签归档', tag.slug) p = Paginator(Article.objects.filter(author__username='******'), 2) self.__check_pagination__(p, '作者文章归档', 'superstrongz') p = Paginator(Article.objects.filter(category=category), 2) self.__check_pagination__(p, '分类目录归档', category.slug) f = BlogSearchForm() f.search() self.client.login(username='******', password='******') from DjangoBlog.spider_notify import SpiderNotify SpiderNotify.baidu_notify([article.get_full_url()]) from blog.templatetags.blog_tags import gravatar_url, gravatar u = gravatar_url('*****@*****.**') u = gravatar('*****@*****.**')
def test_validate_article(self): site = Site.objects.get_current().domain user = BlogUser.objects.get_or_create(email="*****@*****.**", username="******")[0] user.set_password("liangliangyy") user.is_staff = True user.is_superuser = True user.save() response = self.client.get(user.get_absolute_url()) self.assertEqual(response.status_code, 200) s = SideBar() s.sequence = 1 s.name = 'test' s.content = 'test content' s.is_enable = True s.save() category = Category() category.name = "category" category.created_time = datetime.datetime.now() category.last_mod_time = datetime.datetime.now() category.save() tag = Tag() tag.name = "nicetag" tag.save() article = Article() article.title = "nicetitle" article.body = "nicecontent" article.author = user article.category = category article.type = 'a' article.status = 'p' article.save() self.assertEqual(0, article.tags.count()) article.tags.add(tag) article.save() self.assertEqual(1, article.tags.count()) for i in range(20): article = Article() article.title = "nicetitle" + str(i) article.body = "nicetitle" + str(i) article.author = user article.category = category article.type = 'a' article.status = 'p' article.save() article.tags.add(tag) article.save() response = self.client.get(article.get_absolute_url()) self.assertEqual(response.status_code, 200) from DjangoBlog.spider_notify import SpiderNotify SpiderNotify.notify(article.get_absolute_url()) response = self.client.get(tag.get_absolute_url()) self.assertEqual(response.status_code, 200) response = self.client.get(category.get_absolute_url()) self.assertEqual(response.status_code, 200) response = self.client.get('/search', {'q': 'django'}) self.assertEqual(response.status_code, 200) s = load_articletags(article) self.assertIsNotNone(s) rsp = self.client.get('/refresh') self.assertEqual(rsp.status_code, 302) self.client.login(username='******', password='******') rsp = self.client.get('/refresh') self.assertEqual(rsp.status_code, 200) response = self.client.get(reverse('blog:archives')) self.assertEqual(response.status_code, 200) p = Paginator(Article.objects.all(), 2) self.__check_pagination__(p, '', '') p = Paginator(Article.objects.filter(tags=tag), 2) self.__check_pagination__(p, '分类标签归档', tag.slug) p = Paginator(Article.objects.filter(author__username='******'), 2) self.__check_pagination__(p, '作者文章归档', 'liangliangyy') p = Paginator(Article.objects.filter(category=category), 2) self.__check_pagination__(p, '分类目录归档', category.slug) f = BlogSearchForm() f.search() self.client.login(username='******', password='******') from DjangoBlog.spider_notify import SpiderNotify SpiderNotify.baidu_notify([article.get_full_url()]) from blog.templatetags.blog_tags import gravatar_url, gravatar u = gravatar_url('*****@*****.**') u = gravatar('*****@*****.**')
def test_validate_article(self): # site = get_current_site().domain user = BlogUser.objects.get_or_create(email="*****@*****.**", username="******")[0] user.set_password("liangliangyy") user.is_staff = True user.is_superuser = True user.save() response = self.client.get(user.get_absolute_url()) self.assertEqual(response.status_code, 200) response = self.client.get('/admin/servermanager/emailsendlog/') response = self.client.get('admin/admin/logentry/') s = SideBar() s.sequence = 1 s.name = 'test' s.content = 'test content' s.is_enable = True s.save() category = Category() category.name = "category" category.created_time = datetime.datetime.now() category.last_mod_time = datetime.datetime.now() category.save() tag = Tag() tag.name = "nicetag" tag.save() article = Article() article.title = "nicetitle" article.body = "nicecontent" article.author = user article.category = category article.type = 'a' article.status = 'p' article.save() self.assertEqual(0, article.tags.count()) article.tags.add(tag) article.save() self.assertEqual(1, article.tags.count()) for i in range(20): article = Article() article.title = "nicetitle" + str(i) article.body = "nicetitle" + str(i) article.author = user article.category = category article.type = 'a' article.status = 'p' article.save() article.tags.add(tag) article.save() response = self.client.get(article.get_absolute_url()) self.assertEqual(response.status_code, 200) SpiderNotify.notify(article.get_absolute_url()) response = self.client.get(tag.get_absolute_url()) self.assertEqual(response.status_code, 200) response = self.client.get(category.get_absolute_url()) self.assertEqual(response.status_code, 200) response = self.client.get('/search', {'q': 'django'}) self.assertEqual(response.status_code, 200) s = load_articletags(article) self.assertIsNotNone(s) rsp = self.client.get('/refresh') self.assertEqual(rsp.status_code, 302) self.client.login(username='******', password='******') rsp = self.client.get('/refresh') self.assertEqual(rsp.status_code, 200) response = self.client.get(reverse('blog:archives')) self.assertEqual(response.status_code, 200) p = Paginator(Article.objects.all(), 2) self.__check_pagination__(p, '', '') p = Paginator(Article.objects.filter(tags=tag), 2) self.__check_pagination__(p, '分类标签归档', tag.slug) p = Paginator(Article.objects.filter(author__username='******'), 2) self.__check_pagination__(p, '作者文章归档', 'liangliangyy') p = Paginator(Article.objects.filter(category=category), 2) self.__check_pagination__(p, '分类目录归档', category.slug) f = BlogSearchForm() f.search() self.client.login(username='******', password='******') SpiderNotify.baidu_notify([article.get_full_url()]) # u = gravatar_url('*****@*****.**') u = gravatar('*****@*****.**') link = Links(sequence=1, name="lylinux", link='https://wwww.lylinux.net') link.save() response = self.client.get('/links.html') self.assertEqual(response.status_code, 200)
def test_validate_article(self): site = Site.objects.get_current().domain user = BlogUser.objects.get_or_create(email="*****@*****.**", username="******")[0] user.set_password("liangliangyy") user.save() response = self.client.get(user.get_absolute_url()) self.assertEqual(response.status_code, 200) category = Category() category.name = "category" category.created_time = datetime.datetime.now() category.last_mod_time = datetime.datetime.now() category.save() tag = Tag() tag.name = "nicetag" tag.save() article = Article() article.title = "nicetitle" article.body = "nicecontent" article.author = user article.category = category article.type = 'a' article.status = 'p' article.save() self.assertEqual(0, article.tags.count()) article.tags.add(tag) article.save() self.assertEqual(1, article.tags.count()) response = self.client.get(article.get_absolute_url()) self.assertEqual(response.status_code, 200) response = self.client.get(tag.get_absolute_url()) self.assertEqual(response.status_code, 200) response = self.client.get(category.get_absolute_url()) self.assertEqual(response.status_code, 200) response = self.client.get('/search', {'q': 'django'}) self.assertEqual(response.status_code, 200) s = load_articletags(article) self.assertIsNotNone(s) p = Paginator(Article.objects.all(), 2) s = load_pagination_info(p.page(1), '', '') self.assertIsNotNone(s) p = Paginator(Tag.objects.all(), 2) s = load_pagination_info(p.page(1), '分类标签归档', 'tagname') self.assertIsNotNone(s) p = Paginator(BlogUser.objects.all(), 2) s = load_pagination_info(p.page(1), '作者文章归档', 'username') self.assertIsNotNone(s) p = Paginator(Category.objects.all(), 2) s = load_pagination_info(p.page(1), '分类目录归档', 'categoryname') self.assertIsNotNone(s) f = BlogSearchForm() f.search() from DjangoBlog.spider_notify import SpiderNotify SpiderNotify.baidu_notify([article.get_full_url()])