Skip to content

Instantly share code, notes, and snippets.

@j2labs
Last active December 14, 2015 11:48
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save j2labs/5081768 to your computer and use it in GitHub Desktop.
Save j2labs/5081768 to your computer and use it in GitHub Desktop.
>>> from schematics.models import Model
>>> from schematics.types.base import StringType, DateTimeType, IntType, BooleanType
>>> from schematics.types.compound import ListType, ModelType
>>>
>>> class ProtoStep(Model):
... step_type = StringType(required=True) # enum type?
... deadline = DateTimeType()
...
>>> class DocumentStep(ProtoStep):
... doc_name = StringType()
... responsible = IntType()
...
>>> class ApprovalStep(ProtoStep):
... include_subparts = BooleanType(default=False)
... responsible_list = ListType(IntType(), required=True)
...
>>> class WorkflowPayload(Model):
... steps = ListType([ModelType(DocumentStep),
... ModelType(ApprovalStep)], required=True)
...
>>> x = {
... "steps": [
... {
... "step_type": "DU",
... "deadline": "2013-02-02T00:00:00Z",
... "doc_name": "NDA document",
... "responsible": 3
... },
... {
... "step_type": "AP",
... "include_subparts": True,
... "responsible_list": [2, 4]
... }
... ]
... }
>>> wp = WorkflowPayload(**x)
>>> wp.steps
[<DocumentStep: DocumentStep object>, <ApprovalStep: ApprovalStep object>]
>>> wp.steps[0].step_type
'DU'
>>> wp.steps[0].doc_name
'NDA document'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment