diff --git a/anonkun.sql b/anonkun.sql index 4e96a1b..867634d 100644 --- a/anonkun.sql +++ b/anonkun.sql @@ -24,6 +24,13 @@ CREATE TABLE `quest_meta` ( FOREIGN KEY (`owner_id`) REFERENCES `users`(`user_id`) ) 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` ( `post_id` MEDIUMINT UNSIGNED NOT NULL AUTO_INCREMENT, `quest_id` SMALLINT UNSIGNED NOT NULL, @@ -32,7 +39,8 @@ CREATE TABLE `quest_data` ( `post` MEDIUMTEXT NOT NULL, `timestamp` INT UNSIGNED NOT NULL, 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; CREATE TABLE `dice_calls` ( diff --git a/database.py b/database.py index cf3c356..e16ea3d 100644 --- a/database.py +++ b/database.py @@ -154,12 +154,13 @@ def get_quest_meta(quest_id): return data -def get_quest_data(quest_id): +def get_quest_data(quest_id, page_num): """Retrieves all quest posts.""" 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", - (quest_id,)).fetchall() + (quest_id, page_num)).fetchall() return data @@ -345,3 +346,19 @@ def get_poll_votes_voted(post_id, ip_address): + "AND `poll_votes`.`ip_address` = %s", (post_id, ip_address)).fetchall() 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 diff --git a/templates/quest.html b/templates/quest.html index f453ee1..f401c2f 100644 --- a/templates/quest.html +++ b/templates/quest.html @@ -12,11 +12,11 @@ {% block header %} {% if session.get("user_id") == owner_id %}