Commit 8e93dd1d authored by Dmitry Volodin's avatar Dmitry Volodin Committed by Andrey Vertiprahov
Browse files

Model __str__ methods

parent 0bb9bcaa
......@@ -2,13 +2,14 @@
# ----------------------------------------------------------------------
# Dashboard storage
# ----------------------------------------------------------------------
# Copyright (C) 2007-2018 The NOC Project
# Copyright (C) 2007-2019 The NOC Project
# See LICENSE for details
# ----------------------------------------------------------------------
# Python modules
import datetime
# Third-party modules
import six
from mongoengine.document import Document, EmbeddedDocument
from mongoengine.fields import (StringField, DateTimeField, ListField,
IntField, BinaryField, EmbeddedDocumentField)
......@@ -32,6 +33,7 @@ class DashboardAccess(EmbeddedDocument):
])
@six.python_2_unicode_compatible
class Dashboard(Document):
meta = {
"collection": "noc.dashboards",
......@@ -59,7 +61,7 @@ class Dashboard(Document):
#
access = ListField(EmbeddedDocumentField(DashboardAccess))
def __unicode__(self):
def __str__(self):
return self.title
def get_user_access(self, user):
......@@ -74,7 +76,7 @@ class Dashboard(Document):
if ar.group and ar.group in groups:
level = max(level, ar.level)
if level == DAL_ADMIN:
return level
return level
return level
def save(self, force_insert=False, validate=True, clean=True,
......
......@@ -2,17 +2,20 @@
# ----------------------------------------------------------------------
# Dashboard Layout
# ----------------------------------------------------------------------
# Copyright (C) 2007-2016 The NOC Project
# Copyright (C) 2007-2019 The NOC Project
# See LICENSE for details
# ----------------------------------------------------------------------
# Third-party modules
import six
from mongoengine.document import Document, EmbeddedDocument
from mongoengine.fields import (StringField, UUIDField, IntField,
ListField, EmbeddedDocumentField)
# NOC modules
from noc.lib.prettyjson import to_json
@six.python_2_unicode_compatible
class DashboardCell(EmbeddedDocument):
name = StringField()
# Row number
......@@ -28,7 +31,7 @@ class DashboardCell(EmbeddedDocument):
# Large devices (Desktop, > 1200px)
lg = IntField()
def __unicode__(self):
def __str__(self):
return self.name
def to_json(self, *args, **kwargs):
......@@ -43,6 +46,7 @@ class DashboardCell(EmbeddedDocument):
}
@six.python_2_unicode_compatible
class DashboardLayout(Document):
meta = {
"collection": "noc.dashboardlayouts",
......@@ -57,7 +61,7 @@ class DashboardLayout(Document):
# @todo: Add preview
cells = ListField(EmbeddedDocumentField(DashboardCell))
def __unicode__(self):
def __str__(self):
return self.name
def to_json(self):
......
......@@ -2,13 +2,14 @@
# ---------------------------------------------------------------------
# Error Types
# ---------------------------------------------------------------------
# Copyright (C) 2007-2015 The NOC Project
# Copyright (C) 2007-2019 The NOC Project
# See LICENSE for details
# ---------------------------------------------------------------------
# Python modules
import os
# Third-party modules
import six
from mongoengine.document import Document
from mongoengine.fields import StringField, UUIDField
# NOC modules
......@@ -16,6 +17,7 @@ from noc.lib.prettyjson import to_json
from noc.lib.text import quote_safe_path
@six.python_2_unicode_compatible
class ErrorType(Document):
meta = {
"collection": "noc.errortypes",
......@@ -29,7 +31,7 @@ class ErrorType(Document):
subject_template = StringField()
body_template = StringField()
def __unicode__(self):
def __str__(self):
return self.name
def get_json_path(self):
......
......@@ -2,13 +2,14 @@
# ---------------------------------------------------------------------
# Object Facts
# ---------------------------------------------------------------------
# Copyright (C) 2007-2015 The NOC Project
# Copyright (C) 2007-2019 The NOC Project
# See LICENSE for details
# ---------------------------------------------------------------------
# Python modules
import datetime
# Third-party modules
import six
from mongoengine.document import Document
from mongoengine.fields import StringField, DictField, DateTimeField, UUIDField
# NOC modules
......@@ -16,6 +17,7 @@ from noc.sa.models.managedobject import ManagedObject
from noc.lib.nosql import ForeignKeyField
@six.python_2_unicode_compatible
class ObjectFact(Document):
meta = {
"collection": "noc.objectfacts",
......@@ -34,5 +36,5 @@ class ObjectFact(Document):
introduced = DateTimeField(default=datetime.datetime.now)
changed = DateTimeField(default=datetime.datetime.now)
def __unicode__(self):
def __str__(self):
return self.object.name
......@@ -2,11 +2,12 @@
# ---------------------------------------------------------------------
# Object notifications
# ---------------------------------------------------------------------
# Copyright (C) 2007-2018 The NOC Project
# Copyright (C) 2007-2019 The NOC Project
# See LICENSE for details
# ---------------------------------------------------------------------
# Third-party modules
import six
from django.db import models
# NOC modules
from noc.main.models.notificationgroup import NotificationGroup
......@@ -16,8 +17,9 @@ OBJECT_TYPES = ["config", "dns", "prefix-list", "rpsl"]
OBJECT_TYPE_CHOICES = [(x, x) for x in OBJECT_TYPES if x != "config"]
@six.python_2_unicode_compatible
class ObjectNotify(models.Model):
class Meta:
class Meta(object):
app_label = "cm"
db_table = "cm_objectnotify"
verbose_name = "Object Notify"
......@@ -32,6 +34,6 @@ class ObjectNotify(models.Model):
notification_group = models.ForeignKey(NotificationGroup,
verbose_name="Notification Group")
def __unicode__(self):
def __str__(self):
return u"(%s, %s, %s)" % (self.type, self.administrative_domain,
self.notification_group)
......@@ -2,27 +2,30 @@
# ---------------------------------------------------------------------
# Validation Policy
# ---------------------------------------------------------------------
# Copyright (C) 2007-2018 The NOC Project
# Copyright (C) 2007-2019 The NOC Project
# See LICENSE for details
# ---------------------------------------------------------------------
# Python modules
from __future__ import absolute_import
# Third-party modules
import six
from mongoengine.document import Document, EmbeddedDocument
from mongoengine.fields import EmbeddedDocumentField, StringField, BooleanField, ListField, ReferenceField
# NOC modules
from .validationrule import ValidationRule
@six.python_2_unicode_compatible
class RuleItem(EmbeddedDocument):
rule = ReferenceField(ValidationRule)
is_active = BooleanField(default=True)
def __unicode__(self):
def __str__(self):
return self.rule.name
@six.python_2_unicode_compatible
class ValidationPolicy(Document):
meta = {
"collection": "noc.validationpolicy",
......@@ -35,5 +38,5 @@ class ValidationPolicy(Document):
description = StringField()
rules = ListField(EmbeddedDocumentField(RuleItem))
def __unicode__(self):
def __str__(self):
return self.name
......@@ -2,13 +2,14 @@
# ---------------------------------------------------------------------
# Policy Settings
# ---------------------------------------------------------------------
# Copyright (C) 2007-2018 The NOC Project
# Copyright (C) 2007-2019 The NOC Project
# See LICENSE for details
# ---------------------------------------------------------------------
# Python modules
from __future__ import absolute_import
# Third-party modules
import six
from mongoengine.document import Document, EmbeddedDocument
from mongoengine.fields import (StringField, ReferenceField, ListField,
EmbeddedDocumentField, BooleanField)
......@@ -16,14 +17,16 @@ from mongoengine.fields import (StringField, ReferenceField, ListField,
from .validationpolicy import ValidationPolicy
@six.python_2_unicode_compatible
class ValidationPolicyItem(EmbeddedDocument):
policy = ReferenceField(ValidationPolicy)
is_active = BooleanField(default=True)
def __unicode__(self):
def __str__(self):
return self.policy.name
@six.python_2_unicode_compatible
class ValidationPolicySettings(Document):
meta = {
"collection": "noc.validationpolicysettings",
......@@ -35,5 +38,5 @@ class ValidationPolicySettings(Document):
object_id = StringField()
policies = ListField(EmbeddedDocumentField(ValidationPolicyItem))
def __unicode__(self):
def __str__(self):
return u"%s: %s" % (self.model_id, self.object_id)
......@@ -2,7 +2,7 @@
# ---------------------------------------------------------------------
# Validation Rule
# ---------------------------------------------------------------------
# Copyright (C) 2007-2018 The NOC Project
# Copyright (C) 2007-2019 The NOC Project
# See LICENSE for details
# ---------------------------------------------------------------------
......@@ -10,6 +10,7 @@
from __future__ import absolute_import
import logging
# Third-party modules
import six
from mongoengine.document import Document, EmbeddedDocument
from mongoengine.fields import (StringField, BooleanField, DictField,
ListField, EmbeddedDocumentField)
......@@ -33,22 +34,25 @@ ACTIONS = [
]
@six.python_2_unicode_compatible
class SelectorItem(EmbeddedDocument):
selector = ForeignKeyField(ManagedObjectSelector)
action = StringField(choices=ACTIONS)
def __unicode__(self):
def __str__(self):
return u"%s: %s" % (self.action, self.selector.name)
@six.python_2_unicode_compatible
class ObjectItem(EmbeddedDocument):
object = ForeignKeyField(ManagedObject)
action = StringField(choices=ACTIONS)
def __unicode__(self):
def __str__(self):
return u"%s: %s" % (self.action, self.object.name)
@six.python_2_unicode_compatible
class ValidationRule(Document):
meta = {
"collection": "noc.validationrules",
......@@ -64,7 +68,7 @@ class ValidationRule(Document):
handler = StringField()
config = DictField()
def __unicode__(self):
def __str__(self):
return self.name
def is_applicable_for(self, object):
......@@ -95,7 +99,7 @@ class ValidationRule(Document):
@classmethod
def on_delete(cls, sender, document, **kwargs):
from validationpolicy import ValidationPolicy
from noc.cm.models.validationpolicy import ValidationPolicy
logger.info("Deleting rule %s", document.name)
for vp in ValidationPolicy.objects.filter(rules__rule=document):
logger.info("Removing rule %s from policy %s",
......
......@@ -2,7 +2,7 @@
# ----------------------------------------------------------------------
# Subscriber
# ----------------------------------------------------------------------
# Copyright (C) 2007-2017 The NOC Project
# Copyright (C) 2007-2019 The NOC Project
# See LICENSE for details
# ----------------------------------------------------------------------
......@@ -11,6 +11,7 @@ from __future__ import absolute_import
from threading import Lock
import operator
# Third-party modules
import six
from mongoengine.document import Document
from mongoengine.fields import StringField, ListField, LongField
import cachetools
......@@ -28,6 +29,7 @@ id_lock = Lock()
@bi_sync
@workflow
@six.python_2_unicode_compatible
class Subscriber(Document):
meta = {
"collection": "noc.subscribers",
......@@ -59,7 +61,7 @@ class Subscriber(Document):
_id_cache = cachetools.TTLCache(maxsize=100, ttl=60)
def __unicode__(self):
def __str__(self):
return self.name
@classmethod
......
......@@ -2,7 +2,7 @@
# ----------------------------------------------------------------------
# Subscriber Profile
# ----------------------------------------------------------------------
# Copyright (C) 2007-2017 The NOC Project
# Copyright (C) 2007-2019 The NOC Project
# See LICENSE for details
# ----------------------------------------------------------------------
......@@ -10,6 +10,7 @@
import operator
from threading import Lock
# Third-party modules
import six
from mongoengine.document import Document
from mongoengine.fields import StringField, ListField, IntField, LongField, BooleanField
import cachetools
......@@ -28,6 +29,7 @@ id_lock = Lock()
@on_delete_check(check=[
("crm.Subscriber", "profile")
])
@six.python_2_unicode_compatible
class SubscriberProfile(Document):
meta = {
"collection": "noc.subscriberprofiles",
......@@ -59,7 +61,7 @@ class SubscriberProfile(Document):
_id_cache = cachetools.TTLCache(maxsize=100, ttl=60)
def __unicode__(self):
def __str__(self):
return self.name
@classmethod
......
......@@ -2,7 +2,7 @@
# ----------------------------------------------------------------------
# Supplier
# ----------------------------------------------------------------------
# Copyright (C) 2007-2018 The NOC Project
# Copyright (C) 2007-2019 The NOC Project
# See LICENSE for details
# ----------------------------------------------------------------------
......@@ -11,6 +11,7 @@ from __future__ import absolute_import
from threading import Lock
import operator
# Third-party modules
import six
from mongoengine.document import Document
from mongoengine.fields import StringField, ListField, BooleanField, LongField
import cachetools
......@@ -32,6 +33,7 @@ id_lock = Lock()
@on_delete_check(check=[
("phone.PhoneRange", "supplier")
])
@six.python_2_unicode_compatible
class Supplier(Document):
meta = {
"collection": "noc.suppliers",
......@@ -60,7 +62,7 @@ class Supplier(Document):
_id_cache = cachetools.TTLCache(maxsize=100, ttl=60)
def __unicode__(self):
def __str__(self):
return self.name
@classmethod
......
......@@ -2,7 +2,7 @@
# ----------------------------------------------------------------------
# Supplier Group
# ----------------------------------------------------------------------
# Copyright (C) 2007-2017 The NOC Project
# Copyright (C) 2007-2019 The NOC Project
# See LICENSE for details
# ----------------------------------------------------------------------
......@@ -10,6 +10,7 @@
import operator
from threading import Lock
# Third-party modules
import six
from mongoengine.document import Document
from mongoengine.fields import StringField, ListField, LongField
import cachetools
......@@ -28,6 +29,7 @@ id_lock = Lock()
@on_delete_check(check=[
("crm.Supplier", "profile")
])
@six.python_2_unicode_compatible
class SupplierProfile(Document):
meta = {
"collection": "noc.supplierprofiles",
......@@ -50,7 +52,7 @@ class SupplierProfile(Document):
_id_cache = cachetools.TTLCache(maxsize=100, ttl=60)
def __unicode__(self):
def __str__(self):
return self.name
@classmethod
......
......@@ -2,7 +2,7 @@
# ----------------------------------------------------------------------
# Quiz model
# ----------------------------------------------------------------------
# Copyright (C) 2007-2018 The NOC Project
# Copyright (C) 2007-2019 The NOC Project
# See LICENSE for details
# ----------------------------------------------------------------------
......@@ -10,6 +10,7 @@
import operator
from threading import Lock
# Third-party modules
import six
from mongoengine.document import Document, EmbeddedDocument
from mongoengine.fields import (StringField, EmbeddedDocumentField,
ListField, UUIDField, IntField, DateTimeField)
......@@ -65,6 +66,7 @@ class QuizQuestion(EmbeddedDocument):
@on_delete_check(check=[
("dev.Spec", "quiz")
])
@six.python_2_unicode_compatible
class Quiz(Document):
meta = {
"collection": "quiz",
......@@ -86,7 +88,7 @@ class Quiz(Document):
_id_cache = cachetools.TTLCache(maxsize=100, ttl=60)
_name_cache = cachetools.TTLCache(maxsize=100, ttl=60)
def __unicode__(self):
def __str__(self):
return self.name
@classmethod
......
......@@ -2,7 +2,7 @@
# ----------------------------------------------------------------------
# Spec model
# ----------------------------------------------------------------------
# Copyright (C) 2007-2018 The NOC Project
# Copyright (C) 2007-2019 The NOC Project
# See LICENSE for details
# ----------------------------------------------------------------------
......@@ -12,6 +12,7 @@ import os
import operator
from threading import Lock
# Third-party modules
import six
from mongoengine.document import Document, EmbeddedDocument
from mongoengine.fields import (StringField, EmbeddedDocumentField, DateTimeField,
ListField, UUIDField, IntField)
......@@ -52,6 +53,7 @@ class SpecAnswer(EmbeddedDocument):
}
@six.python_2_unicode_compatible
class Spec(Document):
meta = {
"collection": "specs",
......@@ -76,7 +78,7 @@ class Spec(Document):
_id_cache = cachetools.TTLCache(maxsize=100, ttl=60)
_name_cache = cachetools.TTLCache(maxsize=100, ttl=60)
def __unicode__(self):
def __str__(self):
return self.name
@classmethod
......
......@@ -2,11 +2,12 @@
# ---------------------------------------------------------------------
# DNSServer model
# ---------------------------------------------------------------------
# Copyright (C) 2007-2018 The NOC Project
# Copyright (C) 2007-2019 The NOC Project
# See LICENSE for details
# ---------------------------------------------------------------------
# Third-party modules modules
import six
from django.utils.translation import ugettext_lazy as _
from django.db import models
# NOC modules
......@@ -16,6 +17,7 @@ from noc.core.datastream.decorator import datastream
@datastream
@six.python_2_unicode_compatible
class DNSServer(models.Model):
"""
DNS Server is an database object representing real DNS server.
......@@ -24,7 +26,7 @@ class DNSServer(models.Model):
:param ip: Server's IP address
:param description: Optional description
"""
class Meta:
class Meta(object):
verbose_name = _("DNS Server")
verbose_name_plural = _("DNS Servers")
db_table = "dns_dnsserver"
......@@ -38,7 +40,7 @@ class DNSServer(models.Model):
blank=True, null=True
)
def __unicode__(self):
def __str__(self):
return self.name
def iter_changed_datastream(self):
......
......@@ -2,7 +2,7 @@
# ---------------------------------------------------------------------
# DNSZone
# ---------------------------------------------------------------------
# Copyright (C) 2007-2018 The NOC Project
# Copyright (C) 2007-2019 The NOC Project
# See LICENSE for details
# ---------------------------------------------------------------------
......@@ -45,6 +45,7 @@ ZONE_REVERSE_IPV6 = "6"
@on_delete_check(check=[
("dns.DNSZoneRecord", "zone")
])
@six.python_2_unicode_compatible
class DNSZone(models.Model):
"""
DNS Zone
......@@ -92,7 +93,7 @@ class DNSZone(models.Model):
_id_cache = cachetools.TTLCache(maxsize=100, ttl=60)
_name_cache = cachetools.TTLCache(maxsize=100, ttl=60)
def __unicode__(self):
def __str__(self):
return self.name
@classmethod
......
......@@ -2,7 +2,7 @@
# ---------------------------------------------------------------------
# DNSZoneProfile model
# ---------------------------------------------------------------------
# Copyright (C) 2007-2018 The NOC Project
# Copyright (C) 2007-2019 The NOC Project
# See LICENSE for details
# ---------------------------------------------------------------------
......@@ -11,6 +11,7 @@ from __future__ import absolute_import
from threading import Lock
import operator
# Third-party modules
import six
from django.utils.translation import ugettext_lazy as _
from django.db import models
import cachetools
......@@ -28,6 +29,7 @@ id_lock = Lock()
@on_delete_check(check=[
("dns.DNSZone", "profile")
])
@six.python_2_unicode_compatible
class DNSZoneProfile(models.Model):
"""
DNS Zone profile is a set of common parameters, shared between zones.
......@@ -44,7 +46,7 @@ class DNSZoneProfile(models.Model):
:param notification_group:
:param description:
"""
class Meta:
class Meta(object):
verbose_name = _("DNS Zone Profile")
verbose_name_plural = _("DNS Zone Profiles")
db_table = "dns_dnszoneprofile"
......@@ -72,7 +74,7 @@ class DNSZoneProfile(models.Model):
_id_cache = cachetools.TTLCache(maxsize=100, ttl=60)
_name_cache = cachetools.TTLCache(maxsize=100, ttl=60)
def __unicode__(self):
def __str__(self):
return self.name
@classmethod
......
......@@ -2,13 +2,14 @@
# ---------------------------------------------------------------------
# DNSZoneRecord model
# ---------------------------------------------------------------------
# Copyright (C) 2007-2018 The NOC Project
# Copyright (C) 2007-2019 The NOC Project