Skip to content

Commit 8ba2ba9

Browse files
author
yangxueguang
committed
新增新浪微博登录和全文搜索
1 parent a846071 commit 8ba2ba9

File tree

29 files changed

+1406
-19
lines changed

29 files changed

+1406
-19
lines changed

accounts/admin.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
11
from django.contrib import admin
2+
from .models import BlogUser
23

34
# Register your models here.
5+
admin.site.register(BlogUser)

blog/search_indexes.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
from haystack import indexes
2+
from .models import Article
3+
4+
5+
class ArticleIndex(indexes.SearchIndex, indexes.Indexable):
6+
text = indexes.CharField(document=True, use_template=True)
7+
created_time = indexes.DateTimeField(model_attr='created_time')
8+
9+
def get_model(self):
10+
return Article
11+
12+
def index_queryset(self, using=None):
13+
return self.get_model().objects.filter(status='p')

blog/static/blog/css/comment.css

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,23 @@
7373
display: none;
7474
}
7575

76+
.comment-panel .like-form {
77+
display: inline-block;
78+
margin: 0;
79+
padding: 0;
80+
}
81+
82+
.comment-panel .like-form button {
83+
background: none;
84+
border: none;
85+
margin-right: 10px;
86+
font-size: 16px;
87+
}
88+
89+
.comment-panel .like-form button i {
90+
margin: 0;
91+
}
92+
7693
input[name='honeypot'] {
7794
display: none;
7895
}

blog/static/blog/js/blog.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ $(
2525
}),
2626

2727
$('.comment-panel .ion-chatbox-working').click(function () {
28-
$(this).parent().siblings('.inner-panel , form').slideToggle(400);
28+
$(this).parent().siblings('.inner-panel , .comment-form').slideToggle(400);
2929
$(this).parent().siblings(':last').children(':button').click(function () {
3030
$(this).parent().parent().children('.inner-panel , form').slideUp(400);
3131
});

blog/templates/blog/comment.html

Whitespace-only changes.

blog/templates/blog/detail.html

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -33,11 +33,9 @@ <h1 class="entry-title">{{ article.title }}</h1>
3333
{{ article.body|markdown }}
3434
</div>
3535
</article>
36-
{% if user.is_authenticated %}
37-
{% render_comment_form for article %}
38-
{% else %}
39-
<div>登录后评论</div>
40-
{% endif %}
36+
37+
{% render_comment_form for article %}
38+
4139

4240
{% render_comment_list for article %}
4341
</main>
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
{{ object.title }}
2+
{{ object.body }}

blog/templates/search/search.html

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
{% extends 'base.html' %}
2+
3+
{% block content %}
4+
<h2>Search</h2>
5+
6+
<form method="get" action=".">
7+
<table>
8+
{{ form.as_table }}
9+
<tr>
10+
<td>&nbsp;</td>
11+
<td>
12+
<input type="submit" value="Search">
13+
</td>
14+
</tr>
15+
</table>
16+
17+
{% if query %}
18+
<h3>Results</h3>
19+
20+
{% for result in page.object_list %}
21+
<p>
22+
<a href="{{ result.object.get_absolute_url }}">{{ result.object.title }}</a>
23+
</p>
24+
<p>{{ result.created_time }}</p>
25+
<p>{{ result.object.abstract }}</p>
26+
{% empty %}
27+
<p>No results found.</p>
28+
{% endfor %}
29+
30+
{% if page.has_previous or page.has_next %}
31+
<div>
32+
{% if page.has_previous %}
33+
<a href="?q={{ query }}&amp;page={{ page.previous_page_number }}">{% endif %}&laquo; Previous
34+
{% if page.has_previous %}</a>{% endif %}
35+
|
36+
{% if page.has_next %}<a href="?q={{ query }}&amp;page={{ page.next_page_number }}">{% endif %}
37+
Next &raquo;{% if page.has_next %}</a>{% endif %}
38+
</div>
39+
{% endif %}
40+
{% else %}
41+
{# Show some example queries to run, maybe query syntax, something else? #}
42+
{% endif %}
43+
</form>
44+
{% endblock %}

blog/views.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ class IndexView(ListView):
1313
template_name = "blog/index.html"
1414

1515
def get_queryset(self):
16+
print(self.request.session.items())
1617
return Article.objects.filter(status='p')
1718

1819

blog_project/settings.py

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,10 +39,12 @@
3939
'markdown_deux',
4040
'django_comments',
4141
'notifications',
42+
'haystack',
4243
'likes',
4344
'blog',
4445
'comments',
4546
'accounts',
47+
'social_login',
4648
]
4749

4850
SITE_ID = 1
@@ -76,6 +78,7 @@
7678
'django.contrib.auth.context_processors.auth',
7779
'django.contrib.messages.context_processors.messages',
7880
'blog.context_processors.sidebar', # for sidebar information
81+
'social_login.context_processors.social_sites', # for social login
7982
],
8083
},
8184
},
@@ -157,3 +160,28 @@
157160
]
158161

159162
LOGIN_URL = '/login/'
163+
164+
MEDIA_ROOT = 'media/'
165+
MEDIA_URL = '/media/'
166+
167+
# social user settings
168+
SOCIALOAUTH_SITES = (
169+
('weibo', 'socialoauth.sites.weibo.Weibo', '新浪微博',
170+
{
171+
'redirect_uri': 'http://zmrenwu.pythonanywhere.com',
172+
'client_id': '3072222160',
173+
'client_secret': '9b06ed28d7598a91ee72bc38e4f067b2',
174+
}
175+
),
176+
)
177+
SOCIAL_LOGIN_ERROR_REDIRECT_URL = 'errors/'
178+
179+
# haystack
180+
HAYSTACK_CONNECTIONS = {
181+
'default': {
182+
'ENGINE': 'whoosh_cn_backend.WhooshEngine',
183+
'PATH': os.path.join(BASE_DIR, 'whoosh_index'),
184+
},
185+
}
186+
# 自动更新索引
187+
HAYSTACK_SIGNAL_PROCESSOR = 'haystack.signals.RealtimeSignalProcessor'

0 commit comments

Comments
 (0)