aboutsummaryrefslogtreecommitdiffstats
path: root/src/booking/models.py
diff options
context:
space:
mode:
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):