refactor quest template database calls

This commit is contained in:
iou1name 2018-07-16 12:56:45 -04:00
parent 75fdbd6bd7
commit 1c4a7971d2
3 changed files with 13 additions and 19 deletions

View File

@ -288,13 +288,6 @@ def get_polls(quest_id):
return data
def get_poll(post_id):
"""Gets poll information."""
data = _DB.execute(
"SELECT * FROM `polls` WHERE `post_id` = %s", (post_id,)).fetchall()
return data
def insert_poll_option(post_id, option_text):
"""Insert a new poll option. ips_voted will be NULL to start."""
_DB.execute(

View File

@ -240,12 +240,10 @@
{% endautoescape %}
{% elif quest_post[2] == "dice" %}
<h3>{{ quest_post[3] }} - {% if quest_post[0] == open_post_id %}Open{% else %}Closed{% endif %}</h3>
{% for dice_roll in quest_post[0]|get_rolls %}
{% if dice_roll[2] == quest_post[0] %}
{% for dice_roll in dice_rolls[quest_post[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>
</div>
{% endif %}
{% endfor %}
{% elif quest_post[2] == "poll" %}
<h3>{{ quest_post[3] }} - {% if quest_post[0] == open_post_id %}Open{% else %}Closed{% endif %}</h3>
@ -253,8 +251,7 @@
<col{% if quest_post[0] != open_post_id %} style="visibility: collapse;"{% endif %}/>
<col/>
<col/>
{% for option in options %}
{% if option[1] == quest_post[0] %}
{% for option in options[quest_post[0]] %}
<tr>
<td class="pollCheckBox">
<input type="checkbox" id="pollInput-{{ option[0] }}" onchange="pollVote({{ option[0] }})"/>
@ -263,7 +260,6 @@
<td class="option_text">{{ option[2] }}</td>
<td class="optionVotes">0</td>
</tr>
{% endif %}
{% endfor %}
</table>
{% endif %}

View File

@ -47,7 +47,6 @@ def quest(quest_title):
"""
An arbituary quest page.
"""
then = time.time()
ident_title, _, extra = quest_title.partition("/")
data = db.get_quest_meta(ident_title=ident_title)
if not data:
@ -59,13 +58,19 @@ def quest(quest_title):
open_post_id = data[4]
quest_posts = db.get_quest_data(quest_id)
dice_rolls = db.get_dice_rolls(quest_id)
options = db.get_poll_options(quest_id=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]].append(roll) for roll in dice_rolls_raw]
del dice_rolls_raw
options_raw = db.get_poll_options(quest_id=quest_id)
options = {opt[1]: [] for opt in options_raw}
_ = [options[opt[1]].append(opt) for opt in options_raw]
del options_raw
messages = db.get_chat_messages(quest_id)
temp = render_template('quest.html', **locals())
print(time.time() - then)
return temp
return render_template('quest.html', **locals())
@views.route("/quest/<path:quest_title>/edit_quest", methods=["GET", "POST"])