Siobhan Tully | 4bc09f2 | 2013-04-10 21:15:21 -0400 | [diff] [blame] | 1 | import os |
| 2 | from django.db import models |
Siobhan Tully | 30fd429 | 2013-05-10 08:59:56 -0400 | [diff] [blame] | 3 | from core.models import PlCoreBase |
Siobhan Tully | bf1153a | 2013-05-27 20:53:48 -0400 | [diff] [blame] | 4 | from core.models import Deployment |
Siobhan Tully | de5450d | 2013-06-21 11:35:33 -0400 | [diff] [blame] | 5 | from core.models import Tag |
| 6 | from django.contrib.contenttypes import generic |
Siobhan Tully | 567e3e6 | 2013-06-21 18:03:16 -0400 | [diff] [blame] | 7 | from geoposition.fields import GeopositionField |
Siobhan Tully | 4bc09f2 | 2013-04-10 21:15:21 -0400 | [diff] [blame] | 8 | |
| 9 | class Site(PlCoreBase): |
| 10 | |
Tony Mack | 85d1883 | 2013-05-09 17:02:31 -0400 | [diff] [blame] | 11 | tenant_id = models.CharField(null=True, blank=True, max_length=200, help_text="Keystone tenant id") |
Siobhan Tully | 4bc09f2 | 2013-04-10 21:15:21 -0400 | [diff] [blame] | 12 | name = models.CharField(max_length=200, help_text="Name for this Site") |
| 13 | site_url = models.URLField(null=True, blank=True, max_length=512, help_text="Site's Home URL Page") |
| 14 | enabled = models.BooleanField(default=True, help_text="Status for this Site") |
Siobhan Tully | 567e3e6 | 2013-06-21 18:03:16 -0400 | [diff] [blame] | 15 | location = GeopositionField() |
Siobhan Tully | 4bc09f2 | 2013-04-10 21:15:21 -0400 | [diff] [blame] | 16 | longitude = models.FloatField(null=True, blank=True) |
| 17 | latitude = models.FloatField(null=True, blank=True) |
| 18 | login_base = models.CharField(max_length=50, unique=True, help_text="Prefix for Slices associated with this Site") |
| 19 | is_public = models.BooleanField(default=True, help_text="Indicates the visibility of this site to other members") |
| 20 | abbreviated_name = models.CharField(max_length=80) |
| 21 | |
Siobhan Tully | bf1153a | 2013-05-27 20:53:48 -0400 | [diff] [blame] | 22 | deployments = models.ManyToManyField(Deployment, blank=True, related_name='sites') |
Siobhan Tully | de5450d | 2013-06-21 11:35:33 -0400 | [diff] [blame] | 23 | tags = generic.GenericRelation(Tag) |
Siobhan Tully | 4bc09f2 | 2013-04-10 21:15:21 -0400 | [diff] [blame] | 24 | |
| 25 | def __unicode__(self): return u'%s' % (self.name) |
| 26 | |
Siobhan Tully | bfd11dc | 2013-09-03 12:59:24 -0400 | [diff] [blame] | 27 | class SiteRole(PlCoreBase): |
| 28 | |
| 29 | ROLE_CHOICES = (('admin','Admin'),('pi','PI'),('tech','Tech'),('billing','Billing')) |
| 30 | role = models.CharField(choices=ROLE_CHOICES, unique=True, max_length=30) |
| 31 | |
| 32 | def __unicode__(self): return u'%s' % (self.role) |
| 33 | |
Siobhan Tully | 4bc09f2 | 2013-04-10 21:15:21 -0400 | [diff] [blame] | 34 | class SitePrivilege(PlCoreBase): |
| 35 | |
Siobhan Tully | 30fd429 | 2013-05-10 08:59:56 -0400 | [diff] [blame] | 36 | user = models.ForeignKey('User', related_name='site_privileges') |
Siobhan Tully | 4bc09f2 | 2013-04-10 21:15:21 -0400 | [diff] [blame] | 37 | site = models.ForeignKey('Site', related_name='site_privileges') |
Siobhan Tully | bfd11dc | 2013-09-03 12:59:24 -0400 | [diff] [blame] | 38 | role = models.ForeignKey('SiteRole') |
Siobhan Tully | 4bc09f2 | 2013-04-10 21:15:21 -0400 | [diff] [blame] | 39 | |
| 40 | def __unicode__(self): return u'%s %s %s' % (self.site, self.user, self.role) |
| 41 | |
Tony Mack | 00d361f | 2013-04-28 10:28:42 -0400 | [diff] [blame] | 42 | def save(self, *args, **kwds): |
Tony Mack | 00d361f | 2013-04-28 10:28:42 -0400 | [diff] [blame] | 43 | super(SitePrivilege, self).save(*args, **kwds) |
| 44 | |
| 45 | def delete(self, *args, **kwds): |
Tony Mack | 00d361f | 2013-04-28 10:28:42 -0400 | [diff] [blame] | 46 | super(SitePrivilege, self).delete(*args, **kwds) |
| 47 | |
Siobhan Tully | 4bc09f2 | 2013-04-10 21:15:21 -0400 | [diff] [blame] | 48 | |