Tony Mack | 06c8e47 | 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 | |
| 9 | class ControllerUsers(PlCoreBase): |
| 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: |
| 22 | qs = ControllerUsers.objects.all() |
| 23 | else: |
| 24 | users = Users.select_by_user(user) |
| 25 | qs = ControllerUsers.objects.filter(user__in=users) |
| 26 | return qs |