move UserDeployments to a separate file to resolve circular reference
Scott Baker [Wed, 11 Jun 2014 21:37:48 +0000 (14:37 -0700)]
planetstack/core/models/__init__.py
planetstack/core/models/user.py
planetstack/core/models/userdeployments.py [new file with mode: 0644]

index e31da37..4e76958 100644 (file)
@@ -8,10 +8,11 @@ from .tag import Tag
 from .role import Role
 from .site import Site,Deployment, DeploymentRole, DeploymentPrivilege, SiteDeployments
 from .dashboard import DashboardView
-from .user import User, UserDeployments, UserDashboardView
+from .user import User, UserDashboardView
 from .serviceclass import ServiceClass
 from .slice import Slice, SliceDeployments
 from .site import SitePrivilege, SiteDeployments
+from .userdeployments import UserDeployments
 from .image import Image, ImageDeployments
 from .node import Node
 from .serviceresource import ServiceResource
index 6e7eef6..fba2a7e 100644 (file)
@@ -4,7 +4,6 @@ from collections import defaultdict
 from django.db import models
 from django.db.models import F, Q
 from core.models import PlCoreBase,Site, DashboardView
-from core.models.deployment import Deployment
 from django.contrib.auth.models import AbstractBaseUser, BaseUserManager
 from timezones.fields import TimeZoneField
 from operator import itemgetter, attrgetter
@@ -164,24 +163,6 @@ class User(AbstractBaseUser):
             qs = User.objects.filter(Q(site__in=sites) | Q(id__in=user_ids))
         return qs            
 
-             
-    
-class UserDeployments(PlCoreBase):
-    user = models.ForeignKey(User)
-    deployment = models.ForeignKey(Deployment)
-    kuser_id = models.CharField(null=True, blank=True, max_length=200, help_text="Keystone user id")
-
-    def __unicode__(self):  return u'%s %s' % (self.user, self.deployment.name)
-
-    @staticmethod
-    def select_by_user(user):
-        if user.is_admin:
-            qs = UserDeployments.objects.all()
-        else:
-            users = Users.select_by_user(user)
-            qs = Usereployments.objects.filter(user__in=slices)
-        return qs
-
 class UserDashboardView(PlCoreBase):
      user = models.ForeignKey(User, related_name="dashboardViews")
      dashboardView = models.ForeignKey(DashboardView, related_name="dashboardViews")
diff --git a/planetstack/core/models/userdeployments.py b/planetstack/core/models/userdeployments.py
new file mode 100644 (file)
index 0000000..3422156
--- /dev/null
@@ -0,0 +1,22 @@
+import os
+import datetime
+from collections import defaultdict
+from django.db import models
+from django.db.models import F, Q
+from core.models import PlCoreBase,Site,User,Deployment
+
+class UserDeployments(PlCoreBase):
+    user = models.ForeignKey(User)
+    deployment = models.ForeignKey(Deployment)
+    kuser_id = models.CharField(null=True, blank=True, max_length=200, help_text="Keystone user id")
+
+    def __unicode__(self):  return u'%s %s' % (self.user, self.deployment.name)
+
+    @staticmethod
+    def select_by_user(user):
+        if user.is_admin:
+            qs = UserDeployments.objects.all()
+        else:
+            users = Users.select_by_user(user)
+            qs = Usereployments.objects.filter(user__in=slices)
+        return qs