# Path: mentoring/light_children.py
# class XBlockWithLightChildren(LightChildrenMixin, XBlock):
#     """
#     XBlock base class with support for LightChild
#     """
#     def __init__(self, *args, **kwargs):
#         super(XBlockWithLightChildren, self).__init__(*args, **kwargs)
#         self.xblock_container = self
#         self.load_children_from_xml_content()
# 
#     @XBlock.json_handler
#     def view(self, data, suffix=''):
#         """
#         Current HTML view of the XBlock, for refresh by client
#         """
#         frag = self.student_view({})
#         frag = self.fragment_text_rewriting(frag)
# 
#         return {
#             'html': frag.content,
#         }
# 
#     def fragment_text_rewriting(self, fragment):
#         """
#         Do replacements like `/jump_to_id` URL rewriting in the provided text
#         """
#         # TODO: Why do we need to use `xmodule_runtime` and not `runtime`?
#         try:
#             course_id = self.xmodule_runtime.course_id
#         except AttributeError:
#             # TODO-WORKBENCH-WORKAROUND: To allow to load from the workbench
#             course_id = 'sample-course'
# 
#         try:
#             jump_to_url = reverse('jump_to_id', kwargs={'course_id': course_id, 'module_id': ''})
#         except:
#             # TODO-WORKBENCH-WORKAROUND: To allow to load from the workbench
#             jump_to_url = '/jump_to_id'
# 
#         fragment = replace_jump_to_id_urls(course_id, jump_to_url, self, 'student_view', fragment, {})
#         return fragment
# 
# Path: mentoring/message.py
# class MentoringMessageBlock(LightChild):
#     """
#     A message which can be conditionally displayed at the mentoring block level,
#     for example upon completion of the block
#     """
#     content = String(help="Message to display upon completion", scope=Scope.content, default="")
#     type = String(help="Type of message", scope=Scope.content, default="completed")
#     has_children = True
# 
#     def mentoring_view(self, context=None):
#         fragment, named_children = self.get_children_fragment(context, view_name='mentoring_view')
#         fragment.add_content(render_template('templates/html/message.html', {
#             'self': self,
#             'named_children': named_children,
#         }))
#         return fragment
# 
# Path: mentoring/utils.py
# def get_scenarios_from_path(scenarios_path, include_identifier=False):
#     """
#     Returns an array of (title, xmlcontent) from files contained in a specified directory,
#     formatted as expected for the return value of the workbench_scenarios() method
#     """
#     base_fullpath = os.path.dirname(os.path.realpath(__file__))
#     scenarios_fullpath = os.path.join(base_fullpath, scenarios_path)
# 
#     scenarios = []
#     if os.path.isdir(scenarios_fullpath):
#         for template in os.listdir(scenarios_fullpath):
#             if not template.endswith('.xml'):
#                 continue
#             identifier = template[:-4]
#             title = identifier.replace('_', ' ').title()
#             template_path = os.path.join(scenarios_path, template)
#             if not include_identifier:
#                 scenarios.append((title, load_resource(template_path)))
#             else:
#                 scenarios.append((identifier, title, load_resource(template_path)))
# 
#     return scenarios
# 
# def load_resource(resource_path):
#     """
#     Gets the content of a resource
#     """
#     resource_content = pkg_resources.resource_string(__name__, resource_path)
#     return unicode(resource_content)
# 
# 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
import uuid
from lxml import etree
from StringIO import StringIO
from xblock.core import XBlock
from xblock.fields import Boolean, Scope, String
from xblock.fragment import Fragment
from .light_children import XBlockWithLightChildren
from .message import MentoringMessageBlock
from .utils import get_scenarios_from_path, load_resource, render_template

        log.debug(u'Response from Studio: {}'.format(response))
        return response

    @property
    def default_xml_content(self):
        return render_template('templates/xml/mentoring_default.xml', {
            'self': self,
            'url_name': self.url_name_with_default,
        })

    @property
    def url_name_with_default(self):
        """
        Ensure the `url_name` is set to a unique, non-empty value.
        This should ideally be handled by Studio, but we need to declare the attribute
        to be able to use it from the workbench, and when this happen Studio doesn't set
        a unique default value - this property gives either the set value, or if none is set
        a randomized default value
        """
        if self.url_name == 'mentoring-default':
            return 'mentoring-{}'.format(uuid.uuid4())
        else:
            return self.url_name

    @staticmethod
    def workbench_scenarios():
        """
        Scenarios displayed by the workbench. Load them from external (private) repository
        """

# Path: mentoring/light_children.py
# class XBlockWithLightChildren(LightChildrenMixin, XBlock):
#     """
#     XBlock base class with support for LightChild
#     """
#     def __init__(self, *args, **kwargs):
#         super(XBlockWithLightChildren, self).__init__(*args, **kwargs)
#         self.xblock_container = self
#         self.load_children_from_xml_content()
# 
#     @XBlock.json_handler
#     def view(self, data, suffix=''):
#         """
#         Current HTML view of the XBlock, for refresh by client
#         """
#         frag = self.student_view({})
#         frag = self.fragment_text_rewriting(frag)
# 
#         return {
#             'html': frag.content,
#         }
# 
#     def fragment_text_rewriting(self, fragment):
#         """
#         Do replacements like `/jump_to_id` URL rewriting in the provided text
#         """
#         # TODO: Why do we need to use `xmodule_runtime` and not `runtime`?
#         try:
#             course_id = self.xmodule_runtime.course_id
#         except AttributeError:
#             # TODO-WORKBENCH-WORKAROUND: To allow to load from the workbench
#             course_id = 'sample-course'
# 
#         try:
#             jump_to_url = reverse('jump_to_id', kwargs={'course_id': course_id, 'module_id': ''})
#         except:
#             # TODO-WORKBENCH-WORKAROUND: To allow to load from the workbench
#             jump_to_url = '/jump_to_id'
# 
#         fragment = replace_jump_to_id_urls(course_id, jump_to_url, self, 'student_view', fragment, {})
#         return fragment
# 
# Path: mentoring/message.py
# class MentoringMessageBlock(LightChild):
#     """
#     A message which can be conditionally displayed at the mentoring block level,
#     for example upon completion of the block
#     """
#     content = String(help="Message to display upon completion", scope=Scope.content, default="")
#     type = String(help="Type of message", scope=Scope.content, default="completed")
#     has_children = True
# 
#     def mentoring_view(self, context=None):
#         fragment, named_children = self.get_children_fragment(context, view_name='mentoring_view')
#         fragment.add_content(render_template('templates/html/message.html', {
#             'self': self,
#             'named_children': named_children,
#         }))
#         return fragment
# 
# Path: mentoring/utils.py
# def get_scenarios_from_path(scenarios_path, include_identifier=False):
#     """
#     Returns an array of (title, xmlcontent) from files contained in a specified directory,
#     formatted as expected for the return value of the workbench_scenarios() method
#     """
#     base_fullpath = os.path.dirname(os.path.realpath(__file__))
#     scenarios_fullpath = os.path.join(base_fullpath, scenarios_path)
# 
#     scenarios = []
#     if os.path.isdir(scenarios_fullpath):
#         for template in os.listdir(scenarios_fullpath):
#             if not template.endswith('.xml'):
#                 continue
#             identifier = template[:-4]
#             title = identifier.replace('_', ' ').title()
#             template_path = os.path.join(scenarios_path, template)
#             if not include_identifier:
#                 scenarios.append((title, load_resource(template_path)))
#             else:
#                 scenarios.append((identifier, title, load_resource(template_path)))
# 
#     return scenarios
# 
# def load_resource(resource_path):
#     """
#     Gets the content of a resource
#     """
#     resource_content = pkg_resources.resource_string(__name__, resource_path)
#     return unicode(resource_content)
# 
# 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/mentoring.py
import logging
import uuid
from lxml import etree
from StringIO import StringIO
from xblock.core import XBlock
from xblock.fields import Boolean, Scope, String
from xblock.fragment import Fragment
from .light_children import XBlockWithLightChildren
from .message import MentoringMessageBlock
from .utils import get_scenarios_from_path, load_resource, render_template


        log.debug(u'Response from Studio: {}'.format(response))
        return response

    @property
    def default_xml_content(self):
        return render_template('templates/xml/mentoring_default.xml', {
            'self': self,
            'url_name': self.url_name_with_default,
        })

    @property
    def url_name_with_default(self):
        """
        Ensure the `url_name` is set to a unique, non-empty value.
        This should ideally be handled by Studio, but we need to declare the attribute
        to be able to use it from the workbench, and when this happen Studio doesn't set
        a unique default value - this property gives either the set value, or if none is set
        a randomized default value
        """
        if self.url_name == 'mentoring-default':
            return 'mentoring-{}'.format(uuid.uuid4())
        else:
            return self.url_name

    @staticmethod
    def workbench_scenarios():
        """
        Scenarios displayed by the workbench. Load them from external (private) repository
        """

        return get_scenarios_from_path('templates/xml')