From 639cd5db77064c275253828780c17ae59551d95c Mon Sep 17 00:00:00 2001 From: maxbr Date: Fri, 29 Jul 2016 12:43:43 +0200 Subject: import pharos dashboard code JIRA: RELENG-12 The last commit was missing some JS/CSS dependencies of the site. This happened because they are in folders that are named 'build' or 'dist'. This commit adds a bower.json file, that specifies dependencies. Dependencies can now be installed by running 'bower install' in the dashboard/static folder. Change-Id: I054f319c66771f767e97711cb678d79d3bd6bee4 Signed-off-by: maxbr --- pharos-dashboard/dashboard/models.py | 89 ++++++++++++++++++++++++++++++++++++ 1 file changed, 89 insertions(+) create mode 100644 pharos-dashboard/dashboard/models.py (limited to 'pharos-dashboard/dashboard/models.py') diff --git a/pharos-dashboard/dashboard/models.py b/pharos-dashboard/dashboard/models.py new file mode 100644 index 0000000..132ba7c --- /dev/null +++ b/pharos-dashboard/dashboard/models.py @@ -0,0 +1,89 @@ +from __future__ import unicode_literals + +from django.db import models +from django.contrib.auth.models import User + + +class Booking(models.Model): + booking_id = models.AutoField(primary_key=True) + # Bookings should be deleted before resources + resource = models.ForeignKey('Resource', models.PROTECT) + # delete Booking when user is deleted + user = models.ForeignKey(User, models.CASCADE) + start_date_time = models.DateTimeField() + end_date_time = models.DateTimeField() + creation = models.DateTimeField(auto_now=True) + purpose = models.CharField(max_length=300) + + class Meta: + db_table = 'booking' + + # check for conflicting bookings before saving + def save(self, *args, **kwargs): + # conflicts end after booking starts, and start before booking ends + conflicting_bookings = Booking.objects.filter(resource_id=self.resource_id) + conflicting_bookings = conflicting_bookings.filter(end_date_time__gt=self.start_date_time) + conflicting_bookings = conflicting_bookings.filter(start_date_time__lt=self.end_date_time) + # we may change a booking, so it is not a conflict + conflicting_bookings = conflicting_bookings.exclude(booking_id=self.booking_id) + if conflicting_bookings.count() > 0: + raise ValueError('This booking overlaps with another booking') + super(Booking, self).save(*args, **kwargs) + + +def __str__(self): + return 'Booking: ' + str(self.resource) + + +class Pod(models.Model): + pod_id = models.AutoField(primary_key=True) + # Delete Pod with resource + resource = models.ForeignKey('Resource', models.CASCADE) + chassis = models.CharField(max_length=500, blank=True, null=True) + + class Meta: + db_table = 'pod' + + def __str__(self): + if self.chassis is None: + return str(self.pod_id) + ' ' + str(self.resource) + return str(self.pod_id) + ' ' + self.chassis + + +class Resource(models.Model): + resource_id = models.AutoField(primary_key=True) + name = models.CharField(max_length=100, unique=True) + slavename = models.CharField(max_length=50, blank=True, null=True) + description = models.CharField(max_length=300, blank=True, null=True) + url = models.CharField(max_length=100, blank=True, null=True) + bookable = models.BooleanField(default=False) + active = models.BooleanField(default=True) + + class Meta: + db_table = 'resource' + + def __str__(self): + return self.name + + +class Server(models.Model): + server_id = models.AutoField(primary_key=True) + resource = models.ForeignKey(Resource, models.DO_NOTHING) + model = models.CharField(max_length=200, blank=True, null=True) + cpu = models.CharField(max_length=200, blank=True, null=True) + ram = models.CharField(max_length=200, blank=True, null=True) + storage = models.CharField(max_length=200, blank=True, null=True) + count = models.IntegerField(default=1) + + class Meta: + db_table = 'server' + + +class UserResource(models.Model): + user_resource_id = models.AutoField(primary_key=True) + user = models.ForeignKey(User, models.CASCADE) + # Delete if Resource is deleted + resource = models.ForeignKey(Resource, models.CASCADE) + + class Meta: + db_table = 'user_resource' -- cgit 1.2.3-korg