add modification|fix bug|还有一堆事情记不得了

merge-requests/3/head
bug_creator 3 years ago
parent cf76ec12f5
commit 0939ba25cd

@ -11,7 +11,7 @@ from . import main
from .forms import UploadPhotoForm, CommentForm, PostMdForm
from .. import db, csrf, cache
from ..models import Permission, User, Post, Comment, Notification, Like, Transaction, Activity, Collect, Want, \
Question, Savequestion
Question, Savequestion, Saveanswer
from ..decorators import permission_required
from ..util import check_text
@ -299,7 +299,6 @@ def query(content):
@main.route('/query-user', methods=['GET', 'POST'])
def query_user():
if request.method == 'GET':
return render_template('queryuser.html')
if request.method == 'POST':
@ -365,6 +364,7 @@ def user(username):
posts = user.posts.order_by(Post.timestamp.desc())
questions = user.questions.order_by(Question.timestamp.desc())
concernQuestions = Savequestion.query.filter_by(saver_id=user.id)
concernAnswers = Saveanswer.query.filter_by(saver_id=user.id)
liking_posts = [{'post': item.liked_post, 'timestamp': item.timestamp} for item in
liking.order_by(Like.timestamp.desc())]
@ -375,7 +375,7 @@ def user(username):
return render_template('user.html', user=user, posts=posts, questions=questions, liking_posts=liking_posts,
activities=activities,
transactionsInProfile=transactions, collects=collects, wants=wants,
concernQuestions=concernQuestions, concernAnswers=posts)
concernQuestions=concernQuestions, concernAnswers=concernAnswers)
@main.route('/notification')
@ -622,6 +622,16 @@ def delete_post_inProfile(post_id):
return redirect(url_for('.user', username=current_user.username))
@main.route('/delete_question_profile/<question_id>')
@login_required
def delete_question_inProfile(question_id):
post = Question.query.filter_by(id=question_id).first()
db.session.delete(post)
db.session.commit()
flash('The posting has been deleted.')
return redirect(url_for('.user', username=current_user.username))
@main.route('/send_message/<username>/<message>')
@login_required
def send_message(username, message):
@ -889,6 +899,38 @@ def new_question_md():
return render_template('new_posting/new_mdquestion.html', form=form)
@main.route('/edit_question_md/<question_id>', methods=['GET', 'POST'])
@login_required
def edit_question_md(question_id):
form = PostMdForm()
question = Question.query.filter_by(id=question_id).first()
if current_user.can(Permission.WRITE) and form.validate_on_submit():
title = request.form.get('title')
body = form.body.data
if request.form.get('anonymous') == "on":
is_anonymous = True
else:
is_anonymous = False
if title == "":
flash("Title cannot be None!")
return render_template('new_posting/new_mdpost.html', form=form)
body_html = request.form['test-editormd-html-code']
question.title = title
question.body = body
question.body_html = body_html
question.is_anonymous = is_anonymous
question.recent_activity = datetime.utcnow()
db.session.add(question)
db.session.commit()
if question.is_anonymous:
flash("You have just posted a posting anonymously", 'success')
else:
flash("You have just posted a posting", 'success')
return redirect(url_for('.index'))
return render_template('new_posting/new_mdquestion.html', form=form, default_title=question.title,
default_body=question.body)
@main.route('/new_answer_md/<question_id>', methods=['GET', 'POST'])
@login_required
def new_answer_md(question_id):
@ -921,6 +963,35 @@ def new_answer_md(question_id):
return render_template('new_posting/new_mdanswer.html', form=form)
@main.route('/edit_answer_md/<answer_id>', methods=['GET', 'POST'])
@login_required
def edit_answer_md(answer_id):
form = PostMdForm()
answer = Post.query.filter_by(id=answer_id).first()
if current_user.can(Permission.WRITE) and form.validate_on_submit():
title = request.form.get('title')
body = form.body.data
if request.form.get('anonymous') == "on":
is_anonymous = True
else:
is_anonymous = False
body_html = request.form['test-editormd-html-code']
answer.title=title
answer.body = body
answer.body_html = body_html
answer.is_anonymous = is_anonymous
answer.recent_activity = datetime.utcnow()
db.session.add(answer)
db.session.commit()
if answer.is_anonymous:
flash("You have just posted a posting anonymously", 'success')
else:
flash("You have just posted a posting", 'success')
return redirect(url_for('.index'))
return render_template('new_posting/new_mdanswer.html', form=form,
default_body=answer.body)
@main.route('/questions/<question_id>', methods=['GET', 'POST'])
def view_question(question_id):
if request.method == 'GET':
@ -989,6 +1060,25 @@ def AJAXsave_question(question_id):
return jsonify({'code': 200, 'like': True, 'num': question.savers.count()})
@main.route('/AJAXsave_answer/<answer_id>', methods=['POST'], strict_slashes=False)
# @login_required
@csrf.exempt
@permission_required(Permission.FOLLOW)
def AJAXsave_answer(answer_id):
if current_user is None:
return redirect(url_for("/"))
answer = Post.query.filter_by(id=answer_id).first()
if answer is not None:
if current_user.is_savinganswer(answer):
current_user.unsaveanswer(answer)
db.session.commit()
return jsonify({'code': 200, 'like': False, 'num': answer.savers.count()})
else:
current_user.saveanswer(answer)
db.session.commit()
return jsonify({'code': 200, 'like': True, 'num': answer.savers.count()})
@main.route('/invitelist/<question_id>')
def invite_list(question_id):
# user = User.query.filter_by(id=user_id).first()
@ -1012,9 +1102,8 @@ def invite(question_id, user_id):
question = Question.query.filter_by(id=question_id).first()
user = User.query.filter_by(id=user_id).first()
notification=Notification(timestamp=datetime.utcnow(), username=current_user.username, action=" has invited ",
object=question.title, object_id=question_id, receiver_id=user_id)
notification = Notification(timestamp=datetime.utcnow(), username=current_user.username, action=" has invited ",
object=question.title, object_id=question_id, receiver_id=user_id)
db.session.add(notification)
db.session.commit()
return redirect(url_for('.invite_list', question_id=question_id))

@ -157,7 +157,7 @@ class User(UserMixin, db.Model):
# # # # save
saved_questions = db.relationship('Savequestion', foreign_keys=[Savequestion.saver_id], backref=db.backref('saver', lazy='joined'),
lazy='dynamic', cascade='all, delete-orphan')
aved_answers = db.relationship('Saveanswer', foreign_keys=[Saveanswer.saver_id],
saved_answers = db.relationship('Saveanswer', foreign_keys=[Saveanswer.saver_id],
backref=db.backref('saver', lazy='joined'),
lazy='dynamic', cascade='all, delete-orphan')

@ -2,7 +2,7 @@
*/
.comment-content {
padding: 5px;
padding: 5px 20px;
background-color: #fff;
border-bottom: 1px solid #ddd;
overflow: hidden;

@ -33,6 +33,7 @@
*/
.comment-cont{
padding: 0;
margin-top: 20px;
background-color: #fff;
box-shadow: 0 0 10px 3px #ddd;
@ -60,7 +61,7 @@
left: 50%;
top: 50%;
margin-left: 600px;
height: 150px;
height: 200px;
width: 80px;
background-color: #fff;
box-shadow: 0 0 10px 3px #ddd;

@ -1,21 +1,21 @@
<ul class="posts list-unstyled">
{% for post in concernAnswers %}
{% if post.is_anonymous==False %}
{% if post.answer.is_anonymous==False %}
<li class="post">
<div class="post-box">
<div class="post-content">
<h3 class="post-title">
<a href="{{ url_for('.post', id=post.id) }}">{{ post.title }}</a>
<a href="{{ url_for('.view_question', question_id=post.answer.question.id) }}">{{ post.answer.question.title }}</a>
</h3>
<div class="post-body">
<p>
{% if post.body_html %}
{{ post.body_html |safe|striptags|truncate(260,killwords=Flase,leeway=0) }}
{% if post.answer.body_html %}
{{ post.answer.body_html |safe|striptags|truncate(260,killwords=Flase,leeway=0) }}
{% else %}
{{ post.body |truncate(200,killwords=Flase,leeway=0)}}
{{ post.answer.body |truncate(200,killwords=Flase,leeway=0)}}
{% endif %}
<small><a href="{{ url_for('.post', id=post.id) }}"><B>Read More</B></a></small>
<small><a href="{{ url_for('.post', id=post.answer.id) }}"><B>Read More</B></a></small>
</p>
</div>
<div class="post-footer">
@ -23,7 +23,7 @@
<span class="glyphicon glyphicon-time"></span>
{{ moment(post.timestamp).fromNow() }}
</span>
{% if current_user == post.author %}
{% if current_user == post.answer.author %}
{# 删除#}
<a class="icon-btn" href="{{ url_for('main.delete_post_inProfile', post_id=post.id)}}">

@ -6,7 +6,7 @@
<div class="post-content">
<h3 class="post-title">
<a href="{{ url_for('.post', id=post.id) }}">{{ post.title }}</a>
<a href="{{ url_for('.view_question', question_id=post.question.id) }}">{{ post.question.title }}</a>
</h3>
<div class="post-body">
<p>
@ -31,7 +31,7 @@
<span>delete</span>
</a>
{# 修改 #}
<a class="icon-btn" href="#">
<a class="icon-btn" href="{{ url_for('main.edit_answer_md', answer_id=post.id)}}">
<span class="glyphicon glyphicon-pencil"></span>
<span>modification</span>
</a>

@ -6,7 +6,7 @@
<div class="post-content">
<h3 class="post-title">
<a href="{{ url_for('.post', id=post.id) }}">{{ post.title }}</a>
<a href="{{ url_for('.view_question', question_id=post.id) }}">{{ post.title }}</a>
</h3>
<div class="post-body">
<p>
@ -15,7 +15,7 @@
{% else %}
{{ post.body |truncate(200,killwords=Flase,leeway=0)}}
{% endif %}
<small><a href="{{ url_for('.post', id=post.id) }}"><B>Read More</B></a></small>
{# <small><a href="{{ url_for('.view_question', question_id=post.id) }}"><B>Read More</B></a></small>#}
</p>
</div>
<div class="post-footer">
@ -26,12 +26,12 @@
{% if current_user == post.author %}
{# 删除#}
<a class="icon-btn" href="{{ url_for('main.delete_post_inProfile', post_id=post.id)}}">
<a class="icon-btn" href="{{ url_for('main.delete_question_inProfile', question_id=post.id)}}">
<span class="glyphicon glyphicon-trash"></span>
<span>delete</span>
</a>
{# 修改 #}
<a class="icon-btn" href="#">
<a class="icon-btn" href="{{ url_for('main.edit_question_md', question_id=post.id)}}">
<span class="glyphicon glyphicon-pencil"></span>
<span>modification</span>
</a>

@ -111,12 +111,15 @@
<h2 class="post-title" style="margin-top: 12px; margin-bottom: 8px">
{{ question.title }}
</h2>
<div class="post-body" style="margin-top: 9px">
<p>
{{ question.body }}
</p>
{# <div class="post-body" style="margin-top: 9px">#}
{# <p>#}
{# {{ question.body }}#}
{# </p>#}
<div class="content" id="fancy-content" style="padding: 0 10px 10px;margin: 10px 0 0;box-shadow: none;border-top:1px solid #444444;border-bottom:1px solid #444444;">
{{ question.body_html| safe }}
</div>
{# <small><a href="{{ url_for('.post', id=post.id) }}"><B>Read More</B></a></small></p>#}
</div>
{# </div>#}
</div>

@ -73,8 +73,14 @@
</div>
<button type="submit" class="btn btn-primary" style="width: 120px;margin-left: 20px">submit</button>
</div>
<script>
ts=document.getElementById("ts")
ts.value={{ default_body|tojson }}
</script>
</form>
{% endif %}
</div>
{% endblock %}

@ -80,7 +80,7 @@
{# font-weight: 600;#}
outline: none;
box-shadow: none;
height: 100%;"></textarea>
height: 100%;" >{{ default_title }}</textarea>
{# </label>#}
</div>
@ -98,6 +98,10 @@
</div>
<button type="submit" class="btn btn-primary" style="width: 120px;margin-left: 20px">submit</button>
</div>
<script>
ts=document.getElementById("ts")
ts.value={{ default_body|tojson }}
</script>
</form>
{% endif %}

@ -152,7 +152,11 @@
{# 评论区#}
<div class="container col-sm-offset-1 col-sm-10 comment-cont">
<h2 id="comments">Comments</h2>
<div class="panel panel-default">
<div class="panel-heading">
<h3 class="panel-title">Comments</h3>
</div>
{% include 'Posts/_comments.html' %}
{% if current_user.can(Permission.COMMENT) %}
<div class="comment-form">
@ -181,6 +185,7 @@
</div>
</form>
</div>
</div>
{% endif %}
{% if pagination %}
<div class="pagination">
@ -210,6 +215,64 @@
<div>{{ post.liker.count() }} likes</div>
</a>
{% endif %}
<a class="unlike" href="javascript:void (0);" onclick="{
var csrftoken = $('meta[name=csrf-token]').attr('content');
var _this=document.getElementById('follow_answer');
var follow_icon=document.getElementById('follow_icon');
{#console.log(this.childNodes[3]);#}
{#console.log(this.childElementCount);#}
var sendData={
'csrf_token':csrftoken
};
$.ajax({
url: '{{ url_for('.AJAXsave_answer', answer_id=post.id) }}',
type: 'POST',
{#dataType: 'json',#}
{#contentType: 'application/json',#}
{#data: JSON.stringify(sendData),#}
success: function(result) {
console.log('success\n'+result);
if(result.like){
_this.innerText=' Unfollow'
follow_icon.setAttribute('fill','#3688FF')
}else{
_this.innerText=' Follow'
follow_icon.setAttribute('fill','#868686')
}
{#span1.setAttribute('href', '{{ url_for('.dislike', post_id=post.id) }}');#}
},
error:function(msg){
console.log(msg);
if(msg.status===403){
window.location.href='{{ url_for('auth.login') }}'
}
}
})
}" >
<svg viewBox="0 0 1024 1024" width="25" height="25">
<path id="follow_icon" d="M 100 100 L 600 800 L 800 100 z"
fill="{% if current_user.is_authenticated %}
{% if not current_user.is_savinganswer(post) %}
#868686
{% else %}
#3688FF
{% endif %}
{% else %}
#868686
{% endif %}"></path></svg>
<div id="follow_answer">{% if current_user.is_authenticated %}
{% if not current_user.is_savinganswer(post) %}
Follow
{% else %}
Unfollow
{% endif %}
{% else %}
Follow
{% endif %}</div>
</a>
<a class="all-liker" href="{{ url_for('.liked_by', post_id = post.id ) }}">
<svg viewBox="0 0 1024 1024" version="1.1" width="30" height="30">
<path d="M896.930909 247.156364c-4.421818-5.12-9.076364-9.774545-13.730909-14.196364a225.745455 225.745455 0 0 0-104.727273-56.552727 24.436364 24.436364 0 0 0-4.421818 0 160.349091 160.349091 0 0 0-23.272727-4.189091c-7.912727 0-16.290909-1.396364-24.436364-1.629091a226.210909 226.210909 0 0 0-65.396363 8.610909 232.727273 232.727273 0 0 0-76.8 37.701818 230.632727 230.632727 0 0 0-141.963637-46.545454c-8.378182 0-16.290909 0-23.272727 1.629091a209.454545 209.454545 0 0 0-23.272727 3.956363A230.4 230.4 0 0 0 285.090909 232.727273a156.392727 156.392727 0 0 0-13.498182 14.196363 228.072727 228.072727 0 0 0-57.250909 130.094546 269.730909 269.730909 0 0 0-1.163636 27.694545 252.974545 252.974545 0 0 0 4.421818 46.545455 136.145455 136.145455 0 0 1 71.912727 26.763636 139.636364 139.636364 0 0 1 46.545455-23.272727 128.930909 128.930909 0 0 1 39.098182-5.12 99.141818 99.141818 0 0 1 14.661818 0 72.610909 72.610909 0 0 1 14.196363 2.56 8.145455 8.145455 0 0 1 2.56 0A135.447273 135.447273 0 0 1 468.945455 488.727273c2.792727 2.792727 5.585455 5.585455 8.145454 8.610909a135.912727 135.912727 0 0 1 34.909091 76.567273 132.421818 132.421818 0 0 1 0 16.756363 170.589091 170.589091 0 0 1-10.007273 53.992727 267.636364 267.636364 0 0 1-43.054545 75.17091l-7.68 8.843636c-5.585455 6.749091-11.636364 13.032727-17.687273 19.316364a1156.189091 1156.189091 0 0 0 140.8 94.72 19.781818 19.781818 0 0 0 19.083636 0c12.567273-6.981818 36.770909-21.178182 67.025455-41.425455s60.974545-42.356364 94.952727-69.818182l14.894546-12.8 7.912727-6.981818a778.705455 778.705455 0 0 0 75.636364-76.101818l12.567272-15.127273a436.130909 436.130909 0 0 0 71.912728-125.207273 282.763636 282.763636 0 0 0 15.825454-90.530909 269.032727 269.032727 0 0 0 0-27.694545 229.236364 229.236364 0 0 0-57.250909-129.861818z"
@ -224,6 +287,7 @@
<div>All Likers</div>
</a>
</div>
{# </div>#}
</li>
{% endfor %}

@ -146,9 +146,9 @@
{% include 'Posts/_postsInProfile.html' %}
</ul>
</div>
<div class="tab-pane active" id="panel-7">
<div class="tab-pane pane" id="panel-7">
<ul class="posts list-unstyled">
{% include 'Posts/_answersInProfile.html' %}
{% include 'Posts/_questionsInProfile.html' %}
</ul>
</div>
<div class="tab-pane" id="panel-2">

Binary file not shown.

@ -46,3 +46,4 @@ webencodings==0.5.1
Werkzeug==2.0.2
WTForms==2.2
WTForms-Appengine==0.1
Flask-Docs

Loading…
Cancel
Save