2016-03-01 11:23:03 -05:00
|
|
|
from rest_framework import serializers
|
|
|
|
|
2017-03-08 16:18:41 -05:00
|
|
|
from dcim.api.serializers import NestedSiteSerializer
|
2017-03-20 16:21:10 -04:00
|
|
|
from extras.models import ACTION_CHOICES, Graph, GRAPH_TYPE_CHOICES, ExportTemplate, TopologyMap, UserAction
|
2017-03-09 14:26:39 -05:00
|
|
|
from users.api.serializers import NestedUserSerializer
|
|
|
|
from utilities.api import ChoiceFieldSerializer
|
2016-03-01 11:23:03 -05:00
|
|
|
|
|
|
|
|
2017-03-08 16:12:14 -05:00
|
|
|
#
|
|
|
|
# Graphs
|
|
|
|
#
|
|
|
|
|
2016-03-01 11:23:03 -05:00
|
|
|
class GraphSerializer(serializers.ModelSerializer):
|
2017-03-20 15:14:33 -04:00
|
|
|
type = ChoiceFieldSerializer(choices=GRAPH_TYPE_CHOICES)
|
|
|
|
|
|
|
|
class Meta:
|
|
|
|
model = Graph
|
|
|
|
fields = ['id', 'type', 'weight', 'name', 'source', 'link']
|
|
|
|
|
|
|
|
|
|
|
|
class WritableGraphSerializer(serializers.ModelSerializer):
|
|
|
|
|
|
|
|
class Meta:
|
|
|
|
model = Graph
|
|
|
|
fields = ['id', 'type', 'weight', 'name', 'source', 'link']
|
|
|
|
|
|
|
|
|
|
|
|
class RenderedGraphSerializer(serializers.ModelSerializer):
|
2016-03-01 11:23:03 -05:00
|
|
|
embed_url = serializers.SerializerMethodField()
|
2016-06-24 11:16:49 -04:00
|
|
|
embed_link = serializers.SerializerMethodField()
|
2017-03-20 15:14:33 -04:00
|
|
|
type = ChoiceFieldSerializer(choices=GRAPH_TYPE_CHOICES)
|
2016-03-01 11:23:03 -05:00
|
|
|
|
|
|
|
class Meta:
|
|
|
|
model = Graph
|
2017-03-20 15:14:33 -04:00
|
|
|
fields = ['id', 'type', 'weight', 'name', 'embed_url', 'embed_link']
|
2016-03-01 11:23:03 -05:00
|
|
|
|
|
|
|
def get_embed_url(self, obj):
|
|
|
|
return obj.embed_url(self.context['graphed_object'])
|
2016-06-24 11:16:49 -04:00
|
|
|
|
|
|
|
def get_embed_link(self, obj):
|
|
|
|
return obj.embed_link(self.context['graphed_object'])
|
2017-03-08 16:12:14 -05:00
|
|
|
|
|
|
|
|
2017-03-20 16:21:10 -04:00
|
|
|
#
|
|
|
|
# Export templates
|
|
|
|
#
|
|
|
|
|
|
|
|
class ExportTemplateSerializer(serializers.ModelSerializer):
|
|
|
|
|
|
|
|
class Meta:
|
|
|
|
model = ExportTemplate
|
|
|
|
fields = ['id', 'content_type', 'name', 'description', 'template_code', 'mime_type', 'file_extension']
|
|
|
|
|
|
|
|
|
2017-03-08 16:12:14 -05:00
|
|
|
#
|
|
|
|
# Topology maps
|
|
|
|
#
|
|
|
|
|
2017-03-08 16:18:41 -05:00
|
|
|
class TopologyMapSerializer(serializers.ModelSerializer):
|
|
|
|
site = NestedSiteSerializer()
|
2017-03-08 16:12:14 -05:00
|
|
|
|
|
|
|
class Meta:
|
|
|
|
model = TopologyMap
|
|
|
|
fields = ['id', 'name', 'slug', 'site', 'device_patterns', 'description']
|
|
|
|
|
|
|
|
|
|
|
|
class WritableTopologyMapSerializer(serializers.ModelSerializer):
|
|
|
|
|
|
|
|
class Meta:
|
|
|
|
model = TopologyMap
|
2017-03-17 17:32:43 -04:00
|
|
|
fields = ['id', 'name', 'slug', 'site', 'device_patterns', 'description']
|
2017-03-09 14:26:39 -05:00
|
|
|
|
|
|
|
|
|
|
|
#
|
|
|
|
# User actions
|
|
|
|
#
|
|
|
|
|
|
|
|
class UserActionSerializer(serializers.ModelSerializer):
|
|
|
|
user = NestedUserSerializer()
|
|
|
|
action = ChoiceFieldSerializer(choices=ACTION_CHOICES)
|
|
|
|
|
|
|
|
class Meta:
|
|
|
|
model = UserAction
|
|
|
|
fields = ['id', 'time', 'user', 'action', 'message']
|