Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
from rest_framework_mongoengine.serializers import DocumentSerializer
from rest_framework_mongoengine.validators import (
UniqueTogetherValidator, UniqueValidator
)
from .utils import dedent
class NonValidatingModel(Document):
name = fields.StringField()
code = fields.IntField()
class UniqueValidatingModel(Document):
name = fields.StringField(unique=True)
code = fields.IntField()
class NullValidatingModel(Document):
name = fields.StringField()
code = fields.IntField(null=True)
other = fields.StringField(null=True)
# Tests for explicit `UniqueValidator`
# ------------------------------------
class UniqueValidatorSerializer(DocumentSerializer):
class Meta:
model = NonValidatingModel
fields = '__all__'
return super(ActivatorModelManager, self).get_query_set().filter(status=1)
def inactive(self):
""" Returns inactive instances of ActivatorModel: SomeModel.objects.inactive() """
return super(ActivatorModelManager, self).get_query_set().filter(status=0)
class ActivatorModel(Document):
""" ActivatorModel
An abstract base class model that provides activate and deactivate fields.
"""
STATUS_CHOICES = (
(0, _('Inactive')),
(1, _('Active')),
)
status = IntField(_('status'), choices=STATUS_CHOICES, default=1)
activate_date = DateTimeField(blank=True, null=True, help_text=_('keep empty for an immediate activation'))
deactivate_date = DateTimeField(blank=True, null=True, help_text=_('keep empty for indefinite activation'))
objects = ActivatorModelManager()
class Meta:
abstract = True
def save(self, *args, **kwargs):
if not self.activate_date:
self.activate_date = datetime.datetime.now()
super(ActivatorModel, self).save(*args, **kwargs)
("project.Project", "shape_overlay_glyph"),
("sa.ManagedObject", "shape_overlay_glyph"),
("sa.ManagedObjectProfile", "shape_overlay_glyph"),
]
)
class Glyph(Document):
meta = {
"collection": "glyphs",
"strict": False,
"auto_create_index": False,
"json_collection": "main.glyphs",
}
name = StringField(unique=True)
uuid = UUIDField(unique=True, binary=True)
font = PlainReferenceField(Font)
code = IntField()
_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: Union[str, bson.ObjectId]) -> "Glyph":
return Glyph.objects.filter(id=id).first()
@property
def json_data(self):
return {
"name": self.name,
"$collection": self._meta["json_collection"],
# (C) 2017 The MITRE Corporation.
from mongoengine.document import Document, EmbeddedDocument
from mongoengine.fields import DictField, StringField, ListField, URLField, ReferenceField, IntField
from data_model.event import DataModelEvent
import requests
attack_url = 'https://attack-old.mitre.org'
proxies = {}
class AttackTactic(Document):
name = StringField()
url = URLField()
description = StringField()
order = IntField()
class AttackTechnique(Document):
tactics = ListField(ReferenceField(AttackTactic))
technique_id = StringField(unique=True)
name = StringField()
description = StringField()
url = URLField()
class TechniqueMapping(EmbeddedDocument):
LOW = 'Low'
MODERATE = 'Moderate'
HIGH = 'High'
technique = ReferenceField(AttackTechnique)
from mongoengine import Document
from mongoengine.fields import IntField, StringField, DateTimeField,\
BooleanField, BinaryField, ReferenceField
from luckycat.database.models.User import User
class Job(Document):
name = StringField()
description = StringField()
date = DateTimeField()
maximum_samples = IntField()
maximum_iteration = IntField()
timeout = IntField()
enabled = BooleanField()
archived = BooleanField()
mutation_engine = StringField()
fuzzer = StringField()
verifier = StringField()
samples = BinaryField()
firmware_root = BinaryField()
fuzzing_target = BinaryField()
cmd_args = StringField()
owner = ReferenceField(User)
)
elif self.type == "bool":
return models.BooleanField(name=name, db_column=self.db_column, default=False)
elif self.type == "date":
return models.DateField(name=name, db_column=self.db_column, null=True, blank=True)
elif self.type == "datetime":
return models.DateTimeField(
name=name, db_column=self.db_column, null=True, blank=True
)
else:
raise NotImplementedError
else:
if self.type == "str":
return fields.StringField(db_field=self.db_column, required=False)
elif self.type == "int":
return fields.IntField(db_field=self.db_column, required=False)
elif self.type == "bool":
return fields.BooleanField(db_field=self.db_column, required=False)
elif self.type in ("date", "datetime"):
return fields.DateTimeField(db_field=self.db_column, required=False)
else:
raise NotImplementedError
class AlarmClassConfig(Document):
"""
Alarm class
"""
meta = {
"collection": "noc.alarmclassconfigs",
"strict": False,
"auto_create_index": False
}
alarm_class = PlainReferenceField(AlarmClass, unique=True)
notification_delay = IntField(required=False)
control_time0 = IntField(required=False)
control_time1 = IntField(required=False)
control_timeN = IntField(required=False)
def __unicode__(self):
return self.alarm_class.name
# Third-party modules
import six
from mongoengine.document import Document, EmbeddedDocument
from mongoengine.fields import StringField, UUIDField, IntField, ListField, EmbeddedDocumentField
# NOC modules
from noc.core.prettyjson import to_json
@six.python_2_unicode_compatible
class DashboardCell(EmbeddedDocument):
name = StringField()
# Row number
row = IntField(min_value=0)
# Height
height = IntField()
# Extra small devices columns (Phones, <768px)
xs = IntField()
# Small devices columns (Tablets, <992px)
sm = IntField()
# Medium devices (Desktop, <1200px)
md = IntField()
# Large devices (Desktop, > 1200px)
lg = IntField()
def __str__(self):
return self.name
def to_json(self, *args, **kwargs):
return {
"name": self.name,
"row": self.row,
"indexes": ["parent", "data", "name"]
}
# Division type
type = StringField(default="A", choices=[
("A", "Administrative")
])
#
parent = PlainReferenceField("self")
# Normalized name
name = StringField()
# street/town/city, etc
short_name = StringField()
#
is_active = BooleanField(default=True)
# Division level
level = IntField()
# Additional data
# Depends on importer
data = DictField()
#
start_date = DateTimeField()
end_date = DateTimeField()
def __unicode__(self):
if self.short_name:
return "%s, %s" % (self.name, self.short_name)
else:
return self.name
def get_children(self):
return Division.objects.filter(parent=self.id)