blob: 234868e0a8e0a6ec671665688197c4a548e1da88 [file] [log] [blame]
Siobhan Tully4bc09f22013-04-10 21:15:21 -04001import os
2import datetime
3from django.db import models
Siobhan Tully30fd4292013-05-10 08:59:56 -04004from core.models import PlCoreBase
Siobhan Tullybfd11dc2013-09-03 12:59:24 -04005from django.contrib.contenttypes.models import ContentType
6from django.contrib.contenttypes import generic
Siobhan Tully4bc09f22013-04-10 21:15:21 -04007
8class Role(PlCoreBase):
9
Siobhan Tullybfd11dc2013-09-03 12:59:24 -040010 role_type = models.CharField(max_length=80, verbose_name="Name")
11 description = models.CharField(max_length=120, verbose_name="Description")
12 content_type = models.ForeignKey(ContentType, verbose_name="Role Scope")
Siobhan Tully4bc09f22013-04-10 21:15:21 -040013
Siobhan Tullybfd11dc2013-09-03 12:59:24 -040014 def __unicode__(self): return u'%s:%s' % (self.content_type,self.role_type)
Siobhan Tully4bc09f22013-04-10 21:15:21 -040015
Tony Mackfd24d0d2013-04-14 00:59:17 -040016
17 def save(self, *args, **kwds):
Siobhan Tully73291342013-05-10 10:50:08 -040018 if not hasattr(self, 'os_manager'):
Tony Mack89f70f12013-05-10 20:20:03 -040019 from openstack.manager import OpenStackManager
Siobhan Tully73291342013-05-10 10:50:08 -040020 setattr(self, 'os_manager', OpenStackManager())
Tony Mack89f70f12013-05-10 20:20:03 -040021 self.os_manager.save_role(self)
Tony Mackfd24d0d2013-04-14 00:59:17 -040022 super(Role, self).save(*args, **kwds)
23
24 def delete(self, *args, **kwds):
Siobhan Tully73291342013-05-10 10:50:08 -040025 if not hasattr(self, 'os_manager'):
Tony Mack89f70f12013-05-10 20:20:03 -040026 from openstack.manager import OpenStackManager
Siobhan Tully73291342013-05-10 10:50:08 -040027 setattr(self, 'os_manager', OpenStackManager())
Tony Mack89f70f12013-05-10 20:20:03 -040028 self.os_manager.delete_role(self)
Tony Mackfd24d0d2013-04-14 00:59:17 -040029 super(Role, self).delete(*args, **kwds)
30