X-Git-Url: http://git.onelab.eu/?a=blobdiff_plain;f=planetstack%2Fcore%2Fmodels%2Fsite.py;h=af57ed24c87840ca63395b0722030d9a51e69d2d;hb=9d8fc9ee70f829785442ecaf94589ef2c631766d;hp=04d10737c47305bbf8da4d7a02b7da5defe67007;hpb=cc750d5a502b2c6b1be2939b8d96f5faf6674779;p=plstackapi.git diff --git a/planetstack/core/models/site.py b/planetstack/core/models/site.py index 04d1073..af57ed2 100644 --- a/planetstack/core/models/site.py +++ b/planetstack/core/models/site.py @@ -1,18 +1,28 @@ import os from django.db import models +from django.db.models import Q from core.models import PlCoreBase,PlCoreBaseManager,PlCoreBaseDeletionManager from core.models import Tag from django.contrib.contenttypes import generic from geoposition.fields import GeopositionField from core.acl import AccessControlList +from planetstack.config import Config + +config = Config() class DeploymentLinkDeletionManager(PlCoreBaseDeletionManager): def get_queryset(self): parent=super(DeploymentLinkDeletionManager, self) - if hasattr(parent, "get_queryset"): - return parent.get_queryset().filter(Q(deployment__backend_type=config.observer_backend_type)|Q(backend_type=None)) + try: + backend_type = config.observer_backend_type + except AttributeError: + backend_type = None + + parent_queryset = parent.get_queryset() if hasattr(parent, "get_queryset") else parent.get_query_set() + if (backend_type): + return parent_queryset.filter(Q(deployment__backend_type=config.observer_backend_type)|Q(backend_type=None)) else: - return parent.get_queryset().filter(Q(deployment__backend_type=config.observer_backend_type)|Q(backend_type=None)) + return parent_queryset # deprecated in django 1.7 in favor of get_queryset(). def get_query_set(self): @@ -22,10 +32,18 @@ class DeploymentLinkDeletionManager(PlCoreBaseDeletionManager): class DeploymentDeletionManager(PlCoreBaseDeletionManager): def get_queryset(self): parent=super(DeploymentDeletionManager, self) - if hasattr(parent, "get_queryset"): - return parent.get_queryset().filter(Q(backend_type=config.observer_backend_type)|Q(backend_type=None)) + + try: + backend_type = config.observer_backend_type + except AttributeError: + backend_type = None + + parent_queryset = parent.get_queryset() if hasattr(parent, "get_queryset") else parent.get_query_set() + + if backend_type: + return parent_queryset.filter(Q(backend_type=config.observer_backend_type)|Q(backend_type=None)) else: - return parent.get_queryset().filter(Q(backend_type=config.observer_backend_type)|Q(backend_type=None)) + return parent_queryset # deprecated in django 1.7 in favor of get_queryset(). def get_query_set(self): @@ -34,10 +52,18 @@ class DeploymentDeletionManager(PlCoreBaseDeletionManager): class DeploymentLinkManager(PlCoreBaseManager): def get_queryset(self): parent=super(DeploymentLinkManager, self) - if hasattr(parent, "get_queryset"): - return parent.get_queryset().filter(Q(deployment__backend_type=config.observer_backend_type)|Q(backend_type=None)) + + try: + backend_type = config.observer_backend_type + except AttributeError: + backend_type = None + + parent_queryset = parent.get_queryset() if hasattr(parent, "get_queryset") else parent.get_query_set() + + if backend_type: + return parent_queryset.filter(Q(deployment__backend_type=config.observer_backend_type)|Q(backend_type=None)) else: - return parent.get_queryset().filter(Q(deployment__backend_type=config.observer_backend_type)|Q(backend_type=None)) + return parent_queryset # deprecated in django 1.7 in favor of get_queryset(). def get_query_set(self): @@ -47,10 +73,18 @@ class DeploymentLinkManager(PlCoreBaseManager): class DeploymentManager(PlCoreBaseManager): def get_queryset(self): parent=super(DeploymentManager, self) - if hasattr(parent, "get_queryset"): - return parent.get_queryset().filter(Q(backend_type=config.observer_backend_type)|Q(backend_type=None)) + + try: + backend_type = config.observer_backend_type + except AttributeError: + backend_type = None + + parent_queryset = parent.get_queryset() if hasattr(parent, "get_queryset") else parent.get_query_set() + + if backend_type: + return parent_queryset.filter(Q(backend_type=config.observer_backend_type)|Q(backend_type=None)) else: - return parent.get_queryset().filter(Q(backend_type=config.observer_backend_type)|Q(backend_type=None)) + return parent_queryset.filter(Q(backend_type=config.observer_backend_type)|Q(backend_type=None)) # deprecated in django 1.7 in favor of get_queryset(). def get_query_set(self):