aboutsummaryrefslogtreecommitdiffstats
path: root/src/booking/models.py
diff options
context:
space:
mode:
authorSawyer Bergeron <sbergeron@iol.unh.edu>2018-01-05 16:07:13 -0500
committerSawyer Bergeron <sbergeron@iol.unh.edu>2018-01-09 15:03:34 -0500
commita1df798486c60c911dfb2e6c2c487f7bcb7f6d01 (patch)
tree60bec95b5de53c332ab1101240095940e5a4554b /src/booking/models.py
parentc81da17a046f1ad81f05de8a242b14ec02cf7c9a (diff)
Implement Booking Modification Interface
Jira: PHAROS-330 Users can change start date if it has not already occurred, and can change end date, purpose, and both installer and scenario. Standard checks apply similar to when initially creating a booking. Change-Id: Ibae7fe91a58bd6e0741db065265c05c3823bdc27 Signed-off-by: Sawyer Bergeron <sbergeron@iol.unh.edu>
Diffstat (limited to 'src/booking/models.py')
-rw-r--r--src/booking/models.py8
1 files changed, 8 insertions, 0 deletions
diff --git a/src/booking/models.py b/src/booking/models.py
index 0bf5961..9156484 100644
--- a/src/booking/models.py
+++ b/src/booking/models.py
@@ -13,6 +13,8 @@ from django.contrib.auth.models import User
from django.db import models
from jira import JIRA
from jira import JIRAError
+from django.utils.crypto import get_random_string
+import hashlib
from dashboard.models import Resource
@@ -40,10 +42,12 @@ class Opsys(models.Model):
class Booking(models.Model):
id = models.AutoField(primary_key=True)
+ changeid = models.TextField(default='initial', blank=True, null=True)
user = models.ForeignKey(User, models.CASCADE) # delete if user is deleted
resource = models.ForeignKey(Resource, models.PROTECT)
start = models.DateTimeField()
end = models.DateTimeField()
+ reset = models.BooleanField(default=False)
jira_issue_id = models.IntegerField(null=True)
jira_issue_status = models.CharField(max_length=50)
@@ -78,6 +82,10 @@ class Booking(models.Model):
conflicting_dates = conflicting_dates.filter(start__lt=self.end)
if conflicting_dates.count() > 0:
raise ValueError('This booking overlaps with another booking')
+ if not self.changeid:
+ self.changeid = self.id
+ else:
+ self.changeid = hashlib.md5(self.changeid.encode() + get_random_string(length=32).encode()).hexdigest()
return super(Booking, self).save(*args, **kwargs)
def __str__(self):