# Path: mentoring/light_children.py
# class LightChild(Plugin, LightChildrenMixin):
#     """
#     Base class for the light children
#     """
#     entry_point = 'xblock.light_children'
# 
#     def __init__(self, parent):
#         self.parent = parent
#         self.xblock_container = parent.xblock_container
# 
#     @property
#     def runtime(self):
#         return self.parent.runtime
# 
#     @property
#     def xmodule_runtime(self):
#         try:
#             xmodule_runtime = self.parent.xmodule_runtime
#         except AttributeError:
#             # TODO-WORKBENCH-WORKAROUND: To allow to load from the workbench
#             class xmodule_runtime(object):
#                 course_id = 'sample-course'
#                 anonymous_student_id = 'student1'
#             xmodule_runtime = xmodule_runtime()
#         return xmodule_runtime
# 
#     def save(self):
#         pass
# 
# class Scope(object):
#     content = None
#     user_state = None
# 
# class String(LightChildField):
#     def __init__(self, *args, **kwargs):
#         self.value = kwargs.get('default', '') or ''
# 
#     def __str__(self):
#         return self.value
# 
#     def split(self, *args, **kwargs):
#         return self.value.split(*args, **kwargs)
# 
# Path: mentoring/utils.py
# def render_template(template_path, context={}):
#     """
#     Evaluate a template by resource path, applying the provided context
#     """
#     template_str = load_resource(template_path)
#     template = Template(template_str)
#     return template.render(Context(context))


import logging
from xblock.fragment import Fragment
from .light_children import LightChild, Scope, String
from .utils import render_template

    Must be a child of a MentoringBlock. Allow to display a tip/advice depending on the 
    values entered by the student, and supports multiple types of multiple-choice
    set, with preset choices and author-defined values.
    """
    question = String(help="Question to ask the student", scope=Scope.content, default="")
    type = String(help="Type of quizz", scope=Scope.content, default="choices")
    student_choice = String(help="Last input submitted by the student", default="", scope=Scope.user_state)
    low = String(help="Label for low ratings", scope=Scope.content, default="Less")
    high = String(help="Label for high ratings", scope=Scope.content, default="More")

    @classmethod
    def init_block_from_node(cls, block, node, attr):
        block.light_children = []
        for child_id, xml_child in enumerate(node):
            if xml_child.tag == "question":
                block.question = xml_child.text
            else:
                cls.add_node_as_child(block, xml_child, child_id)

        for name, value in attr:
            setattr(block, name, value)

        return block

    def mentoring_view(self, context=None):
        if str(self.type) not in ('rating', 'choices'):
            raise ValueError, u'Invalid value for QuizzBlock.type: `{}`'.format(self.type)

        template_path = 'templates/html/quizz_{}.html'.format(self.type)

# Path: mentoring/light_children.py
# class LightChild(Plugin, LightChildrenMixin):
#     """
#     Base class for the light children
#     """
#     entry_point = 'xblock.light_children'
# 
#     def __init__(self, parent):
#         self.parent = parent
#         self.xblock_container = parent.xblock_container
# 
#     @property
#     def runtime(self):
#         return self.parent.runtime
# 
#     @property
#     def xmodule_runtime(self):
#         try:
#             xmodule_runtime = self.parent.xmodule_runtime
#         except AttributeError:
#             # TODO-WORKBENCH-WORKAROUND: To allow to load from the workbench
#             class xmodule_runtime(object):
#                 course_id = 'sample-course'
#                 anonymous_student_id = 'student1'
#             xmodule_runtime = xmodule_runtime()
#         return xmodule_runtime
# 
#     def save(self):
#         pass
# 
# class Scope(object):
#     content = None
#     user_state = None
# 
# class String(LightChildField):
#     def __init__(self, *args, **kwargs):
#         self.value = kwargs.get('default', '') or ''
# 
#     def __str__(self):
#         return self.value
# 
#     def split(self, *args, **kwargs):
#         return self.value.split(*args, **kwargs)
# 
# Path: mentoring/utils.py
# def render_template(template_path, context={}):
#     """
#     Evaluate a template by resource path, applying the provided context
#     """
#     template_str = load_resource(template_path)
#     template = Template(template_str)
#     return template.render(Context(context))


# Path: mentoring/quizz.py
import logging
from xblock.fragment import Fragment
from .light_children import LightChild, Scope, String
from .utils import render_template


    Must be a child of a MentoringBlock. Allow to display a tip/advice depending on the 
    values entered by the student, and supports multiple types of multiple-choice
    set, with preset choices and author-defined values.
    """
    question = String(help="Question to ask the student", scope=Scope.content, default="")
    type = String(help="Type of quizz", scope=Scope.content, default="choices")
    student_choice = String(help="Last input submitted by the student", default="", scope=Scope.user_state)
    low = String(help="Label for low ratings", scope=Scope.content, default="Less")
    high = String(help="Label for high ratings", scope=Scope.content, default="More")

    @classmethod
    def init_block_from_node(cls, block, node, attr):
        block.light_children = []
        for child_id, xml_child in enumerate(node):
            if xml_child.tag == "question":
                block.question = xml_child.text
            else:
                cls.add_node_as_child(block, xml_child, child_id)

        for name, value in attr:
            setattr(block, name, value)

        return block

    def mentoring_view(self, context=None):
        if str(self.type) not in ('rating', 'choices'):
            raise ValueError, u'Invalid value for QuizzBlock.type: `{}`'.format(self.type)

        template_path = 'templates/html/quizz_{}.html'.format(self.type)

        html = render_template(template_path, {