Skip to content
This repository has been archived by the owner on May 10, 2024. It is now read-only.

Commit

Permalink
Init Plugin class vars per subclass
Browse files Browse the repository at this point in the history
  • Loading branch information
Don Mitchell authored and cpennington committed Nov 14, 2014
1 parent 108acc1 commit 0d26db2
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 6 deletions.
23 changes: 22 additions & 1 deletion xblock/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
HandlersMixin,
XmlSerializationMixin,
)
from xblock.plugin import Plugin
from xblock.plugin import Plugin, PluginMetaclass
from xblock.validation import Validation


Expand Down Expand Up @@ -64,6 +64,7 @@ class XBlockMetaclass(
ScopedStorageMixin.__metaclass__,
RuntimeServicesMixin.__metaclass__,
TagCombiningMetaclass,
PluginMetaclass,
):
"""
Metaclass for XBlock.
Expand Down Expand Up @@ -182,10 +183,30 @@ def validate(self):
return Validation(self.scope_ids.usage_id)


class AsideMetaclass(
ScopedStorageMixin.__metaclass__,
RuntimeServicesMixin.__metaclass__,
PluginMetaclass,
):
"""
Metaclass for XBlock.
Combines all the metaclasses XBlocks needs:
* `ChildrenModelMetaclass`
* `ModelMetaclass`
* `TagCombiningMetaclass`
"""
pass


class XBlockAside(ScopedStorageMixin, RuntimeServicesMixin, HandlersMixin, Plugin):
"""
This mixin allows Xblock-like class to declare that it provides aside functionality.
"""
__metaclass__ = AsideMetaclass

entry_point = "xblock_asides.v1"

@classmethod
Expand Down
21 changes: 16 additions & 5 deletions xblock/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,21 @@ def default_select(identifier, all_entry_points):
raise AmbiguousPluginError(all_entry_points)


class PluginMetaclass(type):
"""
Initialize class vars per subclass
"""
def __new__(mcs, name, bases, attrs):
"""
Init the class vars
"""
# Temporary entry points, for register_temp_plugin. A list of pairs,
# (identifier, entry_point):
# [('test1', test1_entrypoint), ('test2', test2_entrypoint), ...]
attrs['extra_entry_points'] = []
return super(PluginMetaclass, mcs).__new__(mcs, name, bases, attrs)


class Plugin(object):
"""Base class for a system that uses entry_points to load plugins.
Expand All @@ -51,14 +66,10 @@ class Plugin(object):
`entry_point`: The name of the entry point to load plugins from.
"""
__metaclass__ = PluginMetaclass

entry_point = None # Should be overwritten by children classes

# Temporary entry points, for register_temp_plugin. A list of pairs,
# (identifier, entry_point):
# [('test1', test1_entrypoint), ('test2', test2_entrypoint), ...]
extra_entry_points = []

@classmethod
def _load_class_entry_point(cls, entry_point):
"""
Expand Down

0 comments on commit 0d26db2

Please sign in to comment.