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 | |
Sapan Bhatia | 13d2db9 | 2014-11-11 21:47:45 -0500 | [diff] [blame^] | 9 | class UserDeployment(PlCoreBase): |
Sapan Bhatia | d0c61c5 | 2014-09-22 15:08:44 -0400 | [diff] [blame] | 10 | objects = DeploymentLinkManager() |
| 11 | deleted_objects = DeploymentLinkDeletionManager() |
| 12 | |
Sapan Bhatia | 13d2db9 | 2014-11-11 21:47:45 -0500 | [diff] [blame^] | 13 | user = models.ForeignKey(User,related_name='userdeployments') |
| 14 | deployment = models.ForeignKey(Deployment,related_name='userdeployments') |
Scott Baker | 7b836b6 | 2014-06-11 14:37:48 -0700 | [diff] [blame] | 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: |
Sapan Bhatia | 84ba65d | 2014-11-11 21:44:35 -0500 | [diff] [blame] | 22 | qs = UserDeployment.objects.all() |
Scott Baker | 7b836b6 | 2014-06-11 14:37:48 -0700 | [diff] [blame] | 23 | else: |
| 24 | users = Users.select_by_user(user) |
| 25 | qs = Usereployments.objects.filter(user__in=slices) |
| 26 | return qs |