评论添加markdown支持

master
liangliang 9 years ago
parent 850ab5b7b0
commit c9c89db93e

@ -58,6 +58,14 @@ class LoginView(FormView):
return super(LoginView, self).dispatch(request, *args, **kwargs)
def get_context_data(self, **kwargs):
redirect_to = self.request.GET.get(self.redirect_field_name)
if redirect_to is None:
redirect_to = '/'
kwargs['redirect_to'] = redirect_to
return super(LoginView, self).get_context_data(**kwargs)
def form_valid(self, form):
form = AuthenticationForm(data=self.request.POST, request=self.request)
@ -65,16 +73,19 @@ class LoginView(FormView):
from DjangoBlog.utils import cache
if cache and cache is not None:
cache.clear()
print(self.redirect_field_name)
redirect_to = self.request.GET.get(self.redirect_field_name)
auth.login(self.request, form.get_user())
return HttpResponseRedirect('/')
return super(LoginView, self).form_valid(form)
# return HttpResponseRedirect('/')
else:
return self.render_to_response({
'form': form
})
def get_success_url(self):
redirect_to = self.request.GET.get(self.redirectfieldname)
print(self.redirect_field_name)
redirect_to = self.request.POST.get(self.redirect_field_name)
if not is_safe_url(url=redirect_to, host=self.request.get_host()):
redirect_to = self.success_url
return redirect_to

File diff suppressed because one or more lines are too long

@ -35,38 +35,39 @@ class Comment(models.Model):
def save(self, *args, **kwargs):
super().save(*args, **kwargs)
subject = '感谢您发表的评论'
site = Site.objects.get_current().domain
article_url = "https://{site}{path}".format(site=site, path=self.article.get_absolute_url())
html_content = """
<p>非常感谢您在本站发表评论</p>
您可以访问
<a href="%s" rel="bookmark">%s</a>
来查看您的评论
再次感谢您
<br />
如果上面链接无法打开请将此链接复制至浏览器
%s
""" % (article_url, self.article.title, article_url)
tomail = self.author.email
msg = EmailMultiAlternatives(subject, html_content, from_email='no-reply@lylinux.net', to=[tomail])
msg.content_subtype = "html"
_thread.start_new_thread(self.send_comment_email, (msg,))
if self.parent_comment:
if not settings.DEBUG:
subject = '感谢您发表的评论'
site = Site.objects.get_current().domain
article_url = "https://{site}{path}".format(site=site, path=self.article.get_absolute_url())
html_content = """
您在 <a href="%s" rel="bookmark">%s</a> 的评论 <br/> %s <br/> 收到回复啦.快去看看吧
<br/>
<p>非常感谢您在本站发表评论</p>
您可以访问
<a href="%s" rel="bookmark">%s</a>
来查看您的评论
再次感谢您
<br />
如果上面链接无法打开请将此链接复制至浏览器
%s
""" % (article_url, self.article.title, self.parent_comment.body, article_url)
tomail = self.parent_comment.author.email
""" % (article_url, self.article.title, article_url)
tomail = self.author.email
msg = EmailMultiAlternatives(subject, html_content, from_email='no-reply@lylinux.net', to=[tomail])
msg.content_subtype = "html"
_thread.start_new_thread(self.send_comment_email, (msg,))
if self.parent_comment:
html_content = """
您在 <a href="%s" rel="bookmark">%s</a> 的评论 <br/> %s <br/> 收到回复啦.快去看看吧
<br/>
如果上面链接无法打开请将此链接复制至浏览器
%s
""" % (article_url, self.article.title, self.parent_comment.body, article_url)
tomail = self.parent_comment.author.email
msg = EmailMultiAlternatives(subject, html_content, from_email='no-reply@lylinux.net', to=[tomail])
msg.content_subtype = "html"
_thread.start_new_thread(self.send_comment_email, (msg,))
def __str__(self):
return self.body

@ -19,7 +19,7 @@
{{ field.errors }}
{% endfor %}
<input type="hidden" name="next" value="{{ redirect_to }}">
<button class="btn btn-lg btn-primary btn-block" type="submit">Sign in</button>
<div class="checkbox">

@ -49,7 +49,8 @@
{% include 'comments/tags/post_comment.html' %}
{% else %}
<div class="comments-area">
<h3 class="comment-meta">您还没有登录请您<a href="{% url "account:login" %}">登录</a>后发表评论</h3>
<h3 class="comment-meta">您还没有登录请您<a
href="{% url "account:login" %}?next={{ request.get_full_path }}">登录</a>后发表评论</h3>
{% load oauth_tags %}
{% load_oauth_applications %}

@ -8,11 +8,11 @@
class="avatar avatar-96 photo" height="96" width="96">
<cite class="fn">
<a rel="nofollow"
{% if comment_item.author.is_superuser %}
{% if comment_item.author.is_superuser %}
href="{{ comment_item.author.get_absolute_url }}"
{% else %}
{% else %}
href="#"
{% endif %}
{% endif %}
rel="external nofollow"
class="url">{{ comment_item.author.username }}
</a>
@ -24,7 +24,7 @@
{{ comment_item.created_time }}
</div>
<p>{{ comment_item.body }}</p>
<p>{{ comment_item.body |custom_markdown }}</p>
<div class="reply"><a rel="nofollow" class="comment-reply-link"
href="javascript:void(0)"

@ -47,13 +47,13 @@
</p>{% endcomment %}
{{ form.parent_comment_id }}
<p class="form-submit">
<div class="form-submit">
<span class="comment-markdown"> 支持markdown</span>
<input name="submit" type="submit" id="submit" class="submit" value="发表评论"/>
<small class="cancel-comment" id="cancel_comment" style="display: none">
<a href="javascript:void(0)" id="cancel-comment-reply-link" onclick="cancel_reply()">取消回复</a>
</small>
</p>
</div>
</form>
</div><!-- #respond -->

Loading…
Cancel
Save