diff options
author | Gergely Csatari <gergely.csatari@nokia.com> | 2023-10-26 10:33:28 +0300 |
---|---|---|
committer | Gergely Csatari <gergely.csatari@nokia.com> | 2023-10-26 10:34:28 +0300 |
commit | 2ec0d7b9f5c1354977b821c6b06c24a3ffa13142 (patch) | |
tree | 6e449d92ddfc880ed007e9d8a8f25bda8fc7cb0f /src/booking/models.py | |
parent | 0d3dd290aa6e7f39e7b0b3cbe448b6622f924240 (diff) |
that the development continues in GitHub
Change-Id: I25c58a679dbf92b2367d826429b7cda936bf9f0e
Signed-off-by: Gergely Csatari <gergely.csatari@nokia.com>
Diffstat (limited to 'src/booking/models.py')
-rw-r--r-- | src/booking/models.py | 72 |
1 files changed, 0 insertions, 72 deletions
diff --git a/src/booking/models.py b/src/booking/models.py deleted file mode 100644 index 966f1c2..0000000 --- a/src/booking/models.py +++ /dev/null @@ -1,72 +0,0 @@ -############################################################################## -# Copyright (c) 2016 Max Breitenfeldt and others. -# Copyright (c) 2018 Sawyer Bergeron, Parker Berberian, and others. -# -# All rights reserved. This program and the accompanying materials -# are made available under the terms of the Apache License, Version 2.0 -# which accompanies this distribution, and is available at -# http://www.apache.org/licenses/LICENSE-2.0 -############################################################################## - - -from resource_inventory.models import ResourceBundle, OPNFVConfig -from account.models import Lab -from django.contrib.auth.models import User -from django.db import models -import resource_inventory.resource_manager - - -class Booking(models.Model): - id = models.AutoField(primary_key=True) - # All bookings are owned by the user who requested it - owner = models.ForeignKey(User, on_delete=models.PROTECT, related_name='owner') - # an owner can add other users to the booking - collaborators = models.ManyToManyField(User, blank=True, related_name='collaborators') - # start and end time - start = models.DateTimeField() - end = models.DateTimeField() - reset = models.BooleanField(default=False) - jira_issue_id = models.IntegerField(null=True, blank=True) - jira_issue_status = models.CharField(max_length=50, blank=True) - purpose = models.CharField(max_length=300, blank=False) - # bookings can be extended a limited number of times - ext_count = models.IntegerField(default=2) - # the hardware that the user has booked - resource = models.ForeignKey(ResourceBundle, on_delete=models.SET_NULL, null=True, blank=True) - opnfv_config = models.ForeignKey(OPNFVConfig, on_delete=models.SET_NULL, null=True, blank=True) - project = models.CharField(max_length=100, default="", blank=True, null=True) - lab = models.ForeignKey(Lab, null=True, on_delete=models.SET_NULL) - pdf = models.TextField(blank=True, default="") - idf = models.TextField(blank=True, default="") - - complete = models.BooleanField(default=False) - - class Meta: - db_table = 'booking' - - def save(self, *args, **kwargs): - """ - Save the booking if self.user is authorized and there is no overlapping booking. - - Raise PermissionError if the user is not authorized - Raise ValueError if there is an overlapping booking - """ - if self.start >= self.end: - raise ValueError('Start date is after end date') - # conflicts end after booking starts, and start before booking ends - conflicting_dates = Booking.objects.filter(resource=self.resource).exclude(id=self.id) - conflicting_dates = conflicting_dates.filter(end__gt=self.start) - conflicting_dates = conflicting_dates.filter(start__lt=self.end) - if conflicting_dates.count() > 0: - raise ValueError('This booking overlaps with another booking') - return super(Booking, self).save(*args, **kwargs) - - def delete(self, *args, **kwargs): - res = self.resource - self.resource = None - self.save() - resource_inventory.resource_manager.ResourceManager.getInstance().deleteResourceBundle(res) - return super(self.__class__, self).delete(*args, **kwargs) - - def __str__(self): - return str(self.purpose) + ' from ' + str(self.start) + ' until ' + str(self.end) |