mirror of
https://github.com/netbox-community/netbox.git
synced 2024-05-10 07:54:54 +00:00
* WIP * Remove FeatureQuery * Standardize use of proxy ContentType for models * Remove TODO * Correctly filter BookmarksWidget object_types choices * Add feature-specific object type validation
This commit is contained in:
@ -1,5 +1,3 @@
|
||||
from django.db.models import Q
|
||||
from django.utils.deconstruct import deconstructible
|
||||
from taggit.managers import _TaggableManager
|
||||
|
||||
from netbox.registry import registry
|
||||
@ -31,29 +29,6 @@ def image_upload(instance, filename):
|
||||
return '{}{}_{}_{}'.format(path, instance.content_type.name, instance.object_id, filename)
|
||||
|
||||
|
||||
@deconstructible
|
||||
class FeatureQuery:
|
||||
"""
|
||||
Helper class that delays evaluation of the registry contents for the functionality store
|
||||
until it has been populated.
|
||||
"""
|
||||
def __init__(self, feature):
|
||||
self.feature = feature
|
||||
|
||||
def __call__(self):
|
||||
return self.get_query()
|
||||
|
||||
def get_query(self):
|
||||
"""
|
||||
Given an extras feature, return a Q object for content type lookup
|
||||
"""
|
||||
query = Q()
|
||||
for app_label, models in registry['model_features'][self.feature].items():
|
||||
query |= Q(app_label=app_label, model__in=models)
|
||||
|
||||
return query
|
||||
|
||||
|
||||
def register_features(model, features):
|
||||
"""
|
||||
Register model features in the application registry.
|
||||
|
Reference in New Issue
Block a user