Scott Baker | 7b836b6 | 2014-06-11 14:37:48 -0700 | [diff] [blame] | 1 | import os |
| 2 | import datetime |
| 3 | from collections import defaultdict |
| 4 | from django.db import models |
| 5 | from django.db.models import F, Q |
| 6 | from core.models import PlCoreBase,Site,User,Deployment |
Sapan Bhatia | d0c61c5 | 2014-09-22 15:08:44 -0400 | [diff] [blame] | 7 | from core.models import Deployment,DeploymentLinkManager,DeploymentLinkDeletionManager |
Scott Baker | 7b836b6 | 2014-06-11 14:37:48 -0700 | [diff] [blame] | 8 | |
| 9 | class UserDeployments(PlCoreBase): |
Sapan Bhatia | d0c61c5 | 2014-09-22 15:08:44 -0400 | [diff] [blame] | 10 | objects = DeploymentLinkManager() |
| 11 | deleted_objects = DeploymentLinkDeletionManager() |
| 12 | |
Scott Baker | 7b836b6 | 2014-06-11 14:37:48 -0700 | [diff] [blame] | 13 | user = models.ForeignKey(User) |
| 14 | deployment = models.ForeignKey(Deployment) |
| 15 | 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: |
| 22 | qs = UserDeployments.objects.all() |
| 23 | else: |
| 24 | users = Users.select_by_user(user) |
| 25 | qs = Usereployments.objects.filter(user__in=slices) |
| 26 | return qs |