diff options
author | 2016-10-05 14:10:56 +0200 | |
---|---|---|
committer | 2016-10-05 14:20:13 +0200 | |
commit | 7c3d7e75f50c3e39eb1c752391c6336431543288 (patch) | |
tree | da5a8f0fe69bc33e5a0de646d407e7dd013a227f /tools/pharos-dashboard/src/booking/models.py | |
parent | 94f19e02d37b1d7af807854cae910c83d34ce0cd (diff) |
Add Installer and Scenario fields to bookings
JIRA: PHAROS-272
Change-Id: I28f44bfadb1dbe3cb0caca0a8038fba988cf26f9
Signed-off-by: maxbr <maxbr@mi.fu-berlin.de>
Diffstat (limited to 'tools/pharos-dashboard/src/booking/models.py')
-rw-r--r-- | tools/pharos-dashboard/src/booking/models.py | 31 |
1 files changed, 16 insertions, 15 deletions
diff --git a/tools/pharos-dashboard/src/booking/models.py b/tools/pharos-dashboard/src/booking/models.py index 200dc830..88ab5589 100644 --- a/tools/pharos-dashboard/src/booking/models.py +++ b/tools/pharos-dashboard/src/booking/models.py @@ -16,6 +16,20 @@ from jira import JIRAError from dashboard.models import Resource from django.conf import settings +class Installer(models.Model): + id = models.AutoField(primary_key=True) + name = models.CharField(max_length=30) + + def __str__(self): + return self.name + +class Scenario(models.Model): + id = models.AutoField(primary_key=True) + name = models.CharField(max_length=300) + + def __str__(self): + return self.name + class Booking(models.Model): id = models.AutoField(primary_key=True) @@ -26,6 +40,8 @@ class Booking(models.Model): jira_issue_id = models.IntegerField(null=True) jira_issue_status = models.CharField(max_length=50) + installer = models.ForeignKey(Installer, models.DO_NOTHING, null=True) + scenario = models.ForeignKey(Scenario, models.DO_NOTHING, null=True) purpose = models.CharField(max_length=300, blank=False) class Meta: @@ -40,27 +56,12 @@ class Booking(models.Model): except JIRAError: return None - def authorization_test(self): - """ - Return True if self.user is authorized to make this booking. - """ - user = self.user - # Check if User is troubleshooter / admin - if user.has_perm('booking.add_booking'): - return True - # Check if User owns this resource - if user == self.resource.owner: - return True - return False - 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 not self.authorization_test(): - raise PermissionError('Insufficient permissions to save this booking.') if self.start >= self.end: raise ValueError('Start date is after end date') # conflicts end after booking starts, and start before booking ends |