Tony Mack | 336e0f9 | 2014-11-30 15:53:08 -0500 | [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,User,Controller |
| 7 | from core.models import Controller,ControllerLinkManager,ControllerLinkDeletionManager |
| 8 | |
Tony Mack | a7dbd42 | 2015-01-05 22:48:11 -0500 | [diff] [blame^] | 9 | class ControllerUser(PlCoreBase): |
Tony Mack | 336e0f9 | 2014-11-30 15:53:08 -0500 | [diff] [blame] | 10 | objects = ControllerLinkManager() |
| 11 | deleted_objects = ControllerLinkDeletionManager() |
| 12 | |
| 13 | user = models.ForeignKey(User,related_name='controllerusers') |
| 14 | controller = models.ForeignKey(Controller,related_name='controllersusers') |
| 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.controller, self.user) |
| 18 | |
| 19 | @staticmethod |
| 20 | def select_by_user(user): |
| 21 | if user.is_admin: |
Tony Mack | a7dbd42 | 2015-01-05 22:48:11 -0500 | [diff] [blame^] | 22 | qs = ControllerUser.objects.all() |
Tony Mack | 336e0f9 | 2014-11-30 15:53:08 -0500 | [diff] [blame] | 23 | else: |
| 24 | users = Users.select_by_user(user) |
Tony Mack | a7dbd42 | 2015-01-05 22:48:11 -0500 | [diff] [blame^] | 25 | qs = ControllerUser.objects.filter(user__in=users) |
Tony Mack | 336e0f9 | 2014-11-30 15:53:08 -0500 | [diff] [blame] | 26 | return qs |