# 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 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 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 errno
import logging
from xblock.fields import Scope
from .light_children import LightChild, String
from .utils import load_resource, render_template



# Globals ###########################################################

log = logging.getLogger(__name__)


# Classes ###########################################################

class MentoringTableBlock(LightChild):
    """
    Table-type display of information from mentoring blocks

    Used to present summary of information entered by the students in mentoring blocks.
    Supports different types of formatting through the `type` parameter.
    """
    type = String(help="Variant of the table to display", scope=Scope.content, default='')
    has_children = True

    def student_view(self, context):
        fragment, columns_frags = self.get_children_fragment(context,
                                                             view_name='mentoring_table_view')
        f, header_frags = self.get_children_fragment(context, view_name='mentoring_table_header_view')

        bg_image_url = self.runtime.local_resource_url(self.xblock_container,
                                                       'public/img/{}-bg.png'.format(self.type))

        # Load an optional description for the background image, for accessibility
        try:

# 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 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 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/table.py
import errno
import logging
from xblock.fields import Scope
from .light_children import LightChild, String
from .utils import load_resource, render_template




# Globals ###########################################################

log = logging.getLogger(__name__)


# Classes ###########################################################

class MentoringTableBlock(LightChild):
    """
    Table-type display of information from mentoring blocks

    Used to present summary of information entered by the students in mentoring blocks.
    Supports different types of formatting through the `type` parameter.
    """
    type = String(help="Variant of the table to display", scope=Scope.content, default='')
    has_children = True

    def student_view(self, context):
        fragment, columns_frags = self.get_children_fragment(context,
                                                             view_name='mentoring_table_view')
        f, header_frags = self.get_children_fragment(context, view_name='mentoring_table_header_view')

        bg_image_url = self.runtime.local_resource_url(self.xblock_container,
                                                       'public/img/{}-bg.png'.format(self.type))

        # Load an optional description for the background image, for accessibility
        try:

            bg_image_description = load_resource('static/text/table-{}.txt'.format(self.type))