55 lines
1.7 KiB
Python
55 lines
1.7 KiB
Python
from db.object_pool import ObjectPool
|
|
|
|
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):
|
|
return self.correctness
|
|
|
|
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)
|
|
|
|
def iter(self):
|
|
return iter(self.object_pool.pool)
|
|
|
|
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)]
|