Skip to content

Commit 42c63df

Browse files
Dataproducts instead of old lrs (#89)
* Create environment variables for mongo and refactor function to get deadlines * modify get_student_deadlines to fetch from dataproduct * Add env variable for dataproduct * move LRS Mongo settings from common.py to production.py * Remove functions to pull project data from Zoho * Change dataproduct name to more accurately reflect that mentor data is also being used * Remove MongoClient import as it's been moved to production.py Co-authored-by: Igor <[email protected]>
1 parent 07c6b62 commit 42c63df

File tree

4 files changed

+7
-125
lines changed

4 files changed

+7
-125
lines changed

lms/djangoapps/ci_program/tests.py

Lines changed: 0 additions & 66 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11

22
from django.urls import reverse
33
from django.test import TestCase, override_settings
4-
from freezegun import freeze_time
5-
from .utils import get_student_deadlines_from_zoho_data
64
from .models import Program
75
from django.contrib.auth.models import User
86
from django.core import mail
@@ -14,70 +12,6 @@ class ProjectDeadlinesUnitTest(TestCase):
1412
def setUp(self):
1513
self.max_diff = None
1614

17-
@freeze_time("2020-10-01 13:00")
18-
def test_parse(self):
19-
self.api_data = {
20-
'Interactive_submission_deadline': '2020-10-01',
21-
'Interactive_latest_submission': None,
22-
'User_Centric_submission_deadline': '2020-09-01',
23-
'User_Centric_latest_submission': '{}',
24-
'Data_Centric_submission_deadline': '2020-11-01',
25-
'Data_Centric_latest_submission': None,
26-
}
27-
result = get_student_deadlines_from_zoho_data(self.api_data)
28-
29-
self.assertEqual([
30-
{'name': 'Project 1',
31-
'submission_deadline': '2020-09-01',
32-
'latest_submission': '{}',
33-
'overdue': False,
34-
'next_project': False},
35-
36-
{'name': 'Project 2',
37-
'submission_deadline': '2020-10-01',
38-
'latest_submission': None,
39-
'overdue': True,
40-
'next_project': False},
41-
42-
{'name': 'Project 3',
43-
'submission_deadline': '2020-11-01',
44-
'latest_submission': None,
45-
'overdue': False,
46-
'next_project': True},
47-
], result)
48-
49-
@freeze_time("2020-08-01 13:00")
50-
def test_next_project(self):
51-
self.api_data = {
52-
'Interactive_submission_deadline': '2020-10-01',
53-
'Interactive_latest_submission': '{}',
54-
'User_Centric_submission_deadline': '2020-09-01',
55-
'User_Centric_latest_submission': '{}',
56-
'Data_Centric_submission_deadline': '2020-11-01',
57-
'Data_Centric_latest_submission': None,
58-
}
59-
result = get_student_deadlines_from_zoho_data(self.api_data)
60-
61-
self.assertEqual([
62-
{'name': 'Project 1',
63-
'submission_deadline': '2020-09-01',
64-
'latest_submission': '{}',
65-
'overdue': False,
66-
'next_project': False},
67-
68-
{'name': 'Project 2',
69-
'submission_deadline': '2020-10-01',
70-
'latest_submission': '{}',
71-
'overdue': False,
72-
'next_project': False},
73-
74-
{'name': 'Project 3',
75-
'submission_deadline': '2020-11-01',
76-
'latest_submission': None,
77-
'overdue': False,
78-
'next_project': True},
79-
], result)
80-
8115
def test_program_email_template(self):
8216
program = Program(program_code_friendly_name='nonexistant')
8317
program.enrollment_type = 0

lms/djangoapps/ci_program/utils.py

Lines changed: 1 addition & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -19,61 +19,4 @@ def is_overdue(data):
1919
now = datetime.now()
2020
project_deadline = datetime.strptime(submission_deadline, '%Y-%m-%d')
2121
project_deadline = project_deadline + timedelta(hours=12)
22-
return now > project_deadline and not data['latest_submission']
23-
24-
25-
def endswith(key):
26-
for field in FIELDS:
27-
if key.endswith(field):
28-
return key[:-len(field)], key[-len(field):]
29-
return None, None
30-
31-
32-
def get_student_deadlines(student_email):
33-
cache_key = '%s_project_deadlines' % student_email
34-
if cache.get(cache_key):
35-
return cache.get(cache_key)
36-
37-
student_record = get_student_record_from_zoho(student_email)
38-
if student_record:
39-
student_deadlines = get_student_deadlines_from_zoho_data(student_record)
40-
cache.set(cache_key, student_deadlines)
41-
else:
42-
student_deadlines = []
43-
return student_deadlines
44-
45-
46-
def get_student_deadlines_from_zoho_data(zoho_record):
47-
student_data = {}
48-
for key, record in zoho_record.items():
49-
project_key, record_id = endswith(key)
50-
if not project_key:
51-
continue
52-
53-
student_data.setdefault(project_key, {})
54-
student_data[project_key][record_id] = record
55-
56-
# Filter Blank submission deadlines
57-
student_data = dict([
58-
(key, submission) for (key, submission) in student_data.items() if
59-
submission.get('submission_deadline')])
60-
61-
sorted_student_data = sorted(
62-
student_data.values(),
63-
key=lambda k: (k.get('submission_deadline') or ''))
64-
65-
for index, data in enumerate(sorted_student_data, start=1):
66-
data['name'] = "Project %s" % index
67-
data['overdue'] = is_overdue(data)
68-
data['next_project'] = False
69-
70-
for data in sorted_student_data:
71-
if not data.get('submission_deadline'):
72-
continue
73-
74-
project_deadline = datetime.strptime(data['submission_deadline'], '%Y-%m-%d')
75-
if project_deadline > datetime.now() and not data['latest_submission']:
76-
data['next_project'] = True
77-
break
78-
79-
return sorted_student_data
22+
return now > project_deadline and not data['submission']

lms/djangoapps/ci_program/views.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
from django.core.cache import cache
77
from edxmako.shortcuts import render_to_response
88
from ci_program.models import Program
9-
from ci_program.utils import get_student_deadlines
109
from openedx.core.djangoapps.bookmarks.models import Bookmark
1110

1211

lms/envs/production.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1072,3 +1072,9 @@ def should_show_debug_toolbar(request):
10721072
MONGO_DB = MONGO_CLIENT[db]
10731073

10741074
CELERY_DEFAULT_QUEUE = AUTH_TOKENS.get("CELERY_DEFAULT_QUEUE")
1075+
1076+
### MONGO DATABASE
1077+
LRS_MONGO_HOST = AUTH_TOKENS.get('LRS_MONGO_HOST', 'mongodb://localhost:27017')
1078+
LRS_MONGO_CLIENT = MongoClient(host=LRS_MONGO_HOST, readPreference='secondaryPreferred')
1079+
LRS_MONGO_DB = LRS_MONGO_CLIENT[AUTH_TOKENS.get('LRS_MONGO_DB', 'dataproduct')]
1080+
LMS_STUDENT_PROJECT_AND_MENTOR_DATA = AUTH_TOKENS.get('LMS_STUDENT_PROJECT_AND_MENTOR_DATA', 'lms_student_project_and_mentor_data')

0 commit comments

Comments
 (0)