Merge remote-tracking branch 'origin/ajax_post' into ajax_post

ajax_post
Shenyuan Jin 3 years ago
commit 11b7943642

@ -442,7 +442,7 @@ def delete_comment(id):
flash('The comment has been deleted.')
return redirect(url_for('.post', id=posts.id))
else:
flash('你没有删评论权限')
flash('You do not have the rights to delete this comment')
return redirect(url_for('.post', id=posts.id))
@ -465,7 +465,7 @@ def follow(username):
flash('Invalid user.')
return redirect(url_for('.index'))
if current_user.is_following(user):
flash('You are already following this user.')
flash('You have already followed this user.')
return redirect(url_for('.user', username=username))
current_user.follow(user)
db.session.commit()
@ -486,7 +486,7 @@ def unfollow(username):
return redirect(url_for('.user', username=username))
current_user.unfollow(user)
db.session.commit()
flash('You are not following %s anymore.' % username)
flash('You do not follow %s anymore.' % username)
return redirect(url_for('.user', username=username))
@ -499,39 +499,36 @@ def like(post_id):
flash('Invalid post.')
return redirect(url_for('.index'))
if current_user.is_liking(post):
flash('You are already liking this post.')
flash('You have already gave a like to this post.')
return redirect(url_for('.post', id=post_id))
current_user.like(post)
post.like(current_user)
post.recent_activity = datetime.utcnow()
db.session.commit()
flash('You are now liking this post')
flash('You give a like to this answer')
return redirect(url_for('.index', id=post_id))
@main.route('/AJAXlike/<post_id>',methods=['POST'], strict_slashes=False)
@main.route('/AJAXlike/<post_id>', methods=['POST'], strict_slashes=False)
# @login_required
@csrf.exempt
@permission_required(Permission.FOLLOW)
def AJAXlike(post_id):
if(current_user is None):
if (current_user is None):
return redirect(url_for("/"))
post = Post.query.filter_by(id=post_id).first()
if post is not None:
if(current_user.is_liking(post)):
if (current_user.is_liking(post)):
current_user.dislike(post)
post.dislike(current_user)
db.session.commit()
return jsonify({'code': 200, 'like': False, 'num':post.liker.count()})
return jsonify({'code': 200, 'like': False, 'num': post.liker.count()})
else:
current_user.like(post)
post.like(current_user)
post.recent_activity = datetime.utcnow()
db.session.commit()
return jsonify({'code': 200, 'like': True, 'num':post.liker.count()})
return jsonify({'code': 200, 'like': True, 'num': post.liker.count()})
@main.route('/likeinpost/<post_id>')

@ -1,3 +1,5 @@
<li class="post" id="{{ post.id }}">
<div class="panel panel-default">
<div class="panel-body">

@ -1,21 +1,91 @@
{#Reference: http://www.internetke.com/effects/css3/2015/0803/1682.html#}
<!DOCTYPE html>
<html lang="zh-cmn-Hans">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=no">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
{% extends "base.html" %}
{% import "_macros.html" as macros %}
{% block title %}Student Exchange Forum of BJUT{% endblock %}
{% block head %}
{{ super() }}
<!-- Custom styles for this template -->
<link rel="stylesheet" href="../../static/smusic.css"/>
<link rel="stylesheet" type="text/css" href="../../static/normalize.css"/>
<link rel="stylesheet" type="text/css" href="../../static/demo.css">
<link rel="stylesheet" href="../../static/style.css">
<title>Music Player</title>
</head>
<body>
{% endblock %}
{#<div class="kePublic">#}
<!--效果html开始-->
{#主导航#}
{% block navbar %}
<nav class="navbar navbar-default navbar-fixed-top">
<div class="container">
<div class="navbar-header">
<button type="button" class="navbar-toggle" data-toggle="collapse" data-target=".navbar-collapse">
<span class="sr-only">Toggle navigation</span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
<a class="navbar-brand" href="{{ url_for('main.index') }}">Student Exchange Forum of BJUT</a>
</div>
<div class="navbar-collapse collapse">
<ul class="nav navbar-nav">
<li><a href="{{ url_for('auth.guidance') }}">Guidance</a></li>
<form class="navbar-form navbar-left" role="search" method="post">
<input type="hidden" name="csrf_token" value="{{ csrf_token() }}"/>
<div class="form-group">
<input name="search" value=" " style="width: 420px;margin-left: 20px;" type="text"
class="form-control" placeholder="Search">
</div>
<button type="submit" class="btn btn-default">Submit</button>
</form>
</ul>
<ul class="nav navbar-nav navbar-right">
{% if current_user.is_authenticated %}
{# 通知#}
<li>
<a href="{{ url_for('main.notification') }}">
<svg viewBox="0 0 1024 1024" width="20" height="20">
<defs>
<style type="text/css"></style>
</defs>
<path d="M892.343 738.743c7.314 0 21.943 0 29.257 7.314-29.257-21.943-51.2-58.514-51.2-95.086V424.23c0-168.229-117.029-307.2-285.257-343.772v-7.314C585.143 36.57 548.57 0 512 0s-80.457 36.571-80.457 73.143v7.314C270.629 117.03 153.6 256 153.6 424.23V650.97c0 36.572-21.943 73.143-51.2 95.086 7.314-7.314 14.629-7.314 29.257-7.314-29.257 0-51.2 21.943-51.2 51.2s21.943 51.2 51.2 51.2h768c29.257 0 51.2-21.943 51.2-51.2-7.314-21.943-29.257-43.886-58.514-51.2zM512 1024c73.143 0 131.657-58.514 131.657-131.657H380.343C380.343 965.486 438.857 1024 512 1024z"
fill="#3BA9F6" p-id="1699">
</path>
</svg>
<span class="badge" style="margin-bottom: 10px"></span>
</a>
</li>
{# 下拉菜单#}
<li class="dropdown">
<a href="{{ url_for('main.notification') }}" class="dropdown-toggle" data-toggle="dropdown">Account<b
class="caret"></b></a>
<ul class="dropdown-menu">
<li><a href="{{ url_for('main.user', username=current_user.username) }}">MY Profile</a>
</li>
<li><a href="{{ url_for('auth.change_password') }}">MY Account</a></li>
<li><a href="{{ url_for('auth.logout') }}">Log Out</a></li>
</ul>
</li>
{% else %}
<li><a href="{{ url_for('auth.login') }}">Log In</a></li>
{% endif %}
</ul>
</div>
</div>
</nav>
{% endblock %}
{% block content %}
<div class="satic-area">
<div class="dynamic-area1"></div>
<div class="dynamic-area2"></div>
@ -125,5 +195,4 @@
<!--效果html结束-->
<div class="clear"></div>
{#</div>#}
</body>
</html>
{% endblock %}

@ -41,7 +41,7 @@
submit.style = "margin-left: 40px";
$(function () {
$(function () {
$("#socialShare").socialShare({
content: '',
@ -51,7 +51,7 @@
});
$("#shareQQ").on("click", function () {
$("#shareQQ").on("click", function () {
$(this).socialShare("tQQ");
})
</script>
@ -73,22 +73,6 @@
</a>
</h1>
<div id="socialShare"></div>
{# <script>#}
{# $(function () {#}
{##}
{# $("#socialShare").socialShare({#}
{# content: '',#}
{# url: '',#}
{# titile: ''#}
{# });#}
{##}
{# });#}
{##}
{# $("#shareQQ").on("click", function () {#}
{# $(this).socialShare("tQQ");#}
{# })#}
{# </script>#}
{# 正文#}
<div class="content" id="fancy-content" style="padding-bottom:20px;
border-bottom: 1px solid #ddd;margin: 30px;">
{{ post.body_html| safe }}
@ -168,7 +152,7 @@
{# 评论区#}
<div class="container col-sm-offset-1 col-sm-10 comment-cont">
<h3 id="comments">Comments</h3>
<h2 id="comments">Comments</h2>
{% include 'Posts/_comments.html' %}
{% if current_user.can(Permission.COMMENT) %}
<div class="comment-form">

Loading…
Cancel
Save