quest pages work more better

This commit is contained in:
iou1name 2018-07-26 11:38:02 -04:00
parent 5ea5020a16
commit d77f254831
4 changed files with 37 additions and 9 deletions

View File

@ -24,6 +24,13 @@ CREATE TABLE `quest_meta` (
FOREIGN KEY (`owner_id`) REFERENCES `users`(`user_id`) FOREIGN KEY (`owner_id`) REFERENCES `users`(`user_id`)
) ENGINE=InnoDB CHARSET utf8mb4; ) ENGINE=InnoDB CHARSET utf8mb4;
CREATE TABLE `page_titles` (
`quest_id` SMALLINT UNSIGNED NOT NULL,
`page_num` TINYINT UNSIGNED NOT NULL,
`page_title` VARCHAR(200) NOT NULL,
FOREIGN KEY (`quest_id`) REFERENCES `quest_meta`(`quest_id`)
) ENGINE=InnoDB CHARSET utf8mb4;
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,
@ -32,7 +39,8 @@ CREATE TABLE `quest_data` (
`post` MEDIUMTEXT NOT NULL, `post` MEDIUMTEXT NOT NULL,
`timestamp` INT UNSIGNED NOT NULL, `timestamp` INT UNSIGNED NOT NULL,
PRIMARY KEY (`post_id`), PRIMARY KEY (`post_id`),
FOREIGN KEY (`quest_id`) REFERENCES `quest_meta`(`quest_id`) FOREIGN KEY (`quest_id`) REFERENCES `quest_meta`(`quest_id`),
FOREIGN KEY (`page_num`) REFERENCES `page_titles`(`page_num`)
) ENGINE=InnoDB CHARSET utf8mb4; ) ENGINE=InnoDB CHARSET utf8mb4;
CREATE TABLE `dice_calls` ( CREATE TABLE `dice_calls` (

View File

@ -154,12 +154,13 @@ def get_quest_meta(quest_id):
return data return data
def get_quest_data(quest_id): def get_quest_data(quest_id, page_num):
"""Retrieves all quest posts.""" """Retrieves all quest posts."""
data = _DB.execute( data = _DB.execute(
"SELECT * FROM `quest_data` WHERE `quest_id` = %s " \ "SELECT * FROM `quest_data` " \
+ "WHERE `quest_id` = %s AND `page_num` = %s " \
+ "ORDER BY `post_id` ASC", + "ORDER BY `post_id` ASC",
(quest_id,)).fetchall() (quest_id, page_num)).fetchall()
return data return data
@ -345,3 +346,19 @@ def get_poll_votes_voted(post_id, ip_address):
+ "AND `poll_votes`.`ip_address` = %s", + "AND `poll_votes`.`ip_address` = %s",
(post_id, ip_address)).fetchall() (post_id, ip_address)).fetchall()
return data return data
def insert_quest_page(quest_id, page_num, page_title):
"""Inserts a new quest page."""
_DB.execute(
"INSERT INTO `page_titles` (`quest_id`, `page_num`, `page_title`) " \
+ "VALUES (%s, %s, %s)",
(quest_id, page_num, page_title))
def get_quest_pages(quest_id):
"""Gets all numbers and titles for a quest."""
data = _DB.execute(
"SELECT * FROM `page_titles` WHERE `quest_id` = %s",
(quest_id,)).fetchall()
return data

View File

@ -12,11 +12,11 @@
{% 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> <li>
<select onChange="window.location.href=this.value"> <select onChange="window.location.href=this.value">
<option value="{{ url_for('.quest', quest_id=quest_id, page_num=1) }}">Page 1</option> {% for page in pages %}
<option value="{{ url_for('.quest', quest_id=quest_id, page_num=2) }}">Page 2</option> <option value="{{ url_for('.quest', quest_id=quest_id, page_num=page[1]) }}"{% if page[1] == page_num %} selected="yes"{% endif %}>{{ page[2] }}</option>
{% endfor %}
</select> </select>
</li> </li>
{% endif %} {% endif %}
@ -161,5 +161,5 @@
<div id="messageTextDiv"><textarea id="messageTextArea"></textarea></div> <div id="messageTextDiv"><textarea id="messageTextArea"></textarea></div>
</div> </div>
</div> </div>
<div id="preview"></div> <div id="preview" style="display:none;"></div>
{% endblock %} {% endblock %}

View File

@ -58,7 +58,9 @@ def quest(quest_id, page_num=1):
open_post_id = data[2] open_post_id = data[2]
ip_address = request.remote_addr ip_address = request.remote_addr
quest_posts = db.get_quest_data(quest_id) pages = db.get_quest_pages(quest_id)
quest_posts = db.get_quest_data(quest_id, page_num)
dice_rolls_raw = db.get_dice_rolls(quest_id) dice_rolls_raw = db.get_dice_rolls(quest_id)
dice_rolls = {roll[2]: [] for roll in dice_rolls_raw} dice_rolls = {roll[2]: [] for roll in dice_rolls_raw}
_ = [dice_rolls[roll[2]].append(roll) for roll in dice_rolls_raw] _ = [dice_rolls[roll[2]].append(roll) for roll in dice_rolls_raw]
@ -131,6 +133,7 @@ def create_quest():
page_num = 1 page_num = 1
quest_id = db.insert_quest(quest_title, owner_id) quest_id = db.insert_quest(quest_title, owner_id)
db.insert_quest_page(quest_id, page_num, "Page 1")
db.insert_quest_post(quest_id, page_num, "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))