Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Develop #408

Merged
merged 6 commits into from
Apr 26, 2024
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: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
ARG DJANGO_CONTAINER_VERSION=2.0.2
ARG DJANGO_CONTAINER_VERSION=2.0.3

FROM us-docker.pkg.dev/uwit-mci-axdd/containers/django-container:${DJANGO_CONTAINER_VERSION} as app-prebundler-container

Expand Down
8 changes: 6 additions & 2 deletions compass/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
from compass.dao.group import is_group_member
from compass.dao import current_datetime
from compass.utils import weekdays_before
from datetime import datetime, timezone


class AppUserManager(models.Manager):
Expand Down Expand Up @@ -232,8 +233,11 @@ def by_adviser(self, adviser_uwnetid, from_days=3):
kwargs = {'app_user__uwnetid': adviser_uwnetid, 'source': 'Checkin'}

if from_days is not None and from_days > 0:
start_date = weekdays_before(current_datetime().date(), from_days)
kwargs['checkin_date__gte'] = start_date
start_date = weekdays_before(current_datetime(), from_days)

# Reset the start_date to midnight and add TZ
kwargs['checkin_date__gte'] = start_date.replace(
hour=0, minute=0, second=0, tzinfo=timezone.utc)

return super().get_queryset().filter(**kwargs).values(
'student__system_key',
Expand Down
38 changes: 25 additions & 13 deletions compass/tests/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,12 @@

from django.test import TestCase
from compass.utils import weekdays_before
from datetime import date
from datetime import datetime, date


class TestUtils(TestCase):
def test_weekdays_before(self):
# date
val = weekdays_before(date(2024, 4, 19), offset_days=3)
self.assertEqual(str(val), '2024-04-16', 'Friday, offset=3')

Expand All @@ -17,21 +18,32 @@ def test_weekdays_before(self):
val = weekdays_before(date(2024, 4, 21), offset_days=3)
self.assertEqual(str(val), '2024-04-17', 'Sunday, offset=3')

val = weekdays_before(date(2024, 4, 22), offset_days=1)
self.assertEqual(str(val), '2024-04-19', 'Monday, offset=1')
# datetime
val = weekdays_before(datetime(2024, 4, 19, 10, 30), offset_days=3)
self.assertEqual(str(val), '2024-04-16 10:30:00', 'Friday, offset=3')

val = weekdays_before(date(2024, 4, 22), offset_days=2)
self.assertEqual(str(val), '2024-04-18', 'Monday, offset=2')
val = weekdays_before(datetime(2024, 4, 20, 0, 1), offset_days=3)
self.assertEqual(str(val), '2024-04-17 00:01:00', 'Saturday, offset=3')

val = weekdays_before(date(2024, 4, 22), offset_days=3)
self.assertEqual(str(val), '2024-04-17', 'Monday, offset=3')
val = weekdays_before(datetime(2024, 4, 21, 23, 59), offset_days=3)
self.assertEqual(str(val), '2024-04-17 23:59:00', 'Sunday, offset=3')

val = weekdays_before(datetime(2024, 4, 22), offset_days=1)
self.assertEqual(str(val), '2024-04-19 00:00:00', 'Monday, offset=1')

val = weekdays_before(datetime(2024, 4, 22), offset_days=2)
self.assertEqual(str(val), '2024-04-18 00:00:00', 'Monday, offset=2')

val = weekdays_before(datetime(2024, 4, 22), offset_days=3)
self.assertEqual(str(val), '2024-04-17 00:00:00', 'Monday, offset=3')

# Bad offsets
val = weekdays_before(date(2024, 4, 22), offset_days=None)
self.assertEqual(str(val), '2024-04-22', 'Monday, offset=None')
val = weekdays_before(datetime(2024, 4, 22), offset_days=None)
self.assertEqual(
str(val), '2024-04-22 00:00:00', 'Monday, offset=None')

val = weekdays_before(date(2024, 4, 22), offset_days=-5)
self.assertEqual(str(val), '2024-04-22', 'Monday, offset=-5')
val = weekdays_before(datetime(2024, 4, 22), offset_days=-5)
self.assertEqual(str(val), '2024-04-22 00:00:00', 'Monday, offset=-5')

val = weekdays_before(date(2024, 4, 22), offset_days=0)
self.assertEqual(str(val), '2024-04-22', 'Monday, offset=0')
val = weekdays_before(datetime(2024, 4, 22), offset_days=0)
self.assertEqual(str(val), '2024-04-22 00:00:00', 'Monday, offset=0')
2 changes: 1 addition & 1 deletion compass/utils.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# Copyright 2024 UW-IT, University of Washington
# SPDX-License-Identifier: Apache-2.0

from datetime import date, timedelta
from datetime import timedelta


def weekdays_before(end_date, offset_days=3):
Expand Down
12 changes: 7 additions & 5 deletions compass/views/api/student.py
Original file line number Diff line number Diff line change
Expand Up @@ -286,16 +286,18 @@ def get(self, request, uwregid):

transcript_data = []
for transcript in transcripts:
term = get_term_by_year_and_quarter(
transcript.tran_term.year,
TERMS[transcript.tran_term.quarter])

transcript_dict = transcript.to_dict()
try:
term = get_term_by_year_and_quarter(
transcript.tran_term.year,
TERMS[transcript.tran_term.quarter])

class_schedule = get_schedule_by_regid_and_term(
uwregid, term)
transcript_dict['class_schedule'] = class_schedule.json_data()
except DataFailureException:
except DataFailureException as ex:
logger.info(
f'Error fetching class schedule for {uwregid}: {ex}')
transcript_dict['class_schedule'] = None
transcript_data.append(transcript_dict)

Expand Down
Loading