Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

添加标签云功能 #12

Merged
merged 3 commits into from
Apr 9, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion DjangoBlog/spider_notify.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ def __google_notify():
print(e)

@staticmethod
def notify(self, url):
def notify(url):

SpiderNotify.baidu_notify(url)
SpiderNotify.__google_notify()
43 changes: 43 additions & 0 deletions accounts/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
from django.contrib.sites.models import Site
import datetime
from accounts.models import BlogUser
from django.core.urlresolvers import reverse


# Create your tests here.
Expand Down Expand Up @@ -39,3 +40,45 @@ def test_validate_account(self):

response = self.client.get(article.get_admin_url())
self.assertEqual(response.status_code, 200)

def test_validate_register(self):
self.assertEquals(0, len(BlogUser.objects.filter(email='user123@user.com')))
response = self.client.post(reverse('account:register'), {
'username': 'user1233',
'email': 'user123@user.com',
'password1': 'password123',
'password2': 'password123',
})
self.assertEquals(1, len(BlogUser.objects.filter(email='user123@user.com')))

self.client.login(username='user1233', password='password123')
user = BlogUser.objects.filter(email='user123@user.com')[0]
user.is_superuser = True
user.is_staff = True
user.save()
article = Article()
article.title = "nicetitle333"
article.body = "nicecontentttt"
article.author = user

article.type = 'a'
article.status = 'p'
article.save()

response = self.client.get(article.get_admin_url())
self.assertEqual(response.status_code, 200)

response = self.client.get(reverse('account:logout'))
self.assertIn(response.status_code, [301, 302])

response = self.client.get(article.get_admin_url())
self.assertIn(response.status_code, [301, 302])

response = self.client.post(reverse('account:login'), {
'username': 'user1233',
'password': 'password123'
})
self.assertIn(response.status_code, [301, 302])

response = self.client.get(article.get_admin_url())
self.assertEqual(response.status_code, 200)
16 changes: 13 additions & 3 deletions blog/templatetags/blog_tags.py
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,17 @@ def load_sidebar(user):
links = Links.objects.all()
commment_list = Comment.objects.order_by('-id')[:settings.SIDEBAR_COMMENT_COUNT]
show_adsense = settings.SHOW_GOOGLE_ADSENSE
# tags=
# 标签云 计算字体大小
# 根据总数计算出平均值 大小为 (数目/平均值)*步长
increment = 10
tags = Tag.objects.all()
sidebar_tags = None
if tags:
s = list(map(lambda t: (t, t.get_article_count()), tags))
count = sum(map(lambda t: t[1], s))
dd = count / len(tags)
sidebar_tags = list(map(lambda x: (x[0], x[1], (x[1] / dd) * increment), s))

return {
'recent_articles': recent_articles,
'sidebar_categorys': sidebar_categorys,
Expand All @@ -137,7 +147,8 @@ def load_sidebar(user):
'sidabar_links': links,
'sidebar_comments': commment_list,
'user': user,
'show_adsense': show_adsense
'show_adsense': show_adsense,
'sidebar_tags': sidebar_tags
}


Expand Down Expand Up @@ -252,4 +263,3 @@ def query(qs, **kwargs):
{% endfor %}
"""
return qs.filter(**kwargs)

8 changes: 6 additions & 2 deletions blog/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,6 @@ def test_validate_article(self):
category.last_mod_time = datetime.datetime.now()
category.save()

response = self.client.get(category.get_absolute_url())
self.assertEqual(response.status_code, 200)
tag = Tag()
tag.name = "nicetag"
tag.save()
Expand All @@ -53,6 +51,12 @@ def test_validate_article(self):
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 test_validate_feed(self):
user = BlogUser.objects.get_or_create(email="liangliangyy12@gmail.com", username="liangliangyy")[0]
user.set_password("liangliangyy")
Expand Down
12 changes: 12 additions & 0 deletions templates/blog/tags/sidebar.html
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,18 @@
{% if show_adsense %}
{% include 'share_layout/adsense.html' %}
{% endif %}
{% if sidebar_tags %}
<aside id="tag_cloud-2" class="widget widget_tag_cloud"><h3 class="widget-title">标签云</h3>
<div class="tagcloud">
{% for tag,count,size in sidebar_tags %}
<a href="{{ tag.get_absolute_url }}"
class="tag-link-{{ tag.id }} tag-link-position-{{ tag.id }}"
style="font-size: {{ size }}pt;" title="{{ count }}个话题"> {{ tag.name }}
</a>
{% endfor %}
</div>
</aside>
{% endif %}
<aside id="text-2" class="widget widget_text"><h3 class="widget-title">欢迎您star或者fork本站源代码</h3>
<div class="textwidget">

Expand Down