Commit working workflow state serializer, API views and tests.

This commit is contained in:
Roberto Rosario
2017-02-09 04:04:58 -04:00
parent d12d2d9865
commit ab68723cf6
4 changed files with 196 additions and 22 deletions

View File

@@ -49,14 +49,33 @@ class WorkflowDocumentTypeSerializer(DocumentTypeSerializer):
class WorkflowStateSerializer(serializers.HyperlinkedModelSerializer):
workflow_url = serializers.SerializerMethodField()
url = serializers.SerializerMethodField()
class Meta:
extra_kwargs = {
'url': {'view_name': 'rest_api:workflowstate-detail'},
'workflow': {'view_name': 'rest_api:workflow-detail'},
}
fields = ('completion', 'id', 'initial', 'label', 'workflow', 'url')
fields = (
'completion', 'id', 'initial', 'label', 'url', 'workflow_url',
)
model = WorkflowState
def create(self, validated_data):
validated_data['workflow'] = self.context['workflow']
return super(WorkflowStateSerializer, self).create(validated_data)
def get_url(self, instance):
return reverse(
'rest_api:workflowstate-detail', args=(
instance.workflow.pk, instance.pk
), request=self.context['request'], format=self.context['format']
)
def get_workflow_url(self, instance):
return reverse(
'rest_api:workflow-detail', args=(
instance.workflow.pk,
), request=self.context['request'], format=self.context['format']
)
class WorkflowSerializer(serializers.HyperlinkedModelSerializer):
document_types_url = serializers.HyperlinkedIdentityField(