initial development checkpoint 2
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
from object_pool import ObjectPool
|
||||
from db.object_pool import ObjectPool
|
||||
|
||||
class Question:
|
||||
def init(self, sID, title, max_time, test_id):
|
||||
@@ -24,6 +24,32 @@ class Question:
|
||||
def get_test_id(self):
|
||||
return self.test_id
|
||||
|
||||
def render_short(self):
|
||||
total_time = self.max_time
|
||||
|
||||
hours = total_time // 3600
|
||||
total_time -= hours * 3600
|
||||
|
||||
minutes = total_time // 60
|
||||
total_time -= minutes * 60
|
||||
|
||||
seconds = total_time
|
||||
|
||||
total_label = []
|
||||
if hours:
|
||||
total_label.append(f"{hours} год.")
|
||||
if minutes:
|
||||
total_label.append(f"{minutes} хв.")
|
||||
if seconds:
|
||||
total_label.append(f"{seconds} c.")
|
||||
|
||||
total_time = " ".join(total_label)
|
||||
|
||||
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>'
|
||||
|
||||
'''
|
||||
class QuestionPool:
|
||||
def __init__(self):
|
||||
@@ -36,8 +62,14 @@ class QuestionPool:
|
||||
'''
|
||||
|
||||
class QuestionPool:
|
||||
def __init__(self):
|
||||
def __init__(self, db):
|
||||
self.object_pool = ObjectPool("question", Question)
|
||||
|
||||
if db:
|
||||
self.object_pool.load_from_db(db)
|
||||
|
||||
def iter(self):
|
||||
return iter(self.object_pool.pool)
|
||||
|
||||
def select_by_test_id(self, test_id):
|
||||
return [i for i in self.object_pool.pool if i.get_test_id() == int(test_id)]
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
from object_pool import ObjectPool
|
||||
from db.object_pool import ObjectPool
|
||||
|
||||
class ResponseOption:
|
||||
def init(self, sID, label, questionID, correctness):
|
||||
@@ -24,20 +24,31 @@ class ResponseOption:
|
||||
def get_correctness(self):
|
||||
return correctness
|
||||
|
||||
class ResponceOptionPool:
|
||||
def __init__(self):
|
||||
def render_short(self):
|
||||
if self.correctness:
|
||||
c_mark = "+ "
|
||||
else:
|
||||
c_mark = " "
|
||||
|
||||
return f'<span class="response-option-short">{c_mark} {self.label}</span>'
|
||||
|
||||
def render_full(self):
|
||||
if self.correctness:
|
||||
c_mark = "+"
|
||||
else:
|
||||
c_mark = "-"
|
||||
|
||||
return f'<div class="response-option"><a class="response-option-mark" href="/flip-correctness.py?res_opt_id={self.id}">{c_mark}</a><span class="response-option-label">{self.label}</span><br><div class="controls"><a class="sub-button" href="/index.py?mode=edit-response-option&id={self.id}">Редагувати</a><a class="scary-button" href="/index.py?mode=delete-response-option&id={self.id}">Видалити</a></div></div>'
|
||||
|
||||
class ResponseOptionPool:
|
||||
def __init__(self, db):
|
||||
self.object_pool = ObjectPool("response_option", ResponseOption)
|
||||
|
||||
if db:
|
||||
self.object_pool.load_from_db(db)
|
||||
|
||||
'''
|
||||
class ResponceOptionPool:
|
||||
def __init__(self):
|
||||
self.pool = []
|
||||
def iter(self):
|
||||
return iter(self.object_pool.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
|
||||
'''
|
||||
def select_by_question_id(self, question_id):
|
||||
return [i for i in self.object_pool.pool if i.get_question_id() == int(question_id)]
|
||||
|
||||
@@ -17,7 +17,7 @@ class Test:
|
||||
return self.name
|
||||
|
||||
def render_short(self):
|
||||
return f'<div class="test-short"><a class="header-link">#{self.sID} {self.name}</a></div>'
|
||||
return f'<div class="test-short"><a class="test-link" href="/index.py?mode=view-test&id={self.id}"><span class="sub-label">#{self.id}</span><span class="main-label">{self.name}</span></a></div>'
|
||||
|
||||
class TestPool:
|
||||
def __init__(self, db):
|
||||
|
||||
Reference in New Issue
Block a user