Commit e70928dd by Kálmán Viktor

request: rework model

parent 28e65ce1
...@@ -12,19 +12,16 @@ class Migration(migrations.Migration): ...@@ -12,19 +12,16 @@ class Migration(migrations.Migration):
dependencies = [ dependencies = [
migrations.swappable_dependency(settings.AUTH_USER_MODEL), migrations.swappable_dependency(settings.AUTH_USER_MODEL),
('contenttypes', '0001_initial'),
('vm', '0002_interface_model'), ('vm', '0002_interface_model'),
] ]
operations = [ operations = [
migrations.CreateModel( migrations.CreateModel(
name='Request', name='ExtendLeaseAction',
fields=[ fields=[
('id', models.AutoField(verbose_name='ID', serialize=False, auto_created=True, primary_key=True)), ('id', models.AutoField(verbose_name='ID', serialize=False, auto_created=True, primary_key=True)),
('created', model_utils.fields.AutoCreatedField(default=django.utils.timezone.now, verbose_name='created', editable=False)), ('instance', models.ForeignKey(to='vm.Instance')),
('modified', model_utils.fields.AutoLastModifiedField(default=django.utils.timezone.now, verbose_name='modified', editable=False)),
('status', models.CharField(default=b'UNSEEN', max_length=10, choices=[(b'UNSEEN', 'unseen'), (b'PENDING', 'pending'), (b'ACCEPTED', 'accepted'), (b'DECLINED', 'declined')])),
('type', models.CharField(max_length=10, choices=[(b'resource', 'resource request'), (b'lease', 'lease request'), (b'template', 'template access')])),
('reason', models.TextField(help_text=b'szia')),
], ],
options={ options={
'abstract': False, 'abstract': False,
...@@ -32,76 +29,71 @@ class Migration(migrations.Migration): ...@@ -32,76 +29,71 @@ class Migration(migrations.Migration):
bases=(models.Model,), bases=(models.Model,),
), ),
migrations.CreateModel( migrations.CreateModel(
name='RequestAction', name='LeaseType',
fields=[ fields=[
('id', models.AutoField(verbose_name='ID', serialize=False, auto_created=True, primary_key=True)), ('id', models.AutoField(verbose_name='ID', serialize=False, auto_created=True, primary_key=True)),
('name', models.CharField(max_length=25)),
('lease', models.ForeignKey(to='vm.Lease')),
], ],
options={ options={
'abstract': False,
}, },
bases=(models.Model,), bases=(models.Model,),
), ),
migrations.CreateModel( migrations.CreateModel(
name='ExtendLeaseAction', name='Request',
fields=[
('requestaction_ptr', models.OneToOneField(parent_link=True, auto_created=True, primary_key=True, serialize=False, to='request.RequestAction')),
('instance', models.ForeignKey(to='vm.Instance')),
],
options={
},
bases=('request.requestaction',),
),
migrations.CreateModel(
name='RequestType',
fields=[ fields=[
('id', models.AutoField(verbose_name='ID', serialize=False, auto_created=True, primary_key=True)), ('id', models.AutoField(verbose_name='ID', serialize=False, auto_created=True, primary_key=True)),
('name', models.CharField(max_length=25)), ('created', model_utils.fields.AutoCreatedField(default=django.utils.timezone.now, verbose_name='created', editable=False)),
('modified', model_utils.fields.AutoLastModifiedField(default=django.utils.timezone.now, verbose_name='modified', editable=False)),
('status', models.CharField(default=b'UNSEEN', max_length=10, choices=[(b'UNSEEN', 'unseen'), (b'PENDING', 'pending'), (b'ACCEPTED', 'accepted'), (b'DECLINED', 'declined')])),
('type', models.CharField(max_length=10, choices=[(b'resource', 'resource request'), (b'lease', 'lease request'), (b'template', 'template access')])),
('reason', models.TextField(help_text=b'szia')),
('object_id', models.IntegerField()),
('content_type', models.ForeignKey(to='contenttypes.ContentType')),
('user', models.ForeignKey(verbose_name='user', to=settings.AUTH_USER_MODEL)),
], ],
options={ options={
'abstract': False,
}, },
bases=(models.Model,), bases=(models.Model,),
), ),
migrations.CreateModel( migrations.CreateModel(
name='LeaseType',
fields=[
('requesttype_ptr', models.OneToOneField(parent_link=True, auto_created=True, primary_key=True, serialize=False, to='request.RequestType')),
('lease', models.ForeignKey(to='vm.Lease')),
],
options={
},
bases=('request.requesttype',),
),
migrations.CreateModel(
name='ResourceChangeAction', name='ResourceChangeAction',
fields=[ fields=[
('requestaction_ptr', models.OneToOneField(parent_link=True, auto_created=True, primary_key=True, serialize=False, to='request.RequestAction')), ('id', models.AutoField(verbose_name='ID', serialize=False, auto_created=True, primary_key=True)),
('num_cores', models.IntegerField(help_text='Number of virtual CPU cores available to the virtual machine.', verbose_name='number of cores', validators=[django.core.validators.MinValueValidator(0)])), ('num_cores', models.IntegerField(help_text='Number of virtual CPU cores available to the virtual machine.', verbose_name='number of cores', validators=[django.core.validators.MinValueValidator(0)])),
('ram_size', models.IntegerField(help_text='Mebibytes of memory.', verbose_name='RAM size', validators=[django.core.validators.MinValueValidator(0)])), ('ram_size', models.IntegerField(help_text='Mebibytes of memory.', verbose_name='RAM size', validators=[django.core.validators.MinValueValidator(0)])),
('priority', models.IntegerField(help_text='CPU priority.', verbose_name='priority', validators=[django.core.validators.MinValueValidator(0)])), ('priority', models.IntegerField(help_text='CPU priority.', verbose_name='priority', validators=[django.core.validators.MinValueValidator(0)])),
('instance', models.ForeignKey(to='vm.Instance')), ('instance', models.ForeignKey(to='vm.Instance')),
], ],
options={ options={
'abstract': False,
}, },
bases=('request.requestaction',), bases=(models.Model,),
), ),
migrations.CreateModel( migrations.CreateModel(
name='TemplateAccessAction', name='TemplateAccessAction',
fields=[ fields=[
('requestaction_ptr', models.OneToOneField(parent_link=True, auto_created=True, primary_key=True, serialize=False, to='request.RequestAction')), ('id', models.AutoField(verbose_name='ID', serialize=False, auto_created=True, primary_key=True)),
('level', models.CharField(default=b'user', max_length=10, choices=[(b'user', 'user'), (b'operator', 'operator')])), ('level', models.CharField(default=b'user', max_length=10, choices=[(b'user', 'user'), (b'operator', 'operator')])),
], ],
options={ options={
'abstract': False,
}, },
bases=('request.requestaction',), bases=(models.Model,),
), ),
migrations.CreateModel( migrations.CreateModel(
name='TemplateAccessType', name='TemplateAccessType',
fields=[ fields=[
('requesttype_ptr', models.OneToOneField(parent_link=True, auto_created=True, primary_key=True, serialize=False, to='request.RequestType')), ('id', models.AutoField(verbose_name='ID', serialize=False, auto_created=True, primary_key=True)),
('name', models.CharField(max_length=25)),
('templates', models.ManyToManyField(to='vm.InstanceTemplate')), ('templates', models.ManyToManyField(to='vm.InstanceTemplate')),
], ],
options={ options={
'abstract': False,
}, },
bases=('request.requesttype',), bases=(models.Model,),
), ),
migrations.AddField( migrations.AddField(
model_name='templateaccessaction', model_name='templateaccessaction',
...@@ -116,18 +108,6 @@ class Migration(migrations.Migration): ...@@ -116,18 +108,6 @@ class Migration(migrations.Migration):
preserve_default=True, preserve_default=True,
), ),
migrations.AddField( migrations.AddField(
model_name='request',
name='action',
field=models.ForeignKey(to='request.RequestAction'),
preserve_default=True,
),
migrations.AddField(
model_name='request',
name='user',
field=models.ForeignKey(verbose_name='user', to=settings.AUTH_USER_MODEL),
preserve_default=True,
),
migrations.AddField(
model_name='extendleaseaction', model_name='extendleaseaction',
name='lease_type', name='lease_type',
field=models.ForeignKey(to='request.LeaseType'), field=models.ForeignKey(to='request.LeaseType'),
......
from django.db.models import ( from django.db.models import (
Model, CharField, IntegerField, TextField, ForeignKey, ManyToManyField, Model, CharField, IntegerField, TextField, ForeignKey, ManyToManyField,
) )
from django.contrib.contenttypes.fields import GenericForeignKey
from django.contrib.contenttypes.models import ContentType
from django.contrib.auth.models import User from django.contrib.auth.models import User
from django.core.validators import MinValueValidator from django.core.validators import MinValueValidator
from django.utils.translation import ugettext_lazy as _ from django.utils.translation import ugettext_lazy as _
...@@ -17,6 +19,9 @@ class RequestAction(Model): ...@@ -17,6 +19,9 @@ class RequestAction(Model):
def accept(self): def accept(self):
raise NotImplementedError raise NotImplementedError
class Meta:
abstract = True
class RequestType(Model): class RequestType(Model):
name = CharField(max_length=25) name = CharField(max_length=25)
...@@ -24,6 +29,9 @@ class RequestType(Model): ...@@ -24,6 +29,9 @@ class RequestType(Model):
def __unicode__(self): def __unicode__(self):
return self.name return self.name
class Meta:
abstract = True
class Request(TimeStampedModel): class Request(TimeStampedModel):
STATUSES = Choices( STATUSES = Choices(
...@@ -42,7 +50,28 @@ class Request(TimeStampedModel): ...@@ -42,7 +50,28 @@ class Request(TimeStampedModel):
) )
type = CharField(choices=TYPES, max_length=10) type = CharField(choices=TYPES, max_length=10)
reason = TextField(help_text="szia") reason = TextField(help_text="szia")
action = ForeignKey(RequestAction)
content_type = ForeignKey(ContentType)
object_id = IntegerField()
action = GenericForeignKey("content_type", "object_id")
def get_readable_status(self):
return self.STATUSES[self.status]
def get_icon(self):
return {
'resource': "tasks",
'lease': "clock-o",
'template': "puzzle-piece"
}.get(self.type)
def get_effect(self):
return {
"UNSEEN": "primary",
"PENDING": "warning",
"ACCEPTED": "success",
"DECLINED": "danger",
}.get(self.status)
class LeaseType(RequestType): class LeaseType(RequestType):
...@@ -103,5 +132,8 @@ class TemplateAccessAction(RequestAction): ...@@ -103,5 +132,8 @@ class TemplateAccessAction(RequestAction):
max_length=10) max_length=10)
user = ForeignKey(User) user = ForeignKey(User)
def get_readable_level(self):
return self.LEVELS[self.level]
def accept(self): def accept(self):
pass pass
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment