note ok
This commit is contained in:
parent
1459f8990c
commit
9bd7ffc9ab
@ -1,24 +1,16 @@
|
||||
{% extends 'base.html' %}
|
||||
|
||||
{% block header %}
|
||||
<style>
|
||||
.maindiv {
|
||||
height: 100%;
|
||||
width: 100%;
|
||||
position: fixed;
|
||||
z-index: 1;
|
||||
top: 20;
|
||||
left: 0;
|
||||
padding-left: 1.2rem;
|
||||
padding-right: 2rem;
|
||||
<script>
|
||||
function control_modal(op, modal_id){
|
||||
modal_elm = document.getElementById(modal_id);
|
||||
if (op == 'active') {
|
||||
modal_elm.classList.add('active');
|
||||
} else {
|
||||
modal_elm.classList.remove('active');
|
||||
}
|
||||
|
||||
.sidenav {
|
||||
height: 100%;
|
||||
max-width: 160px;
|
||||
z-index: 1;
|
||||
}
|
||||
</style>
|
||||
}
|
||||
</script>
|
||||
{% endblock %}
|
||||
|
||||
{% block content %}
|
||||
@ -41,6 +33,28 @@
|
||||
</ul>
|
||||
</div>
|
||||
<div class="column col-9 panel">
|
||||
<div class="modal" id="modal-addnote">
|
||||
<a onclick="control_modal('diactiate', 'modal-addnote')" class="modal-overlay" aria-label="Close"></a>
|
||||
<div class="modal-container">
|
||||
<div class="modal-header">
|
||||
<a onclick="control_modal('diactiate', 'modal-addnote')" class="btn btn-clear float-right" aria-label="Close"></a>
|
||||
<div class="modal-title h5">新建评论</div>
|
||||
</div>
|
||||
<div class="modal-body">
|
||||
<form id="modal-form" method="post" class="form-group" action="/note/create/{{book['book_id']}}/">
|
||||
<label class="form-label" for="notename" >标题</label>
|
||||
<input class="form-input" name="notename" id="notename" required>
|
||||
<label class="form-label" for="notecontent">评论</label>
|
||||
<textarea name="notecontent" id="notecontent" class="form-input" placeholder="添加评论..."rows="8" required></textarea>
|
||||
|
||||
</form>
|
||||
</div>
|
||||
<div class="modal-footer">
|
||||
<input form="modal-form" class="btn btn-primary" type="submit" value="提交">
|
||||
<a href="" class="btn">取消</a>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="panel-header">
|
||||
<div class="panel-title h3">{{book['book_name']}}</div>
|
||||
{%if booktype|length > 0 %}
|
||||
@ -85,7 +99,7 @@
|
||||
</div>
|
||||
<div class="divider-vert"></div>
|
||||
<div class="column">
|
||||
<a href="" class="btn btn-primary">加一个评论</a>
|
||||
<button href="" class="btn btn-primary" onclick="control_modal('active', 'modal-addnote')">添加评论</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
@ -108,11 +122,23 @@
|
||||
</div>
|
||||
{% endfor %}
|
||||
<div class="divider text-center" data-content="评论"></div>
|
||||
<div id="book-notes" class="card">
|
||||
{% for note in notes %}
|
||||
<div id="note{{note['note_id']}}" class="card">
|
||||
<div class="card-header">
|
||||
space
|
||||
<div class="card-title h5">{{note['note_name']}}</div>
|
||||
<div class="card-subtitle">
|
||||
<span><mark>日期</mark>{{note['note_date']}}</span>
|
||||
<div class="float-right">
|
||||
<a href="/note/delete/{{note['note_id']}}/" class="btn">删除</a>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="card-body">
|
||||
<blockquote>
|
||||
<p style="word-wrap:break-word; word-break:break-all; white-space:pre-wrap;">{{note['note_content']}}</p>
|
||||
</div>
|
||||
</div>
|
||||
{% endfor %}
|
||||
</div>
|
||||
<div class="panel-footer">
|
||||
Rendered @ {{cur_time}}
|
||||
|
||||
54
src/user.py
54
src/user.py
@ -211,8 +211,10 @@ def book(id):
|
||||
booktype = cur.fetchall()
|
||||
cur.execute("select * from document where book_id=%s", (book['book_id'], ))
|
||||
documents = cur.fetchall()
|
||||
cur.execute("select * from note where book_id=%s", (book['book_id'], ))
|
||||
notes = cur.fetchall()
|
||||
return render_template("/user/book.html",
|
||||
book=book, booktype=booktype, documents=documents,
|
||||
book=book, booktype=booktype, documents=documents, notes=notes,
|
||||
cur_time=datetime.datetime.now())
|
||||
|
||||
@bp.route("/book/update/<int:id>/", methods=("GET", "POST"))
|
||||
@ -396,3 +398,53 @@ def doc_delete(docid):
|
||||
opname="删除文件出现了一些意外", opresult=warning,
|
||||
cur_time=datetime.datetime.now(), ret_url=url_for("user.book", id=document['book_id']))
|
||||
return redirect(url_for("user.book", id=document['book_id']))
|
||||
|
||||
@bp.route("/note/create/<int:bookid>/", methods=("POST",))
|
||||
@login_required
|
||||
def note_create(bookid):
|
||||
error = None
|
||||
db = get_db()
|
||||
cur = db.cursor()
|
||||
|
||||
notename = request.form['notename']
|
||||
notecontent = request.form["notecontent"]
|
||||
if len(notename) == 0 or len(notecontent) == 0:
|
||||
error = "你竟敢绕过前端验证!"
|
||||
if error is None:
|
||||
try:
|
||||
cur.execute("insert into note (`note_name`,`note_content`,`book_id`,`user_id`) "
|
||||
"values (%s, %s, %s, %s)",
|
||||
(notename, notecontent, bookid, g.user['user_id']))
|
||||
db.commit()
|
||||
except pymysql.Error as _e:
|
||||
error = "未知错误:%s" % (_e)
|
||||
db.rollback()
|
||||
if error is not None:
|
||||
return render_template("/user/result.html",
|
||||
opname="添加评论失败", opresult=error,
|
||||
cur_time=datetime.datetime.now())
|
||||
|
||||
return redirect(url_for("user.book", id=bookid))
|
||||
|
||||
@bp.route("/note/delete/<int:noteid>/", methods=("GET",))
|
||||
@login_required
|
||||
def note_delete(noteid):
|
||||
db = get_db()
|
||||
cur = db.cursor()
|
||||
error = None
|
||||
cur.execute("select * from note where note_id=%s", (noteid,))
|
||||
note = cur.fetchone()
|
||||
if note is None:
|
||||
error = "评论不存在"
|
||||
if error is None:
|
||||
try:
|
||||
cur.execute("delete from note where `note_id`=%s", (noteid))
|
||||
db.commit()
|
||||
except pymysql.Error as _e:
|
||||
error = "未知错误:%s" % (_e)
|
||||
cur.close()
|
||||
if error is not None:
|
||||
return render_template("/user/result.html",
|
||||
opname="删除评论失败", opresult=error,
|
||||
cur_time=datetime.datetime.now())
|
||||
return redirect(url_for("user.book", id=note['book_id']))
|
||||
Loading…
Reference in New Issue
Block a user