def edit_connection_type(request, cid, id): cid = int(cid) id = int(id) conn_type = request.configuration.loadEntity(cid, id) from_dev = getFirstOrNone(conn_type.getNeighboursFrom(filter_func=getFilterNeighboursByClassName(request.configuration, "device_type"))) to_dev = getFirstOrNone(conn_type.getNeighboursTo(filter_func=getFilterNeighboursByClassName(request.configuration, "device_type"))) from_widget = GetHtmlEntityIdSelector(request, "from", cids_or_cnames_list=["device_type"], submit_form_on_select=False, value=from_dev) to_widget = GetHtmlEntityIdSelector(request, "to", cids_or_cnames_list=["device_type"], submit_form_on_select=False, value=to_dev) from_items = from_dev.getNeighboursTo(filter_func=getFilterNeighboursByClassName(request.configuration, "link")) to_items = to_dev.getNeighboursTo(filter_func=getFilterNeighboursByClassName(request.configuration, "channel")) through_items = conn_type.getNeighbours(filter_func=getFilterNeighboursByClassName(request.configuration, "connection_type_part")) for item in through_items: item.from_item = getFirstOrNone(item.getNeighboursTo(filter_func=getFilterNeighboursByClassName(request.configuration, "link"))) item.to_item = getFirstOrNone(item.getNeighboursTo(filter_func=getFilterNeighboursByClassName(request.configuration, "channel"))) from_items.sort(lambda a,b: cmp(a.getTitle(), b.getTitle())) to_items.sort(lambda a,b: cmp(a.getTitle(), b.getTitle())) through_items.sort(lambda a,b: cmp(a.getTitle(), b.getTitle())) ret = { "conn_type" : conn_type, "from_widget" : from_widget, "to_widget" : to_widget, "from_items" : from_items, "to_items" : to_items, "through_items" : through_items, } return ret
def updateConnType(request, conn_type, vals): title = vals["title"] from_cid = int(vals["from_cid"]) from_id = int(vals["from_id"]) to_cid = int(vals["to_cid"]) to_id = int(vals["to_id"]) conn_type["readable_name"] = title conn_type.save() from_dev = getFirstOrNone(conn_type.getNeighboursFrom(filter_func=getFilterNeighboursByClassName(request.configuration, "device_type"))) to_dev = getFirstOrNone(conn_type.getNeighboursTo(filter_func=getFilterNeighboursByClassName(request.configuration, "device_type"))) if (from_dev and from_dev.getId()==(from_cid, from_id) and to_dev and to_dev.getId()==(to_cid, to_id)): return HttpResponse("Ok. Relations not changed") through_items = conn_type.getNeighbours(filter_func=getFilterNeighboursByClassName(request.configuration, "connection_type_part")) for item in through_items: item.delete() old_relations = request.configuration.getAllRelations(conn_type, load_instances=True) for rel in old_relations: rel.delete() if from_cid!=0 and from_id!=0: from_entity = request.configuration.loadEntity(from_cid, from_id) rel_from = request.configuration.makeRelation("logical", from_entity, conn_type) rel_from.save() if to_cid!=0 and to_id!=0: to_entity = request.configuration.loadEntity(to_cid, to_id) rel_to = request.configuration.makeRelation("logical", conn_type, to_entity) rel_to.save() return HttpResponse("Ok. Relations erased")
def index(request): recent_id = None if "recent_id" in request.GET: recent_id = int(request.GET["recent_id"]) from_widget = GetHtmlEntityIdSelector(request, "from", cids_or_cnames_list=["device_type"], submit_form_on_select=False) to_widget = GetHtmlEntityIdSelector(request, "to", cids_or_cnames_list=["device_type"], submit_form_on_select=False) connection_types_list = request.configuration.getAllEntities("connection_type", load_instances=True) connection_types = [] for conn_type in connection_types_list: t_conn_type = { "title" : conn_type.getTitle(), "cid" : conn_type.cid, "id" : conn_type.id, "from" : getFirstOrNone(conn_type.getNeighboursFrom(filter_func=getFilterNeighboursByClassName(request.configuration, "device_type"))), "to" : getFirstOrNone(conn_type.getNeighboursTo(filter_func=getFilterNeighboursByClassName(request.configuration, "device_type"))), "is_recent" : recent_id==conn_type.id } connection_types += [t_conn_type] def sort_func(a,b): return cmp(a["title"], b["title"]) connection_types.sort(sort_func) return {"from_widget" : from_widget, "to_widget" : to_widget, "connection_types" : connection_types}
def show_ioc(request, ioc_name): psc_list = [] iocs = request.configuration.getAllEntities("ioc", filter_func=lambda ent: (ent["name"] == ioc_name)) if len(iocs) != 1: raise Exception("Wrong IOC count. Found %s IOCs with name '%s'" % (len(iocs), ioc_name)) ioc = iocs[0] tmpl = "nsls_tools/db/ioc/" + ioc["template"] blocks = {} for i in range(0,101): blocks[i] = [] devices = ioc.getNeighbours(filter_func=getFilterNeighboursByClassName(request.configuration, "device")) for device in devices: proxy_device = ProxyDevice(device) dev_type = getFirstOrNone(device.getNeighbours(filter_func=getFilterNeighboursByClassName(request.configuration, "device_type"))) tmpl_dir_name = dev_type["template"] tmpl_dir_short = "nsls_tools/db/devices/" + tmpl_dir_name tmpl_dir_full = settings.PROJECT_DIR + "/nsls_tools/templates/" + tmpl_dir_short for dirname, dirnames, filenames in os.walk(tmpl_dir_full): for filename in filenames: bin = int(filename.split(".")[0]) rendered_str = render_to_string(tmpl_dir_short+"/"+filename, {"proxy" : proxy_device}) blocks[bin] += ["\n%s\n" % rendered_str] #psc_list += [t_dummy_device] return render_to_response(tmpl, {"ioc" : ioc, "blocks" : blocks}, context_instance=RequestContext(request))
def get_config_device(request, device): ret = "" ret += device.getTitle() + '\n' device_type = getFirstOrNone(device.getNeighbours(filter_func=getFilterNeighboursByClassName(request.configuration, "device_type"))) ret += device_type.getTitle() + '\n' channels = device_type.getNeighbours(filter_func=getFilterNeighboursByClassName(request.configuration, "channel")) ret += "Channel count = " + str(len(channels)) + '\n' for channel in channels: ret += get_config_channel(request, channel) return ret
def get_config_device(request, device): ret = "" ret += device.getTitle() + '\n' device_type = getFirstOrNone( device.getNeighbours(filter_func=getFilterNeighboursByClassName( request.configuration, "device_type"))) ret += device_type.getTitle() + '\n' channels = device_type.getNeighbours( filter_func=getFilterNeighboursByClassName(request.configuration, "channel")) ret += "Channel count = " + str(len(channels)) + '\n' for channel in channels: ret += get_config_channel(request, channel) return ret
def show_ioc(request, ioc_name): psc_list = [] iocs = request.configuration.getAllEntities("ioc", filter_func=lambda ent: (ent["name"] == ioc_name)) if len(iocs) != 1: raise Exception("Wrong IOC count. Found %s IOCs with name '%s'" % (len(iocs), ioc_name)) ioc = iocs[0] tmpl = "nsls_tools/db/ioc/" + ioc["template"] blocks = {} for i in range(0, 101): blocks[i] = [] devices = ioc.getNeighbours(filter_func=getFilterNeighboursByClassName( request.configuration, "device")) for device in devices: proxy_device = ProxyDevice(device) dev_type = getFirstOrNone( device.getNeighbours(filter_func=getFilterNeighboursByClassName( request.configuration, "device_type"))) tmpl_dir_name = dev_type["template"] tmpl_dir_short = "nsls_tools/db/devices/" + tmpl_dir_name tmpl_dir_full = settings.PROJECT_DIR + "/nsls_tools/templates/" + tmpl_dir_short for dirname, dirnames, filenames in os.walk(tmpl_dir_full): for filename in filenames: bin = int(filename.split(".")[0]) rendered_str = render_to_string( tmpl_dir_short + "/" + filename, {"proxy": proxy_device}) blocks[bin] += ["\n%s\n" % rendered_str] #psc_list += [t_dummy_device] return render_to_response(tmpl, { "ioc": ioc, "blocks": blocks }, context_instance=RequestContext(request))