blob: d0337ba4e3aa28508443988d92189ff34a8064e8 [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 Bhatia85b26c82014-09-22 15:08:44 -04007from core.models import Deployment,DeploymentLinkManager,DeploymentLinkDeletionManager
Scott Baker7b836b62014-06-11 14:37:48 -07008
Sapan Bhatia6bfa2ca2014-11-11 21:47:45 -05009class UserDeployment(PlCoreBase):
Sapan Bhatia85b26c82014-09-22 15:08:44 -040010 objects = DeploymentLinkManager()
11 deleted_objects = DeploymentLinkDeletionManager()
12
Sapan Bhatia6bfa2ca2014-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 Bhatiabfe716a2014-11-11 21:44:35 -050022 qs = UserDeployment.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