# -*- coding: utf-8 -*-
#
# This file is part of INGInious. See the LICENSE and the COPYRIGHTS files for
# more information about the licensing of this file.
""" Displyable problems """
import gettext
import json
from abc import ABCMeta, abstractmethod
from random import Random
from inginious.common.tasks_problems import Problem, CodeProblem, CodeSingleLineProblem, \
MatchProblem, MultipleChoiceProblem, FileProblem
from inginious.frontend.parsable_text import ParsableText
[docs]class DisplayableProblem(Problem, metaclass=ABCMeta):
"""Basic problem """
[docs] @classmethod
@abstractmethod
def get_type_name(self, gettext):
pass
[docs] @classmethod
def get_renderer(cls, template_helper):
""" Get the renderer for this class problem """
return template_helper.get_renderer(False)
[docs] @classmethod
@abstractmethod
def show_editbox(cls, template_helper, key):
""" get the edit box html for this problem """
pass
[docs] @classmethod
@abstractmethod
def show_editbox_templates(cls, template_helper, key):
return ""
[docs]class DisplayableCodeProblem(CodeProblem, DisplayableProblem):
""" A basic class to display all BasicCodeProblem derivatives """
def __init__(self, task, problemid, content, translations=None):
super(DisplayableCodeProblem, self).__init__(task, problemid, content, translations)
[docs] @classmethod
def get_type_name(cls, gettext):
return gettext("code")
[docs] @classmethod
def show_editbox(cls, template_helper, key):
return DisplayableCodeProblem.get_renderer(template_helper).course_admin.subproblems.code(key, True)
[docs] @classmethod
def show_editbox_templates(cls, template_helper, key):
return ""
[docs]class DisplayableCodeSingleLineProblem(CodeSingleLineProblem, DisplayableProblem):
""" A displayable single code line problem """
def __init__(self, task, problemid, content, translations=None):
super(DisplayableCodeSingleLineProblem, self).__init__(task, problemid, content, translations)
[docs] @classmethod
def get_type_name(cls, gettext):
return gettext("single-line code")
[docs] @classmethod
def show_editbox(cls, template_helper, key):
return DisplayableCodeSingleLineProblem.get_renderer(template_helper).course_admin.subproblems.code(key, False)
[docs] @classmethod
def show_editbox_templates(cls, template_helper, key):
return ""
[docs]class DisplayableFileProblem(FileProblem, DisplayableProblem):
""" A displayable code problem """
def __init__(self, task, problemid, content, translations=None):
super(DisplayableFileProblem, self).__init__(task, problemid, content, translations)
[docs] @classmethod
def get_type_name(self, gettext):
return gettext("file upload")
[docs] @classmethod
def show_editbox(cls, template_helper, key):
return DisplayableFileProblem.get_renderer(template_helper).course_admin.subproblems.file(key)
[docs] @classmethod
def show_editbox_templates(cls, template_helper, key):
return ""
[docs]class DisplayableMultipleChoiceProblem(MultipleChoiceProblem, DisplayableProblem):
""" A displayable multiple choice problem """
def __init__(self, task, problemid, content, translations=None):
super(DisplayableMultipleChoiceProblem, self).__init__(task, problemid, content, translations)
[docs] @classmethod
def get_type_name(self, gettext):
return gettext("multiple choice")
[docs] @classmethod
def show_editbox(cls, template_helper, key):
return DisplayableMultipleChoiceProblem.get_renderer(template_helper).course_admin.subproblems.multiple_choice(key)
[docs] @classmethod
def show_editbox_templates(cls, template_helper, key):
return DisplayableMultipleChoiceProblem.get_renderer(template_helper).course_admin.subproblems.multiple_choice_templates(key)
[docs]class DisplayableMatchProblem(MatchProblem, DisplayableProblem):
""" A displayable match problem """
def __init__(self, task, problemid, content, translations=None):
super(DisplayableMatchProblem, self).__init__(task, problemid, content, translations)
[docs] @classmethod
def get_type_name(self, gettext):
return gettext("match")
[docs] @classmethod
def show_editbox(cls, template_helper, key):
return DisplayableMatchProblem.get_renderer(template_helper).course_admin.subproblems.match(key)
[docs] @classmethod
def show_editbox_templates(cls, template_helper, key):
return ""