blob: d8051bf4fc379175a67d9723941d6f71a3960113 [file] [log] [blame]
Scott Baker7b836b62014-06-11 14:37:48 -07001import os
2import datetime
3from collections import defaultdict
4from django.db import models
5from django.db.models import F, Q
6from core.models import PlCoreBase,Site,User,Deployment
Sapan Bhatiad0c61c52014-09-22 15:08:44 -04007from core.models import Deployment,DeploymentLinkManager,DeploymentLinkDeletionManager
Scott Baker7b836b62014-06-11 14:37:48 -07008
Sapan Bhatia3f879692014-11-19 15:10:51 -05009class UserDeployments(PlCoreBase):
Sapan Bhatiad0c61c52014-09-22 15:08:44 -040010 objects = DeploymentLinkManager()
11 deleted_objects = DeploymentLinkDeletionManager()
12
Sapan Bhatia13d2db92014-11-11 21:47:45 -050013 user = models.ForeignKey(User,related_name='userdeployments')
14 deployment = models.ForeignKey(Deployment,related_name='userdeployments')
Scott Baker7b836b62014-06-11 14:37:48 -070015 kuser_id = models.CharField(null=True, blank=True, max_length=200, help_text="Keystone user id")
16
17 def __unicode__(self): return u'%s %s' % (self.user, self.deployment.name)
18
19 @staticmethod
20 def select_by_user(user):
21 if user.is_admin:
Sapan Bhatia3f879692014-11-19 15:10:51 -050022 qs = UserDeployments.objects.all()
Scott Baker7b836b62014-06-11 14:37:48 -070023 else:
24 users = Users.select_by_user(user)
25 qs = Usereployments.objects.filter(user__in=slices)
26 return qs