initial development checkpoint 3

This commit is contained in:
2024-06-01 13:49:13 +03:00
parent b4c1a23ce2
commit 54377708b0
9 changed files with 240 additions and 24 deletions

View File

@@ -1,4 +1,5 @@
from db.object_pool import ObjectPool
from db.response_option import ResponseOptionPool
class Question:
def init(self, sID, title, max_time, test_id):
@@ -24,7 +25,10 @@ class Question:
def get_test_id(self):
return self.test_id
def render_short(self):
def get_time_label(self):
if int(self.max_time) == 0:
return "Час на відповідь не обмежений"
total_time = self.max_time
hours = total_time // 3600
@@ -36,6 +40,7 @@ class Question:
seconds = total_time
total_label = []
if hours:
total_label.append(f"{hours} год.")
if minutes:
@@ -43,23 +48,17 @@ class Question:
if seconds:
total_label.append(f"{seconds} c.")
total_time = " ".join(total_label)
return "На відповідь є " + " ".join(total_label)
def get_response_option_short_list(self, cur):
rop = ResponseOptionPool(cur)
return "<br>".join([i.render_short() for i in rop.select_by_question_id(self.id)])
if int(self.max_time) > 0:
return f'<div class="question-short"><a class="question-link" href="/index.py?mode=view-question&id={self.id}"><span class="sub-label">#{self.id}</span><span class="main-label">{self.title}</span></a><span class="sub-title">На відповідь є {total_time}</span></div>'
else:
return f'<div class="question-short"><a class="question-link" href="/index.py?mode=view-question&id={self.id}"><span class="sub-label">#{self.id}</span><span class="main-label">{self.title}</span></a><span class="sub-title">Час на відповідь не обмежений</span></div>'
def render_short(self, cur):
time_label = self.get_time_label()
response_options = self.get_response_option_short_list(cur)
'''
class QuestionPool:
def __init__(self):
self.pool = []
def load_from_db(self, cur):
db.execute("SELECT * FROM response_option;")
self.pool = [ResponseOption().init_from_data(i) for i in cur]
return self
'''
return f'<div class="question-short"><a class="question-link" href="/index.py?mode=view-question&id={self.id}"><span class="sub-label">#{self.id}</span><span class="main-label">{self.title}</span></a><span class="sub-title">{time_label}</span><div class="response-option-short-list">{response_options}</div><div class="controls"><a class="sub-button" href="/index.py?mode=edit-question&id={self.id}">Редагувати</a><a class="scary-button" href="/index.py?mode=delete-question&id={self.id}">Видалити</a></div></div>'
class QuestionPool:
def __init__(self, db):

View File

@@ -28,7 +28,7 @@ class ResponseOption:
if self.correctness:
c_mark = "+ "
else:
c_mark = " "
c_mark = "- "
return f'<span class="response-option-short">{c_mark} {self.label}</span>'