Last active
December 14, 2015 11:48
-
-
Save j2labs/5081768 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
>>> 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