def init_solutions(): """ Initialize solutions and load modules """ from noc.main.models import CustomField CustomField.install_fields() for sn in config.options("solutions"): if config.getboolean("solutions", sn): load_solution(sn)
def get_data(self, vrf, afi, prefix, **kwargs): def get_row(p, level=0): s = "--" * level r = [s + p.prefix, p.state.name, unicode(p.vc) if p.vc else ""] for f in cf: v = getattr(p, f.name) r += [v if v is not None else ""] r += [p.description, p] return r def get_info(prefix, level=0): data = [get_row(prefix, level)] for c in prefix.children_set.order_by("prefix"): data += get_info(c, level + 1) return data cf = CustomField.table_fields("ip_prefix") # Prepare columns columns = ["Prefix", "State", "VC"] for f in cf: columns += [f.label] columns += ["Description", TableColumn(_("Tags"), format="tags")] data = get_info(prefix) return self.from_dataset(title=_( "All allocated blocks in VRF %(vrf)s (IPv%(afi)s), %(prefix)s" % { "vrf": vrf.name, "afi": afi, "prefix": prefix.prefix }), columns=columns, data=data, enumerate=True)
def apply_custom_fields(self, o, v, table): """ Apply custom fields to form :param o: Object :param v: values dict :param table: table :return: """ from noc.main.models import CustomField for f in CustomField.table_fields(table): n = str(f.name) if n in v: setattr(o, n, v[n]) return o
def apply_custom_initial(self, o, v, table): """ :param o: Object :param v: Initial data :param table: table :return: """ from noc.main.models import CustomField for f in CustomField.table_fields(table): n = str(f.name) if n not in v: x = getattr(o, n) if x: v[n] = x return o
def get_data(self, vrf, afi, prefix, **kwargs): def get_row(p): r = [p.prefix, p.state.name, unicode(p.vc) if p.vc else ""] for f in cf: v = getattr(p, f.name) r += [v if v is not None else ""] r += [p.description, p] return r cf = CustomField.table_fields("ip_prefix") cfn = dict((f.name, f) for f in cf) # Prepare columns columns = [ "Prefix", "State", "VC" ] for f in cf: columns += [f.label] columns += [ "Description", TableColumn(_("Tags"), format="tags") ] # Prepare query q = Q() for k in kwargs: v = kwargs[k] if k in cfn and v is not None and v != "": q &= Q(**{str(k): v}) # return self.from_dataset(title=_( "Allocated blocks in VRF %(vrf)s (IPv%(afi)s), %(prefix)s" % { "vrf": vrf.name, "afi": afi, "prefix": prefix.prefix }), columns=columns, data=[get_row(p) for p in prefix.children_set.filter(q).order_by("prefix")], enumerate=True)
def get_data(self, **kwargs): def get_row(p): r = [p.vrf.name, p.prefix, p.state.name, unicode(p.asn), unicode(p.vc) if p.vc else ""] for f in cf: v = getattr(p, f.name) r += [v if v is not None else ""] r += [p.description, p] return r q = {} for k in kwargs: v = kwargs[k] if v: if k == "description": q[k + "__icontains"] = v else: q[k] = v columns = ["VRF", "Prefix", "State", "AS", "VC"] cf = CustomField.table_fields("ip_prefix") for f in cf: if f.type == "bool": columns += [TableColumn(f.label, format="bool")] else: columns += [f.label] columns += [ "Description", TableColumn(_("Tags"), format="tags") ] data = [get_row(p) for p in Prefix.objects.filter(**q)\ .exclude(prefix="0.0.0.0/0")\ .exclude(prefix="::/0")\ .order_by("vrf__name", "prefix").select_related()] return self.from_dataset( title=self.title, columns=columns, data=data )
def customize_form(self, form, table, search=False): """ Add custom fields to django form class """ from noc.main.models import CustomField l = [] for f in CustomField.table_fields(table): if f.is_hidden: continue if f.type == "str": if search and f.is_filtered: ff = forms.ChoiceField(required=False, label=f.label, choices=[("", "---")] + f.get_choices()) elif f.enum_group: ff = forms.ChoiceField(required=False, label=f.label, choices=[("", "---")] + f.get_enums()) else: ml = f.max_length if f.max_length else 256 ff = forms.CharField(required=False, label=f.label, max_length=ml) elif f.type == "int": ff = forms.IntegerField(required=False, label=f.label) elif f.type == "bool": ff = forms.BooleanField(required=False, label=f.label) elif f.type == "date": ff = forms.DateField(required=False, label=f.label) elif f.type == "datetime": ff = forms.DateTimeField(required=False, label=f.label) else: raise ValueError("Invalid field type: '%s'" % f.type) l += [(str(f.name), ff)] form.base_fields.update(SortedDict(l)) return form
#!./bin/python # -*- coding: utf-8 -*- ##---------------------------------------------------------------------- ## noc-wf daemon ##---------------------------------------------------------------------- ## Copyright (C) 2007-2011 The NOC Project ## See LICENSE for details ##---------------------------------------------------------------------- if __name__ == "__main__": from noc.wf.wf.daemon import WFDaemon from noc.lib.debug import error_report from noc.main.models import CustomField CustomField.install_fields() try: WFDaemon().process_command() except SystemExit: pass except Exception: error_report()
def get_custom_fields(self): from noc.main.models import CustomField return list(CustomField.table_fields(self.model._meta.db_table))
# --------------------------------------------------------------------- # Copyright (C) 2007-2018 The NOC Project # See LICENSE for details # --------------------------------------------------------------------- # Third-party modules from django.db import connection # NOC modules from noc.lib.app.reportapplication import ReportApplication from noc.main.models import CustomField from noc.ip.models.vrfgroup import VRFGroup from noc.ip.models.prefix import Prefix from noc.core.ip import IP prefix_fields = [ f for f in CustomField.table_fields("ip_prefix") if not f.is_hidden ] # % fixme rewrite to separate file CSS = """ <style> TABLE { border-spacing: 8px; } TABLE TR TD { border: none; } .block { padding: 8px;