basic support for pagination
This commit is contained in:
parent
3b4d24bd7c
commit
5ea5020a16
|
@ -57,7 +57,6 @@ app.wsgi_app = ProxyFix(app.wsgi_app)
|
||||||
app.register_blueprint(views)
|
app.register_blueprint(views)
|
||||||
app.config['MAX_CONTENT_LENGTH'] = 16 * 1024 * 1024
|
app.config['MAX_CONTENT_LENGTH'] = 16 * 1024 * 1024
|
||||||
app.config['SESSION_TYPE'] = 'filesystem'
|
app.config['SESSION_TYPE'] = 'filesystem'
|
||||||
app.url_map.strict_slashes = False
|
|
||||||
app.jinja_env.trim_blocks = True
|
app.jinja_env.trim_blocks = True
|
||||||
app.jinja_env.lstrip_blocks = True
|
app.jinja_env.lstrip_blocks = True
|
||||||
#app.jinja_env.undefined = "StrictUndefined"
|
#app.jinja_env.undefined = "StrictUndefined"
|
||||||
|
|
|
@ -27,6 +27,7 @@ CREATE TABLE `quest_meta` (
|
||||||
CREATE TABLE `quest_data` (
|
CREATE TABLE `quest_data` (
|
||||||
`post_id` MEDIUMINT UNSIGNED NOT NULL AUTO_INCREMENT,
|
`post_id` MEDIUMINT UNSIGNED NOT NULL AUTO_INCREMENT,
|
||||||
`quest_id` SMALLINT UNSIGNED NOT NULL,
|
`quest_id` SMALLINT UNSIGNED NOT NULL,
|
||||||
|
`page_num` TINYINT UNSIGNED NOT NULL,
|
||||||
`post_type` ENUM('text', 'dice', 'poll') NOT NULL,
|
`post_type` ENUM('text', 'dice', 'poll') NOT NULL,
|
||||||
`post` MEDIUMTEXT NOT NULL,
|
`post` MEDIUMTEXT NOT NULL,
|
||||||
`timestamp` INT UNSIGNED NOT NULL,
|
`timestamp` INT UNSIGNED NOT NULL,
|
||||||
|
|
|
@ -130,12 +130,13 @@ def insert_quest(canon_title, owner_id):
|
||||||
return quest_id
|
return quest_id
|
||||||
|
|
||||||
|
|
||||||
def insert_quest_post(quest_id, post_type, post, timestamp):
|
def insert_quest_post(quest_id, page_num, post_type, post, timestamp):
|
||||||
"""Insers a new quest post."""
|
"""Insers a new quest post."""
|
||||||
_DB.execute(
|
_DB.execute(
|
||||||
"INSERT INTO `quest_data`" \
|
"INSERT INTO `quest_data`" \
|
||||||
+ "(`quest_id`, `post_type`, `post`, `timestamp`) " \
|
+ "(`quest_id`, `page_num`, `post_type`, `post`, `timestamp`) " \
|
||||||
+ "VALUES (%s, %s, %s, %s)", (quest_id, post_type, post, timestamp))
|
+ "VALUES (%s, %s, %s, %s, %s)",
|
||||||
|
(quest_id, page_num, post_type, post, timestamp))
|
||||||
post_id = _DB.execute(
|
post_id = _DB.execute(
|
||||||
"SELECT `post_id` FROM `quest_data` WHERE `quest_id` = %s " \
|
"SELECT `post_id` FROM `quest_data` WHERE `quest_id` = %s " \
|
||||||
+ "ORDER BY `post_id` DESC", (quest_id,)).fetchone()[0]
|
+ "ORDER BY `post_id` DESC", (quest_id,)).fetchone()[0]
|
||||||
|
|
15
events.py
15
events.py
|
@ -28,17 +28,16 @@ def qm_only(msg=""):
|
||||||
def _nop(*args, **kwargs):
|
def _nop(*args, **kwargs):
|
||||||
data = args[0]
|
data = args[0]
|
||||||
room = data.get("room")
|
room = data.get("room")
|
||||||
res = db.get_quest_meta(quest_id=room)
|
res = db.get_quest_meta(room)
|
||||||
if not res:
|
if not res:
|
||||||
return msg
|
return msg
|
||||||
if session.get("user_id") != res[3]:
|
if session.get("user_id") != res[2]:
|
||||||
return msg
|
return msg
|
||||||
return func(*args, **kwargs)
|
return func(*args, **kwargs)
|
||||||
return _nop
|
return _nop
|
||||||
return actual_decorator
|
return actual_decorator
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@socketio.on('joined')
|
@socketio.on('joined')
|
||||||
def joined(data):
|
def joined(data):
|
||||||
"""
|
"""
|
||||||
|
@ -167,12 +166,14 @@ def new_post(data, internal=False):
|
||||||
"""
|
"""
|
||||||
room = data.get("room")
|
room = data.get("room")
|
||||||
post = data.get("post")
|
post = data.get("post")
|
||||||
|
page_num = data.get("page_num")
|
||||||
|
|
||||||
post = bleach.clean(post.strip())
|
post = bleach.clean(post.strip())
|
||||||
post = post.replace("\n", "<br />")
|
post = post.replace("\n", "<br />")
|
||||||
post = tools.handle_img(post)
|
post = tools.handle_img(post)
|
||||||
date = int(time.time())
|
date = int(time.time())
|
||||||
|
|
||||||
post_id = db.insert_quest_post(room, "text", post, date)
|
post_id = db.insert_quest_post(room, page_num, "text", post, date)
|
||||||
db.set_post_closed(room)
|
db.set_post_closed(room)
|
||||||
|
|
||||||
data = {}
|
data = {}
|
||||||
|
@ -229,6 +230,7 @@ def dice_post(data):
|
||||||
except (ValueError, AssertionError):
|
except (ValueError, AssertionError):
|
||||||
return
|
return
|
||||||
diceStrict = bool(data.get("diceStrict"))
|
diceStrict = bool(data.get("diceStrict"))
|
||||||
|
page_num = data.get("page_num")
|
||||||
|
|
||||||
dice_roll = f"{data['diceNum']}d{data['diceSides']}"
|
dice_roll = f"{data['diceNum']}d{data['diceSides']}"
|
||||||
if diceMod:
|
if diceMod:
|
||||||
|
@ -241,7 +243,7 @@ def dice_post(data):
|
||||||
post += " vs DC" + str(diceChal)
|
post += " vs DC" + str(diceChal)
|
||||||
date = int(time.time())
|
date = int(time.time())
|
||||||
|
|
||||||
post_id = db.insert_quest_post(room, "dice", post, date)
|
post_id = db.insert_quest_post(room, page_num, "dice", post, date)
|
||||||
new_call = (dice_roll, diceStrict, diceChal, diceRollsTaken)
|
new_call = (dice_roll, diceStrict, diceChal, diceRollsTaken)
|
||||||
db.insert_dice_call(post_id, room, new_call)
|
db.insert_dice_call(post_id, room, new_call)
|
||||||
db.set_post_open(post_id, room)
|
db.set_post_open(post_id, room)
|
||||||
|
@ -295,6 +297,7 @@ def poll_post(data):
|
||||||
room = data.pop("room", None)
|
room = data.pop("room", None)
|
||||||
multi_choice = bool(data.pop("pollAllowMultipleChoices", None))
|
multi_choice = bool(data.pop("pollAllowMultipleChoices", None))
|
||||||
allow_writein = bool(data.pop("pollAllowUserOptions", None))
|
allow_writein = bool(data.pop("pollAllowUserOptions", None))
|
||||||
|
page_num = data.get("page_num")
|
||||||
options = []
|
options = []
|
||||||
for key, value in data.items():
|
for key, value in data.items():
|
||||||
if not value or not key.startswith("pollOption-"):
|
if not value or not key.startswith("pollOption-"):
|
||||||
|
@ -307,7 +310,7 @@ def poll_post(data):
|
||||||
post = "Poll"
|
post = "Poll"
|
||||||
date = int(time.time())
|
date = int(time.time())
|
||||||
|
|
||||||
post_id = db.insert_quest_post(room, "poll", post, date)
|
post_id = db.insert_quest_post(room, page_num, "poll", post, date)
|
||||||
db.insert_poll(post_id, room, multi_choice, allow_writein)
|
db.insert_poll(post_id, room, multi_choice, allow_writein)
|
||||||
new_options = []
|
new_options = []
|
||||||
for option in options:
|
for option in options:
|
||||||
|
|
|
@ -5,7 +5,7 @@ var tid = setInterval( function () {
|
||||||
clearInterval( tid );
|
clearInterval( tid );
|
||||||
|
|
||||||
document.getElementById('chatWindow').scrollTop = document.getElementById('chatWindow').scrollHeight;
|
document.getElementById('chatWindow').scrollTop = document.getElementById('chatWindow').scrollHeight;
|
||||||
socket = io.connect('https://' + document.domain + ':' + location.port);
|
socket = io.connect('https://' + document.domain + location.port);
|
||||||
socket.on('connect', function() {
|
socket.on('connect', function() {
|
||||||
socket.emit('joined', {room: room_id});
|
socket.emit('joined', {room: room_id});
|
||||||
});
|
});
|
||||||
|
@ -223,7 +223,7 @@ function makePost() {
|
||||||
let text = qparea.value.trim();
|
let text = qparea.value.trim();
|
||||||
qparea.value = '';
|
qparea.value = '';
|
||||||
if (text == '') { return; }
|
if (text == '') { return; }
|
||||||
socket.emit('new_post', {post: text, room: room_id});
|
socket.emit('new_post', {post: text, page_num: page_num, room: room_id});
|
||||||
}
|
}
|
||||||
function edit_post(post_id) {
|
function edit_post(post_id) {
|
||||||
document.getElementById('questPostData-' + post_id).contentEditable = 'true';
|
document.getElementById('questPostData-' + post_id).contentEditable = 'true';
|
||||||
|
@ -247,6 +247,7 @@ function form_post(form_id, emit_msg) {
|
||||||
obj[key] = value;
|
obj[key] = value;
|
||||||
});
|
});
|
||||||
obj.room = room_id;
|
obj.room = room_id;
|
||||||
|
obj.page_num = page_num;
|
||||||
socket.emit(emit_msg, obj);
|
socket.emit(emit_msg, obj);
|
||||||
document.getElementById(form_id).reset();
|
document.getElementById(form_id).reset();
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,7 +2,7 @@
|
||||||
{% block title %}{{ quest_title }}{% endblock %}
|
{% block title %}{{ quest_title }}{% endblock %}
|
||||||
{% block head %}
|
{% block head %}
|
||||||
<script type="text/javascript" src="/static/socket.io.slim.js"></script>
|
<script type="text/javascript" src="/static/socket.io.slim.js"></script>
|
||||||
<script>var room_id = {{ room_id }};</script>
|
<script>var room_id = {{ room_id }}; var page_num = {{ page_num }};</script>
|
||||||
{% if session.get("user_id") == owner_id %}
|
{% if session.get("user_id") == owner_id %}
|
||||||
<script type="text/javascript" src="/static/anonkunQM.js"></script>
|
<script type="text/javascript" src="/static/anonkunQM.js"></script>
|
||||||
{% else %}
|
{% else %}
|
||||||
|
@ -11,7 +11,14 @@
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
{% block header %}
|
{% block header %}
|
||||||
{% if session.get("user_id") == owner_id %}
|
{% if session.get("user_id") == owner_id %}
|
||||||
<li><a href="{{ url_for('.edit_quest', quest_id=quest_id) }}">Edit Quest</a></li>
|
<li><a href="{{ url_for('.edit_quest', quest_id=quest_id) }}">Edit Quest</a></li>
|
||||||
|
<li><a href="{{ url_for('.quest', quest_id=quest_id, page_num=1) }}">Page 1</a></li>
|
||||||
|
<li>
|
||||||
|
<select onChange="window.location.href=this.value">
|
||||||
|
<option value="{{ url_for('.quest', quest_id=quest_id, page_num=1) }}">Page 1</option>
|
||||||
|
<option value="{{ url_for('.quest', quest_id=quest_id, page_num=2) }}">Page 2</option>
|
||||||
|
</select>
|
||||||
|
</li>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
{% block content %}
|
{% block content %}
|
||||||
|
@ -20,20 +27,20 @@
|
||||||
<center><h1>{{ quest_title }}</h1></center>
|
<center><h1>{{ quest_title }}</h1></center>
|
||||||
<div id="questPosts">
|
<div id="questPosts">
|
||||||
{% for quest_post in quest_posts %}
|
{% for quest_post in quest_posts %}
|
||||||
{% if quest_post[2] == "text" %}
|
{% if quest_post[3] == "text" %}
|
||||||
<div class="questPost textPost">
|
<div class="questPost textPost">
|
||||||
{% elif quest_post[2] == "dice" %}
|
{% elif quest_post[3] == "dice" %}
|
||||||
<div class="questPost dicePost{% if quest_post == quest_posts|last %} active_post{% endif %}">
|
<div class="questPost dicePost{% if quest_post == quest_posts|last %} active_post{% endif %}">
|
||||||
{% elif quest_post[2] == "poll" %}
|
{% elif quest_post[3] == "poll" %}
|
||||||
<div class="questPost pollPost{% if quest_post == quest_posts|last %} active_post{% endif %}">
|
<div class="questPost pollPost{% if quest_post == quest_posts|last %} active_post{% endif %}">
|
||||||
{% endif %}
|
{% endif %}
|
||||||
<div class="questPostMeta">
|
<div class="questPostMeta">
|
||||||
{{ quest_post[4] | strftime }}
|
{{ quest_post[5] | strftime }}
|
||||||
{% if session.get("user_id") == owner_id %}
|
{% if session.get("user_id") == owner_id %}
|
||||||
{% if quest_post[2] == "text" %}
|
{% if quest_post[3] == "text" %}
|
||||||
<br /><a href="javascript:void(0);" id="editPost-{{ quest_post[0] }}" onclick="edit_post({{ quest_post[0] }})">Edit</a>
|
<br /><a href="javascript:void(0);" id="editPost-{{ quest_post[0] }}" onclick="edit_post({{ quest_post[0] }})">Edit</a>
|
||||||
<a href="javascript:void(0);" id="savePost-{{ quest_post[0] }}" onclick="save_post('{{ quest_post[0] }}')" style="display:none;">Save</a>
|
<a href="javascript:void(0);" id="savePost-{{ quest_post[0] }}" onclick="save_post('{{ quest_post[0] }}')" style="display:none;">Save</a>
|
||||||
{% elif quest_post[2] == "dice" or quest_post[2] == "poll" and quest_post == quest_posts|last %}
|
{% elif quest_post[3] == "dice" or quest_post[3] == "poll" and quest_post == quest_posts|last %}
|
||||||
{% if quest_post[0] == open_post_id %}
|
{% if quest_post[0] == open_post_id %}
|
||||||
<br /><a href="javascript:void(0);" id="close_post_id-{{ quest_post[0] }}" onclick="close_post({{ quest_post[0] }})">Close</a>
|
<br /><a href="javascript:void(0);" id="close_post_id-{{ quest_post[0] }}" onclick="close_post({{ quest_post[0] }})">Close</a>
|
||||||
<a href="javascript:void(0);" id="open_post_id-{{ quest_post[0] }}" onclick="open_post({{ quest_post[0] }})" style="display:none;">Open</a>
|
<a href="javascript:void(0);" id="open_post_id-{{ quest_post[0] }}" onclick="open_post({{ quest_post[0] }})" style="display:none;">Open</a>
|
||||||
|
@ -45,19 +52,19 @@
|
||||||
{% endif %}
|
{% endif %}
|
||||||
</div>
|
</div>
|
||||||
<div class="questPostData" id="questPostData-{{ quest_post[0] }}">
|
<div class="questPostData" id="questPostData-{{ quest_post[0] }}">
|
||||||
{% if quest_post[2] == "text" %}
|
{% if quest_post[3] == "text" %}
|
||||||
{% autoescape false %}
|
{% autoescape false %}
|
||||||
{{ quest_post[3] }}
|
{{ quest_post[4] }}
|
||||||
{% endautoescape %}
|
{% endautoescape %}
|
||||||
{% elif quest_post[2] == "dice" %}
|
{% elif quest_post[3] == "dice" %}
|
||||||
<h3>{{ quest_post[3] }} - {% if quest_post[0] == open_post_id %}Open{% else %}Closed{% endif %}</h3>
|
<h3>{{ quest_post[4] }} - {% if quest_post[0] == open_post_id %}Open{% else %}Closed{% endif %}</h3>
|
||||||
{% for dice_roll in dice_rolls[quest_post[0]] %}
|
{% for dice_roll in dice_rolls[quest_post[0]] %}
|
||||||
<div id="questRollId-{{ dice_roll[0] }}">
|
<div id="questRollId-{{ dice_roll[0] }}">
|
||||||
<b>Rolled {{ dice_roll[4] }} = {{ dice_roll[5] }} ({{ dice_roll[3] }}){% if quest_post[0]|dice_chal != 0 %} - {% if dice_roll[5] >= quest_post[0]|dice_chal %}Pass{% else %} Fail{% endif %}{% endif %}</b>
|
<b>Rolled {{ dice_roll[4] }} = {{ dice_roll[5] }} ({{ dice_roll[3] }}){% if quest_post[0]|dice_chal != 0 %} - {% if dice_roll[5] >= quest_post[0]|dice_chal %}Pass{% else %} Fail{% endif %}{% endif %}</b>
|
||||||
</div>
|
</div>
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
{% elif quest_post[2] == "poll" %}
|
{% elif quest_post[3] == "poll" %}
|
||||||
<h3>{{ quest_post[3] }} - {% if quest_post[0] == open_post_id %}Open{% else %}Closed{% endif %}</h3>
|
<h3>{{ quest_post[4] }} - {% if quest_post[0] == open_post_id %}Open{% else %}Closed{% endif %}</h3>
|
||||||
<table class="poll" id="poll-{{ quest_post[0] }}">
|
<table class="poll" id="poll-{{ quest_post[0] }}">
|
||||||
<col{% if quest_post[0] != open_post_id %} style="visibility: collapse;"{% endif %}/>
|
<col{% if quest_post[0] != open_post_id %} style="visibility: collapse;"{% endif %}/>
|
||||||
<col/>
|
<col/>
|
||||||
|
|
1
todo
1
todo
|
@ -13,6 +13,7 @@ Account managament/logout
|
||||||
Display profile link in header bar
|
Display profile link in header bar
|
||||||
Tagging system
|
Tagging system
|
||||||
Quote backlinks
|
Quote backlinks
|
||||||
|
Make chat hideable
|
||||||
|
|
||||||
Improvements:
|
Improvements:
|
||||||
Revamp post editing
|
Revamp post editing
|
||||||
|
|
8
views.py
8
views.py
|
@ -43,6 +43,7 @@ def login_required(url=None):
|
||||||
|
|
||||||
|
|
||||||
@views.route("/quest/<int:quest_id>", strict_slashes=False)
|
@views.route("/quest/<int:quest_id>", strict_slashes=False)
|
||||||
|
@views.route("/quest/<int:quest_id>/<int:page_num>/")
|
||||||
def quest(quest_id, page_num=1):
|
def quest(quest_id, page_num=1):
|
||||||
"""
|
"""
|
||||||
An arbituary quest page.
|
An arbituary quest page.
|
||||||
|
@ -53,8 +54,8 @@ def quest(quest_id, page_num=1):
|
||||||
|
|
||||||
quest_id = room_id = data[0]
|
quest_id = room_id = data[0]
|
||||||
quest_title = data[1]
|
quest_title = data[1]
|
||||||
owner_id = data[3]
|
owner_id = data[2]
|
||||||
open_post_id = data[4]
|
open_post_id = data[2]
|
||||||
ip_address = request.remote_addr
|
ip_address = request.remote_addr
|
||||||
|
|
||||||
quest_posts = db.get_quest_data(quest_id)
|
quest_posts = db.get_quest_data(quest_id)
|
||||||
|
@ -127,9 +128,10 @@ def create_quest():
|
||||||
|
|
||||||
owner_id = session.get("user_id")
|
owner_id = session.get("user_id")
|
||||||
timestamp = int(time.time())
|
timestamp = int(time.time())
|
||||||
|
page_num = 1
|
||||||
|
|
||||||
quest_id = db.insert_quest(quest_title, owner_id)
|
quest_id = db.insert_quest(quest_title, owner_id)
|
||||||
db.insert_quest_post(quest_id, "text", quest_body, timestamp)
|
db.insert_quest_post(quest_id, page_num, "text", quest_body, timestamp)
|
||||||
|
|
||||||
return redirect(url_for('.quest', quest_id=quest_id))
|
return redirect(url_for('.quest', quest_id=quest_id))
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user