Skip to content

Commit 8f6bbf5

Browse files
authored
add field to GSR for the number of days a GSR is bookable in advance. (#402)
4 for AGH, 7 for everything else
1 parent ba2dff6 commit 8f6bbf5

7 files changed

Lines changed: 65 additions & 21 deletions

File tree

backend/gsr_booking/admin.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ class GSRAdmin(admin.ModelAdmin):
3434
def get_queryset(self, request):
3535
return GSR.all_objects.all()
3636

37-
list_display = ["name", "kind", "lid", "gid", "in_use"]
37+
list_display = ["name", "kind", "lid", "gid", "in_use", "bookable_days"]
3838
search_fields = ["name", "lid", "gid"]
3939
ordering = ["-in_use"]
4040

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
1-
LID,GID,NAME,SERVICE
2-
JMHH,1,Huntsman,wharton
3-
20157,42437,Amy Gutmann Hall,penngroups
4-
ARB,6,Academic Research,wharton
5-
3620,6102,Albrecht Music Library,libcal
6-
2634,1914,Penn Museum Library,libcal
7-
1086,1889,Weigle,libcal
8-
2495,1886,Education Commons,libcal
9-
2587,4368,Lippincott,libcal
10-
4370,7426,Perelman Center,libcal
11-
1086,4660,VP Ground Floor,libcal
12-
1090,1909,Levin Building,libcal
13-
2683,1885,Biotech Commons,libcal
14-
1086,4659,VP 3rd Floor,libcal
15-
1086,1891,VP 4th Floor,libcal
1+
LID,GID,NAME,SERVICE,BOOKABLE_DAYS
2+
JMHH,1,Huntsman,wharton,7
3+
20157,42437,Amy Gutmann Hall,penngroups,4
4+
ARB,6,Academic Research,wharton,7
5+
3620,6102,Albrecht Music Library,libcal,7
6+
2634,1914,Penn Museum Library,libcal,7
7+
1086,1889,Weigle,libcal,7
8+
2495,1886,Education Commons,libcal,7
9+
2587,4368,Lippincott,libcal,7
10+
4370,7426,Perelman Center,libcal,7
11+
1086,4660,VP Ground Floor,libcal,7
12+
1090,1909,Levin Building,libcal,7
13+
2683,1885,Biotech Commons,libcal,7
14+
1086,4659,VP 3rd Floor,libcal,7
15+
1086,1891,VP 4th Floor,libcal,7

backend/gsr_booking/management/commands/load_gsrs.py

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ def handle(self, *args, **kwargs):
1111
with open("gsr_booking/data/gsr_data.csv") as data:
1212
reader = csv.reader(data)
1313
next(reader)
14-
for lid, gid, name, service in reader:
14+
for lid, gid, name, service, bookable_days in reader:
1515
# gets image from s3 given the lid and gid
1616
# TODO: fix image url!
1717
image_url = (
@@ -23,7 +23,14 @@ def handle(self, *args, **kwargs):
2323
else GSR.KIND_WHARTON if service == "wharton" else GSR.KIND_LIBCAL
2424
)
2525
GSR.objects.update_or_create(
26-
lid=lid, gid=gid, defaults={"name": name, "kind": kind, "image_url": image_url}
26+
lid=lid,
27+
gid=gid,
28+
defaults={
29+
"name": name,
30+
"kind": kind,
31+
"image_url": image_url,
32+
"bookable_days": int(bookable_days),
33+
},
2734
)
2835

2936
# Note: Caches are automatically cleared by post_save signals on GSR model
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
# Generated by Django 5.0.2 on 2026-02-21 23:14
2+
3+
from django.db import migrations, models
4+
5+
6+
class Migration(migrations.Migration):
7+
8+
dependencies = [
9+
("gsr_booking", "0014_merge_20251207_1429"),
10+
]
11+
12+
operations = [
13+
migrations.AddField(
14+
model_name="gsr",
15+
name="bookable_days",
16+
field=models.IntegerField(default=7),
17+
),
18+
]

backend/gsr_booking/models.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,7 @@ class GSR(models.Model):
117117
lid = models.CharField(max_length=255)
118118
gid = models.IntegerField(null=True)
119119
name = models.CharField(max_length=255)
120+
bookable_days = models.IntegerField(default=7)
120121
image_url = models.URLField()
121122

122123
in_use = models.BooleanField(default=True)

backend/tests/gsr_booking/test_gsr_views.py

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ def create_test_gsrs(cls):
2323
"kind": GSR.KIND_WHARTON,
2424
"image_url": "https://s3.us-east-2.amazonaws.com/labs.api/gsr/lid-JMHH-gid-1.jpg",
2525
"in_use": True,
26+
"bookable_days": 7,
2627
},
2728
)
2829
cls.agh_gsr, _ = GSR.objects.get_or_create(
@@ -33,6 +34,7 @@ def create_test_gsrs(cls):
3334
"kind": GSR.KIND_PENNGROUPS,
3435
"image_url": "https://s3.us-east-2.amazonaws.com/labs.api/gsr/lid-20157-gid-42437.jpg",
3536
"in_use": True,
37+
"bookable_days": 4,
3638
},
3739
)
3840
cls.weigle_gsr, _ = GSR.objects.get_or_create(
@@ -43,6 +45,7 @@ def create_test_gsrs(cls):
4345
"kind": GSR.KIND_LIBCAL,
4446
"image_url": "https://s3.us-east-2.amazonaws.com/labs.api/gsr/lid-1086-gid-1889.jpg",
4547
"in_use": True,
48+
"bookable_days": 7,
4649
},
4750
)
4851

@@ -104,11 +107,26 @@ def test_get_location(self):
104107
"""Test that the locations endpoint returns all GSRs without auth checks"""
105108
response = self.client.get(reverse("locations"))
106109
res_json = json.loads(response.content)
110+
# TODO: add AGH back to availability route
107111
for entry in res_json:
108112
if entry["id"] == 1:
109113
self.assertEquals(entry["name"], "Huntsman")
114+
self.assertEquals(entry["kind"], GSR.KIND_WHARTON)
115+
self.assertEquals(entry["lid"], "JMHH")
116+
self.assertEquals(entry["gid"], 1)
117+
self.assertEquals(entry["bookable_days"], 7)
110118
if entry["id"] == 2:
119+
self.assertEquals(entry["name"], "Amy Gutmann Hall")
120+
self.assertEquals(entry["kind"], GSR.KIND_PENNGROUPS)
121+
self.assertEquals(entry["lid"], "20157")
122+
self.assertEquals(entry["gid"], 42437)
123+
self.assertEquals(entry["bookable_days"], 4)
124+
if entry["id"] == 3:
111125
self.assertEquals(entry["name"], "Weigle")
126+
self.assertEquals(entry["kind"], GSR.KIND_LIBCAL)
127+
self.assertEquals(entry["lid"], "1086")
128+
self.assertEquals(entry["gid"], 1889)
129+
self.assertEquals(entry["bookable_days"], 7)
112130

113131
@mock.patch("gsr_booking.views.WhartonGSRBooker.is_wharton", return_value=False)
114132
@mock.patch("gsr_booking.views.PennGroupsGSRBooker.is_seas", return_value=False)
@@ -234,14 +252,15 @@ def test_recent(self):
234252
response = self.client.get(reverse("recent-gsrs"))
235253
res_json = json.loads(response.content)
236254
self.assertEqual(2, len(res_json))
237-
self.assertEqual(6, len(res_json[0]))
238-
self.assertEqual(6, len(res_json[1]))
255+
self.assertEqual(7, len(res_json[0]))
256+
self.assertEqual(7, len(res_json[1]))
239257
self.assertIn("id", res_json[0])
240258
self.assertIn("kind", res_json[0])
241259
self.assertIn("lid", res_json[0])
242260
self.assertIn("gid", res_json[0])
243261
self.assertIn("name", res_json[0])
244262
self.assertIn("image_url", res_json[0])
263+
self.assertIn("bookable_days", res_json[0])
245264
self.assertNotEqual(res_json[0]["id"], res_json[1]["id"])
246265

247266
@mock.patch("gsr_booking.api_wrapper.WhartonBookingWrapper.is_wharton", is_wharton_false)

backend/tests/gsr_booking/test_share_codes.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,6 @@ def test_view_shared_booking_public_access(self):
124124
payload = json.loads(response.content)
125125

126126
# Should only contain booking info and not owner info
127-
print("Payload: ", payload)
128127
self.assertIn("booking_id", payload)
129128
self.assertIn("gsr", payload)
130129
self.assertIn("lid", payload["gsr"])

0 commit comments

Comments
 (0)