Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions backend/gsr_booking/data/gsr_data.csv
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
LID,GID,NAME,SERVICE
JMHH,1,Huntsman,wharton
ARB,6,Academic Research,wharton
3620,6102,Albrecht Music Library,libcal
2634,1914,Penn Museum Library,libcal
1086,1889,Weigle,libcal
2495,1886,Education Commons,libcal
2587,4368,Lippincott,libcal
Expand Down
24 changes: 24 additions & 0 deletions backend/gsr_booking/management/commands/update_wharton_status.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
from django.contrib.auth import get_user_model
from django.core.management.base import BaseCommand

from gsr_booking.api_wrapper import WhartonBookingWrapper
from gsr_booking.models import GroupMembership


class Command(BaseCommand):
help = "Updates Wharton privelige status for all users."

def handle(self, *args, **kwargs):
users = GroupMembership.objects.values_list("user__username", flat=True).distinct()
print(f"Checking {len(users)} users...")
for username in users:
user = get_user_model().objects.get(username=username)
is_wharton = WhartonBookingWrapper().is_wharton(user)
memberships = GroupMembership.objects.filter(user__username=user)
for membership in memberships:
if membership.is_wharton != is_wharton:
membership.is_wharton = is_wharton
membership.save()
status = "now" if is_wharton else "no longer"
print(f"User {user} is {status} a Wharton user.")
print("Done updating Wharton statuses.")
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

2 changes: 1 addition & 1 deletion backend/tests/gsr_booking/test_gsr_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ def test_get_location(self):
if entry["id"] == 2:
self.assertEquals(entry["name"], "Academic Research")
if entry["id"] == 3:
self.assertEquals(entry["name"], "Weigle")
self.assertEquals(entry["name"], "Albrecht Music Library")


class TestGSRFunctions(TestCase):
Expand Down
Loading