summaryrefslogtreecommitdiffstats
path: root/dashboard/src/booking
diff options
context:
space:
mode:
Diffstat (limited to 'dashboard/src/booking')
-rw-r--r--dashboard/src/booking/admin.py2
-rw-r--r--dashboard/src/booking/models.py7
-rw-r--r--dashboard/src/booking/stats.py10
-rw-r--r--dashboard/src/booking/tests/test_models.py63
-rw-r--r--dashboard/src/booking/urls.py9
-rw-r--r--dashboard/src/booking/views.py28
6 files changed, 69 insertions, 50 deletions
diff --git a/dashboard/src/booking/admin.py b/dashboard/src/booking/admin.py
index 2beb05b..162777e 100644
--- a/dashboard/src/booking/admin.py
+++ b/dashboard/src/booking/admin.py
@@ -11,6 +11,6 @@
from django.contrib import admin
-from booking.models import *
+from booking.models import Booking
admin.site.register(Booking)
diff --git a/dashboard/src/booking/models.py b/dashboard/src/booking/models.py
index adfc28d..d0c77b4 100644
--- a/dashboard/src/booking/models.py
+++ b/dashboard/src/booking/models.py
@@ -11,11 +11,8 @@
from resource_inventory.models import ResourceBundle, ConfigBundle
from account.models import Lab
-from django.conf import settings
from django.contrib.auth.models import User
from django.db import models
-from jira import JIRA
-from jira import JIRAError
import resource_inventory.resource_manager
@@ -47,7 +44,7 @@ class Opsys(models.Model):
class Booking(models.Model):
id = models.AutoField(primary_key=True)
- owner = models.ForeignKey(User, models.CASCADE, related_name='owner') # delete if user is deleted
+ owner = models.ForeignKey(User, models.CASCADE, related_name='owner')
collaborators = models.ManyToManyField(User, related_name='collaborators')
start = models.DateTimeField()
end = models.DateTimeField()
@@ -56,7 +53,7 @@ class Booking(models.Model):
jira_issue_status = models.CharField(max_length=50, blank=True)
purpose = models.CharField(max_length=300, blank=False)
ext_count = models.IntegerField(default=2)
- resource = models.ForeignKey(ResourceBundle, on_delete=models.SET_NULL, null=True) #need to decide behavior here on delete
+ resource = models.ForeignKey(ResourceBundle, on_delete=models.SET_NULL, null=True)
config_bundle = models.ForeignKey(ConfigBundle, on_delete=models.SET_NULL, null=True)
project = models.CharField(max_length=100, default="", blank=True, null=True)
lab = models.ForeignKey(Lab, null=True, on_delete=models.SET_NULL)
diff --git a/dashboard/src/booking/stats.py b/dashboard/src/booking/stats.py
index 31f7ef1..b706577 100644
--- a/dashboard/src/booking/stats.py
+++ b/dashboard/src/booking/stats.py
@@ -19,9 +19,11 @@ class StatisticsManager(object):
Will return a dictionary of names and 2-D array of x and y data points.
e.g. {"plot1": [["x1", "x2", "x3"],["y1", "y2", "y3]]}
x values will be dates in string
- every change (booking start / end) will be reflected, instead of one data point per day
- y values are the integer number of bookings/users active at some point in the given date
- span is the number of days to plot. The last x value will always be the current time
+ every change (booking start / end) will be reflected,
+ instead of one data point per day
+ y values are the integer number of bookings/users active at
+ some point in the given date span is the number of days to plot.
+ The last x value will always be the current time
"""
x_set = set()
x = []
@@ -29,7 +31,7 @@ class StatisticsManager(object):
users = []
now = datetime.datetime.now(pytz.utc)
delta = datetime.timedelta(days=span)
- end = now-delta
+ end = now - delta
bookings = Booking.objects.filter(start__lte=now, end__gte=end)
for booking in bookings:
x_set.add(booking.start)
diff --git a/dashboard/src/booking/tests/test_models.py b/dashboard/src/booking/tests/test_models.py
index a83f817..c7fb25d 100644
--- a/dashboard/src/booking/tests/test_models.py
+++ b/dashboard/src/booking/tests/test_models.py
@@ -11,25 +11,33 @@
from datetime import timedelta
-from django.contrib.auth.models import Permission
+from django.contrib.auth.models import Permission, User
from django.test import TestCase
from django.utils import timezone
-from booking.models import *
+# from booking.models import *
+from booking.models import Booking
from resource_inventory.models import ResourceBundle, GenericResourceBundle, ConfigBundle
+
class BookingModelTestCase(TestCase):
+
count = 0
+
def setUp(self):
self.owner = User.objects.create(username='owner')
self.res1 = ResourceBundle.objects.create(
- template=GenericResourceBundle.objects.create(name="gbundle" + str(self.count))
- )
+ template=GenericResourceBundle.objects.create(
+ name="gbundle" + str(self.count)
+ )
+ )
self.count += 1
self.res2 = ResourceBundle.objects.create(
- template=GenericResourceBundle.objects.create(name="gbundle2" + str(self.count))
- )
+ template=GenericResourceBundle.objects.create(
+ name="gbundle2" + str(self.count)
+ )
+ )
self.count += 1
self.user1 = User.objects.create(username='user1')
@@ -37,12 +45,15 @@ class BookingModelTestCase(TestCase):
self.user1.user_permissions.add(self.add_booking_perm)
self.user1 = User.objects.get(pk=self.user1.id)
- self.config_bundle = ConfigBundle.objects.create(owner=self.user1, name="test config")
+ self.config_bundle = ConfigBundle.objects.create(
+ owner=self.user1,
+ name="test config"
+ )
def test_start_end(self):
"""
- if the start of a booking is greater or equal then the end, saving should raise a
- ValueException
+ if the start of a booking is greater or equal then the end,
+ saving should raise a ValueException
"""
start = timezone.now()
end = start - timedelta(weeks=1)
@@ -54,7 +65,7 @@ class BookingModelTestCase(TestCase):
resource=self.res1,
owner=self.user1,
config_bundle=self.config_bundle
- )
+ )
end = start
self.assertRaises(
ValueError,
@@ -64,11 +75,12 @@ class BookingModelTestCase(TestCase):
resource=self.res1,
owner=self.user1,
config_bundle=self.config_bundle
- )
+ )
def test_conflicts(self):
"""
- saving an overlapping booking on the same resource should raise a ValueException
+ saving an overlapping booking on the same resource
+ should raise a ValueException
saving for different resources should succeed
"""
start = timezone.now()
@@ -80,8 +92,8 @@ class BookingModelTestCase(TestCase):
owner=self.user1,
resource=self.res1,
config_bundle=self.config_bundle
- )
)
+ )
self.assertRaises(
ValueError,
@@ -91,7 +103,8 @@ class BookingModelTestCase(TestCase):
resource=self.res1,
owner=self.user1,
config_bundle=self.config_bundle
- )
+ )
+
self.assertRaises(
ValueError,
Booking.objects.create,
@@ -100,7 +113,7 @@ class BookingModelTestCase(TestCase):
resource=self.res1,
owner=self.user1,
config_bundle=self.config_bundle
- )
+ )
self.assertRaises(
ValueError,
@@ -110,7 +123,7 @@ class BookingModelTestCase(TestCase):
resource=self.res1,
owner=self.user1,
config_bundle=self.config_bundle
- )
+ )
self.assertRaises(
ValueError,
@@ -120,7 +133,7 @@ class BookingModelTestCase(TestCase):
resource=self.res1,
owner=self.user1,
config_bundle=self.config_bundle
- )
+ )
self.assertRaises(
ValueError,
@@ -130,7 +143,7 @@ class BookingModelTestCase(TestCase):
resource=self.res1,
owner=self.user1,
config_bundle=self.config_bundle
- )
+ )
self.assertRaises(
ValueError,
@@ -140,7 +153,7 @@ class BookingModelTestCase(TestCase):
resource=self.res1,
owner=self.user1,
config_bundle=self.config_bundle
- )
+ )
self.assertTrue(
Booking.objects.create(
@@ -149,8 +162,9 @@ class BookingModelTestCase(TestCase):
owner=self.user1,
resource=self.res1,
config_bundle=self.config_bundle
- )
)
+ )
+
self.assertTrue(
Booking.objects.create(
start=end,
@@ -158,8 +172,8 @@ class BookingModelTestCase(TestCase):
owner=self.user1,
resource=self.res1,
config_bundle=self.config_bundle
- )
)
+ )
self.assertTrue(
Booking.objects.create(
@@ -168,8 +182,8 @@ class BookingModelTestCase(TestCase):
owner=self.user1,
resource=self.res1,
config_bundle=self.config_bundle
- )
)
+ )
self.assertTrue(
Booking.objects.create(
@@ -178,8 +192,8 @@ class BookingModelTestCase(TestCase):
owner=self.user1,
resource=self.res1,
config_bundle=self.config_bundle
- )
)
+ )
self.assertTrue(
Booking.objects.create(
@@ -188,8 +202,8 @@ class BookingModelTestCase(TestCase):
owner=self.user1,
resource=self.res2,
config_bundle=self.config_bundle
- )
)
+ )
def test_extensions(self):
"""
@@ -223,4 +237,3 @@ class BookingModelTestCase(TestCase):
self.assertTrue(booking.save())
except Exception:
self.fail("save() threw an exception")
-
diff --git a/dashboard/src/booking/urls.py b/dashboard/src/booking/urls.py
index 88fbb0a..4d00b7f 100644
--- a/dashboard/src/booking/urls.py
+++ b/dashboard/src/booking/urls.py
@@ -26,7 +26,14 @@ Including another URLconf
"""
from django.conf.urls import url
-from booking.views import *
+from booking.views import (
+ booking_detail_view,
+ BookingDeleteView,
+ bookingDelete,
+ BookingListView,
+ booking_stats_view,
+ booking_stats_json
+)
app_name = "booking"
urlpatterns = [
diff --git a/dashboard/src/booking/views.py b/dashboard/src/booking/views.py
index a0ea31d..ab43519 100644
--- a/dashboard/src/booking/views.py
+++ b/dashboard/src/booking/views.py
@@ -11,10 +11,8 @@
from django.contrib import messages
from django.shortcuts import get_object_or_404
from django.http import JsonResponse
-from django.urls import reverse
from django.utils import timezone
from django.views import View
-from django.views.generic import FormView
from django.views.generic import TemplateView
from django.shortcuts import redirect, render
import json
@@ -107,22 +105,24 @@ def booking_detail_view(request, booking_id):
allowed_users.add(booking.owner)
if user not in allowed_users:
return render(request, "dashboard/login.html", {'title': 'This page is private'})
- return render(request, "booking/booking_detail.html", {
- 'title': 'Booking Details',
- 'booking': booking,
- 'pdf': ResourceManager().makePDF(booking.resource),
- 'user_id': user.id})
+
+ return render(
+ request,
+ "booking/booking_detail.html",
+ {
+ 'title': 'Booking Details',
+ 'booking': booking,
+ 'pdf': ResourceManager().makePDF(booking.resource),
+ 'user_id': user.id
+ })
def booking_stats_view(request):
return render(
- request,
- "booking/stats.html",
- context={
- "data": StatisticsManager.getContinuousBookingTimeSeries(),
- "title": "Booking Statistics"
- }
- )
+ request,
+ "booking/stats.html",
+ context={"data": StatisticsManager.getContinuousBookingTimeSeries(), "title": "Booking Statistics"}
+ )
def booking_stats_json(request):