2024-05-28 17:47:08 +03:00
|
|
|
from db.object_pool import ObjectPool
|
2024-05-25 19:18:26 +03:00
|
|
|
|
|
|
|
class ResponseOption:
|
|
|
|
def init(self, sID, label, questionID, correctness):
|
|
|
|
self.id = sID
|
|
|
|
self.label = label
|
|
|
|
self.questionID = questionID
|
|
|
|
self.correctness = correctness
|
|
|
|
|
|
|
|
return self
|
|
|
|
|
|
|
|
def init_from_data(self, data):
|
|
|
|
return self.init(*data)
|
|
|
|
|
|
|
|
def get_id(self):
|
|
|
|
return self.id
|
|
|
|
|
|
|
|
def get_label(self):
|
|
|
|
return self.label
|
|
|
|
|
|
|
|
def get_question_id(self):
|
|
|
|
return self.questionID
|
|
|
|
|
|
|
|
def get_correctness(self):
|
2024-06-01 19:45:47 +03:00
|
|
|
return self.correctness
|
2024-05-25 19:18:26 +03:00
|
|
|
|
2024-05-28 17:47:08 +03:00
|
|
|
def render_short(self):
|
|
|
|
if self.correctness:
|
|
|
|
c_mark = "+ "
|
|
|
|
else:
|
2024-06-01 13:49:13 +03:00
|
|
|
c_mark = "- "
|
2024-05-28 17:47:08 +03:00
|
|
|
|
|
|
|
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):
|
2024-05-25 19:18:26 +03:00
|
|
|
self.object_pool = ObjectPool("response_option", ResponseOption)
|
|
|
|
|
|
|
|
if db:
|
|
|
|
self.object_pool.load_from_db(db)
|
|
|
|
|
2024-05-28 17:47:08 +03:00
|
|
|
def iter(self):
|
|
|
|
return iter(self.object_pool.pool)
|
2024-05-25 19:18:26 +03:00
|
|
|
|
2024-05-28 17:47:08 +03:00
|
|
|
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)]
|