mirror of
https://github.com/netbox-community/netbox.git
synced 2025-12-26 15:17:45 -06:00
Standardized graph display; added templatization for graph links
This commit is contained in:
@@ -5,10 +5,14 @@ from extras.models import Graph
|
||||
|
||||
class GraphSerializer(serializers.ModelSerializer):
|
||||
embed_url = serializers.SerializerMethodField()
|
||||
embed_link = serializers.SerializerMethodField()
|
||||
|
||||
class Meta:
|
||||
model = Graph
|
||||
fields = ['name', 'embed_url', 'link']
|
||||
fields = ['name', 'embed_url', 'embed_link']
|
||||
|
||||
def get_embed_url(self, obj):
|
||||
return obj.embed_url(self.context['graphed_object'])
|
||||
|
||||
def get_embed_link(self, obj):
|
||||
return obj.embed_link(self.context['graphed_object'])
|
||||
|
||||
@@ -56,6 +56,12 @@ class Graph(models.Model):
|
||||
template = Template(self.source)
|
||||
return template.render(Context({'obj': obj}))
|
||||
|
||||
def embed_link(self, obj):
|
||||
if self.link is None:
|
||||
return ''
|
||||
template = Template(self.link)
|
||||
return template.render(Context({'obj': obj}))
|
||||
|
||||
|
||||
class ExportTemplate(models.Model):
|
||||
content_type = models.ForeignKey(ContentType, limit_choices_to={'model__in': EXPORTTEMPLATE_MODELS})
|
||||
|
||||
Reference in New Issue
Block a user