xmodule_namespace.py 899 Bytes
Newer Older
Calen Pennington committed
1 2 3 4
"""
Namespace defining common fields used by Studio for all blocks
"""

5 6
import datetime

7 8
from xblock.core import Namespace, Scope, ModelType, String
from xmodule.fields import StringyBoolean
9

Calen Pennington committed
10

11 12 13 14 15
class DateTuple(ModelType):
    """
    ModelType that stores datetime objects as time tuples
    """
    def from_json(self, value):
16
        return datetime.datetime(*value[0:6])
17 18

    def to_json(self, value):
19 20 21
        if value is None:
            return None

22 23 24 25
        return list(value.timetuple())


class CmsNamespace(Namespace):
Calen Pennington committed
26 27 28
    """
    Namespace with fields common to all blocks in Studio
    """
29 30
    published_date = DateTuple(help="Date when the module was published", scope=Scope.settings)
    published_by = String(help="Id of the user who published this module", scope=Scope.settings)
31
    empty = StringyBoolean(help="Whether this is an empty template", scope=Scope.settings, default=False)