Commit 7c8d71c8 authored by Dmitry Volodin's avatar Dmitry Volodin
Browse files

inv.vendor: JSON panel

--HG--
branch : feature/inventory
parent cb0724cf
......@@ -48,5 +48,43 @@ Ext.define("NOC.inv.vendor.Application", {
fieldLabel: "Site",
allowBlank: true
}
]
],
filters: [
{
title: "By Is Builtin",
name: "is_builtin",
ftype: "boolean"
}
],
//
initComponent: function() {
var me = this;
me.jsonPanel = Ext.create("NOC.core.JSONPreview", {
app: me,
restUrl: "/inv/vendor/{{id}}/json/",
previewName: "Vendor: {{name}}"
});
me.ITEM_JSON = me.registerItem(me.jsonPanel);
Ext.apply(me, {
formToolbar: [
{
text: "JSON",
glyph: NOC.glyph.file,
tooltip: "Show JSON",
hasAccess: NOC.hasPermission("read"),
scope: me,
handler: me.onJSON
}
]
});
me.callParent();
},
//
onJSON: function() {
var me = this;
me.showItem(me.ITEM_JSON);
me.jsonPanel.preview(me.currentRecord);
}
});
......@@ -8,7 +8,7 @@
## NOC modules
from noc.lib.app import ExtDocApplication, view
from noc.inv.models import Vendor
from noc.inv.models.vendor import Vendor
class VendorApplication(ExtDocApplication):
......@@ -19,3 +19,9 @@ class VendorApplication(ExtDocApplication):
menu = "Setup | Vendors"
model = Vendor
query_fields = ["name__icontains", "site__icontains"]
@view(url="^(?P<id>[0-9a-f]{24})/json/$", method=["GET"],
access="read", api=True)
def api_json(self, request, id):
vendor = self.get_object_or_404(Vendor, id=id)
return vendor.to_json()
......@@ -14,21 +14,7 @@ from noc.lib.nosql import *
from noc.sa.models import ManagedObject, ManagedObjectSelector
class Vendor(Document):
"""
Equipment vendor
"""
meta = {
"collection": "noc.vendors",
"allow_inheritance": False,
}
name = StringField(unique=True)
is_builtin = BooleanField(default=False)
site = URLField(required=False)
def __unicode__(self):
return self.name
from vendor import Vendor
class SocketAttribute(EmbeddedDocument):
......
## -*- coding: utf-8 -*-
##----------------------------------------------------------------------
## Vendor model
##----------------------------------------------------------------------
## Copyright (C) 2007-2013 The NOC Project
## See LICENSE for details
##----------------------------------------------------------------------
## Third-party modules
from mongoengine.document import Document
from mongoengine.fields import StringField, BooleanField, URLField
## NOC modules
from noc.lib.escape import json_escape as q
class Vendor(Document):
"""
Equipment vendor
"""
meta = {
"collection": "noc.vendors",
"allow_inheritance": False,
}
name = StringField(unique=True)
is_builtin = BooleanField(default=False)
site = URLField(required=False)
def __unicode__(self):
return self.name
def to_json(self):
r = [
"[",
" {",
" \"name\": \"%s\"," % q(self.name),
" \"site\": \"%s\"" % q(self.site),
" }",
"]"
]
return "\n".join(r)
\ No newline at end of file
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment