How to use the mongoengine.fields.StringField function in mongoengine

To help you get started, we’ve selected a few mongoengine examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github nocproject / noc / inv / models / networksegmentprofile.py View on Github external
("maxaddr", "Greater Management Address"),
        ]
    )
    is_active = BooleanField(default=True)


@bi_sync
@on_delete_check(
    check=[("inv.NetworkSegment", "profile"), ("inv.NetworkSegmentProfile", "autocreated_profile")]
)
@on_save
@six.python_2_unicode_compatible
class NetworkSegmentProfile(Document):
    meta = {"collection": "noc.networksegmentprofiles", "strict": False, "auto_create_index": False}

    name = StringField(unique=True)
    description = StringField(required=False)
    # segment discovery interval
    discovery_interval = IntField(default=86400)
    # Segment style
    style = ForeignKeyField(Style, required=False)
    # Restrict MAC discovery to management vlan
    mac_restrict_to_management_vlan = BooleanField(default=False)
    # Management vlan, to restrict MAC search for MAC topology discovery
    management_vlan = IntField(required=False, min_value=1, max_value=4095)
    # MVR VLAN
    multicast_vlan = IntField(required=False, min_value=1, max_value=4095)
    # Detect lost redundancy condition
    enable_lost_redundancy = BooleanField(default=False)
    # Horizontal transit policy
    horizontal_transit_policy = StringField(
        choices=[("E", "Always Enable"), ("C", "Calculate"), ("D", "Disable")], default="D"
github nocproject / noc / vc / models / vlanprofile.py View on Github external
from noc.core.mongo.fields import PlainReferenceField, ForeignKeyField
from noc.core.bi.decorator import bi_sync
from noc.core.model.decorator import on_delete_check

id_lock = Lock()


@bi_sync
@on_delete_check(
    check=[("vc.VLAN", "profile"), ("inv.NetworkSegmentProfile", "default_vlan_profile")]
)
@six.python_2_unicode_compatible
class VLANProfile(Document):
    meta = {"collection": "vlanprofiles", "strict": False, "auto_create_index": False}

    name = StringField(unique=True)
    description = StringField()
    # VLAN is management VLAN
    enable_management = BooleanField(default=False)
    # VLAN is multicast VLAN
    enable_multicast = BooleanField(default=False)
    # VLAN should be automatically provisioned
    enable_provisioning = BooleanField(default=False)
    # VLAN workflow
    workflow = PlainReferenceField(Workflow)
    style = ForeignKeyField(Style)
    tags = ListField(StringField())
    # Integration with external NRI and TT systems
    # Reference to remote system object has been imported from
    remote_system = PlainReferenceField(RemoteSystem)
    # Object id in remote system
    remote_id = StringField()
github nocproject / noc / ip / models / prefixprofile.py View on Github external
# Enable nested prefix prefix discovery
    enable_prefix_discovery = BooleanField(default=False)
    # Prefix workflow
    workflow = PlainReferenceField(Workflow)
    style = ForeignKeyField(Style)
    # Template.subject to render Prefix.name
    name_template = ForeignKeyField(Template)
    # Discovery policies
    prefix_discovery_policy = StringField(choices=[("E", "Enable"), ("D", "Disable")], default="D")
    address_discovery_policy = StringField(choices=[("E", "Enable"), ("D", "Disable")], default="D")
    # Send seen event to parent
    seen_propagation_policy = StringField(
        choices=[("P", "Propagate"), ("E", "Enable"), ("D", "Disable")], default="P"
    )
    # Include/Exclude broadcast & network addresses from prefix
    prefix_special_address_policy = StringField(
        choices=[("I", "Include"), ("X", "Exclude")], default="X"
    )
    #
    tags = ListField(StringField())
    # Integration with external NRI and TT systems
    # Reference to remote system object has been imported from
    remote_system = PlainReferenceField(RemoteSystem)
    # Object id in remote system
    remote_id = StringField()
    # Object id in BI
    bi_id = LongField(unique=True)

    _id_cache = cachetools.TTLCache(maxsize=100, ttl=60)
    _bi_id_cache = cachetools.TTLCache(maxsize=100, ttl=60)

    def __str__(self):
github materialsproject / MPContribs / mpcontribs-api / mpcontribs / api / tables / document.py View on Github external
# -*- coding: utf-8 -*-
import json
from hashlib import md5
from flask_mongoengine import DynamicDocument
from mongoengine import signals
from mongoengine.fields import StringField, ListField, IntField


class Tables(DynamicDocument):
    name = StringField(required=True, help_text="name")
    columns = ListField(StringField(), required=True, help_text="column names")
    data = ListField(ListField(StringField()), required=True, help_text="table rows")
    md5 = StringField(regex=r"^[a-z0-9]{32}$", unique=True, help_text="md5 sum")
    total_data_rows = IntField(help_text="total number of rows")
    meta = {"collection": "tables", "indexes": ["name", "columns", "md5"]}

    @classmethod
    def pre_save_post_validation(cls, sender, document, **kwargs):
        from mpcontribs.api.tables.views import TablesResource

        resource = TablesResource()
        d = resource.serialize(document, fields=["columns", "data"])
        s = json.dumps(d, sort_keys=True).encode("utf-8")
        document.md5 = md5(s).hexdigest()
        document.total_data_rows = len(document.data)


signals.pre_save_post_validation.connect(Tables.pre_save_post_validation, sender=Tables)
github nocproject / noc / main / models / textindex.py View on Github external
"fields": ["$title", "$content", "$tags"],
                "default_language": "english",
                "language_override": "language",
                "weights": {"title": 10, "tags": 5, "content": 1},
            },
        ],
    }

    # model name, like 'sa.ManagedObject'
    model = StringField()
    # Object id, converted to string
    object = StringField()
    # Short title
    title = StringField()
    # Content to search
    content = StringField()
    # Card to show in search result
    card = StringField()
    # List of tags
    tags = ListField(StringField())
    # Date of last changed
    changed = DateTimeField()
    #
    language = StringField(default="english")

    rx_phrases = re.compile(r"(\d+(?:[-_.:]\d+)+)")

    def __str__(self):
        return "%s:%s" % (self.model, self.object)

    def get_object(self):
        """
github nocproject / noc / ip / models / addressprofile.py View on Github external
# Address workflow
    workflow = PlainReferenceField(Workflow)
    style = ForeignKeyField(Style)
    # Template.subject to render Address.name
    name_template = ForeignKeyField(Template)
    # Template.subject to render Address.fqdn
    fqdn_template = ForeignKeyField(Template)
    # Send seen event to prefix
    seen_propagation_policy = StringField(choices=[("E", "Enable"), ("D", "Disable")], default="D")
    #
    tags = ListField(StringField())
    # Integration with external NRI and TT systems
    # Reference to remote system object has been imported from
    remote_system = PlainReferenceField(RemoteSystem)
    # Object id in remote system
    remote_id = StringField()
    # Object id in BI
    bi_id = LongField(unique=True)

    _id_cache = cachetools.TTLCache(maxsize=100, ttl=60)
    _name_cache = cachetools.TTLCache(maxsize=100, ttl=60)
    _bi_id_cache = cachetools.TTLCache(maxsize=100, ttl=60)

    def __str__(self):
        return self.name

    @classmethod
    @cachetools.cachedmethod(operator.attrgetter("_id_cache"), lock=lambda _: id_lock)
    def get_by_id(cls, id):
        return AddressProfile.objects.filter(id=id).first()

    @classmethod
github nocproject / noc / cm / models / objectfact.py View on Github external
# NOC modules
from noc.sa.models.managedobject import ManagedObject
from noc.core.mongo.fields import ForeignKeyField


class ObjectFact(Document):
    meta = {
        "collection": "noc.objectfacts",
        "strict": False,
        "auto_create_index": False,
        "indexes": ["object", "attrs.rule"],
    }
    uuid = UUIDField(binary=True, primary_key=True)
    object = ForeignKeyField(ManagedObject)
    cls = StringField()
    label = StringField()
    attrs = DictField()
    introduced = DateTimeField(default=datetime.datetime.now)
    changed = DateTimeField(default=datetime.datetime.now)

    def __str__(self):
        return self.object.name
github nocproject / noc / inv / models / l3link.py View on Github external
Network L3 links.
    Always contains a list of subinterface references
    """

    meta = {
        "collection": "noc.links",
        "strict": False,
        "auto_create_index": False,
        "indexes": ["subinterfaces", "linked_objects"],
    }

    subinterfaces = PlainReferenceListField("inv.SubInterface")
    # List of linked objects
    linked_objects = ListField(IntField())
    # Name of discovery method or "manual"
    discovery_method = StringField()
    # Timestamp of first discovery
    first_discovered = DateTimeField(default=datetime.datetime.now)
    # Timestamp of last confirmation
    last_seen = DateTimeField()
    # L3 path cost
    l3_cost = IntField(default=1)

    def __str__(self):
        return "(%s)" % ", ".join([smart_text(i) for i in self.subinterfaces])

    def clean(self):
        self.linked_objects = sorted(set(i.managed_object.id for i in self.subinterfaces))
        super(L3Link, self).clean()
github nocproject / noc / vc / models / vcdomainprofile.py View on Github external
id_lock = Lock()


@bi_sync
@on_delete_check(check=[
    ("vc.VCDomain", "profile")
])
class VCDomainProfile(Document):
    meta = {
        "collection": "vcdomainprofiles",
        "strict": False,
        "auto_create_index": False
    }

    name = StringField(unique=True)
    description = StringField()
    # Permit VLAN discovery
    enable_vlan_discovery = BooleanField(default=False)
    # Style
    style = ForeignKeyField(Style)
    # Workflow
    workflow = PlainReferenceField(Workflow)
    # Integration with external NRI and TT systems
    # Reference to remote system object has been imported from
    remote_system = PlainReferenceField(RemoteSystem)
    # Object id in remote system
    remote_id = StringField()
    # Object id in BI
    bi_id = LongField(unique=True)

    _id_cache = cachetools.TTLCache(maxsize=100, ttl=60)
    _bi_id_cache = cachetools.TTLCache(maxsize=100, ttl=60)
github hack4impact-uiuc / safe-maps / backend / api / models / Crime.py View on Github external
from mongoengine.fields import StringField, DateTimeField, FloatField, IntField
from api.models.Location import Location
from api.models.OpenHours import OpenHours
import mongoengine
from mongoengine import *
import datetime

# DynamicDocument allows for unspecified fields to be put in as well
class Crime(mongoengine.DynamicDocument):
    """Crime Document Schema"""

    incident_id = StringField(required=True, unique=True)
    incident_datetime = StringField(required=True)
    incident_type_primary = StringField(required=True)
    incident_description = StringField(required=True)
    address_1 = StringField(required=True)
    city = StringField(required=True)
    state = StringField(required=True)
    latitude = FloatField(required=True)
    longitude = FloatField(required=True)
    hour_of_day = IntField(required=True)
    day_of_week = StringField(required=True)
    parent_incident_type = StringField(required=True)
    duration = IntField(required=False)