|
@@ -22,14 +22,15 @@
|
|
|
# Django imports.
|
|
|
from django.contrib.admin.util import NestedObjects
|
|
|
from django.core.exceptions import ValidationError
|
|
|
from django.core.urlresolvers import reverse
|
|
|
from django.db import models
|
|
|
from django.db.models.query_utils import Q
|
|
|
from django.utils.html import format_html
|
|
|
from django.utils.text import capfirst
|
|
|
|
|
|
# Application imports.
|
|
|
from .utils import list_formatter_callback
|
|
|
|
|
|
|
|
|
class SearchManager(models.Manager):
|
|
|
"""
|
|
|
Custom model manager that implements search for model instances that contain
|
|
|
a specific string (search term) in fields "name" or "description".
|
|
@@ -91,53 +92,25 @@ class RelatedCollectorMixin(object):
|
|
|
objects that would get deleted in case the calling model object gets
|
|
|
deleted.
|
|
|
|
|
|
The resulting nested list can be shown to the user for
|
|
|
warning/notification purposes using the unordered_list template tag.
|
|
|
|
|
|
Each non-list element will be a string of format:
|
|
|
|
|
|
MODEL_NAME: OBJECT_REPRESENTATION
|
|
|
|
|
|
If object has a callable get_absolute_url method, the object
|
|
|
representation will be surrouned by HTML anchor tag (<a></a>) where
|
|
|
target (href) is set to the value of get_absolute_url() method call.
|
|
|
Each non-list element will be a string generated using the
|
|
|
conntrackt.utils.list_formatter_callback function.
|
|
|
|
|
|
Returns:
|
|
|
Nested list of representations of model objects that depend
|
|
|
(reference) calling model object.
|
|
|
"""
|
|
|
|
|
|
collector = NestedObjects(using='default')
|
|
|
|
|
|
collector.collect([self])
|
|
|
|
|
|
def formatter_callback(obj):
|
|
|
"""
|
|
|
Creates model object representation in format:
|
|
|
|
|
|
MODEL_NAME: OBJECT_REPRESENTATION
|
|
|
|
|
|
If passed object has a callable get_absolute_url method, the
|
|
|
instance representation will be surrouned by an HTML anchor
|
|
|
(<a></a>) where target is set to value of the get_absolute_url()
|
|
|
method call.
|
|
|
|
|
|
Arguments:
|
|
|
obj - Model object whose representation should be returned.
|
|
|
|
|
|
Returns:
|
|
|
String represenation of passed model object.
|
|
|
"""
|
|
|
|
|
|
try:
|
|
|
return format_html('<strong>{0}</strong>: <a href="{1}">{2}</a>', capfirst(obj._meta.verbose_name), obj.get_absolute_url(), str(obj))
|
|
|
except AttributeError:
|
|
|
return format_html('<strong>{0}</strong>: {1}', capfirst(obj._meta.verbose_name), str(obj))
|
|
|
|
|
|
return collector.nested(formatter_callback)
|
|
|
return collector.nested(list_formatter_callback)
|
|
|
|
|
|
|
|
|
class Project(RelatedCollectorMixin, models.Model):
|
|
|
"""
|
|
|
Implements a model with information about a project. A project has some
|
|
|
basic settings, and mainly serves the purpose of grouping entities for
|
|
@@ -149,13 +122,13 @@ class Project(RelatedCollectorMixin, mod
|
|
|
description - Free-form description of the project.
|
|
|
"""
|
|
|
|
|
|
name = models.CharField(max_length=100, unique=True)
|
|
|
description = models.TextField(blank=True)
|
|
|
objects = SearchManager()
|
|
|
deletion_collect_models = ["Entity", "Interface"]
|
|
|
deletion_collect_models = ["Entity", "Interface"]
|
|
|
|
|
|
class Meta:
|
|
|
permissions = (("view", "Can view information"),)
|
|
|
|
|
|
def __unicode__(self):
|
|
|
"""
|