Ejemplo n.º 1
0
 def load_custom_properties(self):
     filepath = self.config["paths"]["custom_properties"]
     if not filepath:
         custom_properties = {}
     else:
         with open(filepath, "r") as properties:
             custom_properties = yaml.load(properties)
     property_names.update(
         {k: v["pretty_name"]
          for k, v in custom_properties.items()})
     public_custom_properties = {
         k: v
         for k, v in custom_properties.items()
         if not v.get("private", False)
     }
     device_properties.extend(list(custom_properties))
     pool_device_properties.extend(list(public_custom_properties))
     for properties_table in table_properties, filtering_properties:
         properties_table["device"].extend(list(public_custom_properties))
     device_diagram_properties.extend(
         list(p for p, v in custom_properties.items()
              if v["add_to_dashboard"]))
     private_properties.extend(
         list(p for p, v in custom_properties.items()
              if v.get("private", False)))
     return custom_properties
Ejemplo n.º 2
0
Archivo: base.py Proyecto: blaisep/eNMS
 def load_custom_properties(self):
     for model, values in self.properties["custom"].items():
         property_names.update({k: v["pretty_name"] for k, v in values.items()})
         model_properties[model].extend(list(values))
         private_properties.extend(
             list(p for p, v in values.items() if v.get("private", False))
         )
Ejemplo n.º 3
0
 def __new__(cls: type, name: str, bases: tuple, attrs: dict) -> FlaskForm:
     form: FlaskForm = type.__new__(cls, name, bases, attrs)
     if name == "BaseForm":
         return form
     form_type = form.form_type.kwargs["default"]
     form_classes[form_type] = form
     form_templates[form_type] = getattr(form, "template", "base")
     form_actions[form_type] = getattr(form, "action", None)
     properties = {
         field_name: field_types[field.field_class]
         for field_name, field in attrs.items()
         if isinstance(field, UnboundField)
         and field.field_class in field_types
     }
     property_names.update({
         field_name: field.args[0]
         for field_name, field in attrs.items()
         if isinstance(field, UnboundField) and field.args
     })
     form_properties[form_type].update(properties)
     property_types.update(properties)
     for base in form.__bases__:
         if not hasattr(base, "form_type"):
             continue
         base_form_type = base.form_type.kwargs["default"]
         if base_form_type == "service":
             form.service_fields = list(properties)
         if getattr(base, "abstract_service", False):
             form.service_fields.extend(form_properties[base_form_type])
         form_properties[form_type].update(form_properties[base_form_type])
     return form
Ejemplo n.º 4
0
Archivo: base.py Proyecto: ammoam/eNMS
 def load_custom_properties(self) -> dict:
     filepath = environ.get("PATH_CUSTOM_PROPERTIES")
     if not filepath:
         custom_properties: dict = {}
     else:
         with open(filepath, "r") as properties:
             custom_properties = load(properties, Loader=BaseLoader)
     property_names.update(
         {k: v["pretty_name"]
          for k, v in custom_properties.items()})
     for object_properties in (device_properties, pool_device_properties):
         object_properties.extend(list(custom_properties))
     for properties_table in table_properties, filtering_properties:
         properties_table["device"].extend(list(custom_properties))
     device_diagram_properties.extend(
         list(p for p, v in custom_properties.items()
              if v["add_to_dashboard"]))
     return custom_properties
Ejemplo n.º 5
0
 def __new__(cls, name, bases, attrs):
     form: FlaskForm = type.__new__(cls, name, bases, attrs)
     if name == "BaseForm":
         return form
     form_type = form.form_type.kwargs["default"]
     form_classes[form_type] = form
     form_templates[form_type] = getattr(form, "template", "base")
     form_actions[form_type] = getattr(form, "action", None)
     properties = {
         field_name: {
             "type": field_types[field.field_class],
             "model": field.kwargs.pop("model", None),
         }
         for field_name, field in attrs.items()
         if isinstance(field, UnboundField) and field.field_class in field_types
     }
     property_names.update(
         {
             field_name: field.args[0]
             for field_name, field in attrs.items()
             if isinstance(field, UnboundField)
             and field.args
             and isinstance(field.args[0], str)
         }
     )
     form_properties[form_type].update(properties)
     for property, value in properties.items():
         if property not in property_types:
             property_types[property] = value["type"]
     for base in form.__bases__:
         if not hasattr(base, "form_type"):
             continue
         base_form_type = base.form_type.kwargs["default"]
         if base_form_type == "service":
             form.service_fields = list(properties)
         if getattr(base, "abstract_service", False):
             form.service_fields.extend(form_properties[base_form_type])
         form_properties[form_type].update(form_properties[base_form_type])
     return form