def test_virgin_fetch(self):
     details = CourseDetails.fetch(self.course.id)
     self.assertEqual(details.org, self.course.location.org,
                      "Org not copied into")
     self.assertEqual(details.course_id, self.course.location.course,
                      "Course_id not copied into")
     self.assertEqual(details.run, self.course.location.name,
                      "Course name not copied into")
     self.assertEqual(details.course_image_name, self.course.course_image)
     self.assertIsNotNone(details.start_date.tzinfo)
     self.assertIsNone(
         details.end_date,
         "end date somehow initialized " + str(details.end_date))
     self.assertIsNone(
         details.enrollment_start,
         "enrollment_start date somehow initialized " +
         str(details.enrollment_start))
     self.assertIsNone(
         details.enrollment_end,
         "enrollment_end date somehow initialized " +
         str(details.enrollment_end))
     self.assertIsNone(
         details.syllabus,
         "syllabus somehow initialized" + str(details.syllabus))
     self.assertIsNone(
         details.intro_video,
         "intro_video somehow initialized" + str(details.intro_video))
     self.assertIsNone(details.effort,
                       "effort somehow initialized" + str(details.effort))
     self.assertIsNone(
         details.language,
         "language somehow initialized" + str(details.language))
     self.assertFalse(details.self_paced)
Exemple #2
0
 def get_minimum_age(self, course_overview):
     """
     Get the representation for SerializerMethodField `minimum_age`
     Represents the minimum enrollment age for the course
     """
     # Note: This makes a call to the modulestore, unlike the other
     # fields from CourseSerializer, which get their data
     # from the CourseOverview object in SQL.
     courseDetails = CourseDetails.fetch(course_overview.id)
     return courseDetails.minimum_age
 def test_update_and_fetch(self):
     SelfPacedConfiguration(enabled=True).save()
     jsondetails = CourseDetails.fetch(self.course.id)
     jsondetails.syllabus = "<a href='foo'>bar</a>"
     # encode - decode to convert date fields and other data which changes form
     with self.store.branch_setting(ModuleStoreEnum.Branch.draft_preferred, self.course.id):
         self.assertEqual(
             CourseDetails.update_from_json(self.course.id, jsondetails.__dict__, self.user).syllabus,
             jsondetails.syllabus, "After set syllabus"
         )
         jsondetails.short_description = "Short Description"
         self.assertEqual(
             CourseDetails.update_from_json(self.course.id, jsondetails.__dict__, self.user).short_description,
             jsondetails.short_description, "After set short_description"
         )
         jsondetails.overview = "Overview"
         self.assertEqual(
             CourseDetails.update_from_json(self.course.id, jsondetails.__dict__, self.user).overview,
             jsondetails.overview, "After set overview"
         )
         jsondetails.intro_video = "intro_video"
         self.assertEqual(
             CourseDetails.update_from_json(self.course.id, jsondetails.__dict__, self.user).intro_video,
             jsondetails.intro_video, "After set intro_video"
         )
         jsondetails.effort = "effort"
         self.assertEqual(
             CourseDetails.update_from_json(self.course.id, jsondetails.__dict__, self.user).effort,
             jsondetails.effort, "After set effort"
         )
         jsondetails.self_paced = True
         self.assertEqual(
             CourseDetails.update_from_json(self.course.id, jsondetails.__dict__, self.user).self_paced,
             jsondetails.self_paced
         )
         jsondetails.start_date = datetime.datetime(2010, 10, 1, 0, tzinfo=UTC())
         self.assertEqual(
             CourseDetails.update_from_json(self.course.id, jsondetails.__dict__, self.user).start_date,
             jsondetails.start_date
         )
         jsondetails.end_date = datetime.datetime(2011, 10, 1, 0, tzinfo=UTC())
         self.assertEqual(
             CourseDetails.update_from_json(self.course.id, jsondetails.__dict__, self.user).end_date,
             jsondetails.end_date
         )
         jsondetails.course_image_name = "an_image.jpg"
         self.assertEqual(
             CourseDetails.update_from_json(self.course.id, jsondetails.__dict__, self.user).course_image_name,
             jsondetails.course_image_name
         )
         jsondetails.language = "hr"
         self.assertEqual(
             CourseDetails.update_from_json(self.course.id, jsondetails.__dict__, self.user).language,
             jsondetails.language
         )
    def test_toggle_pacing_during_course_run(self):
        self.course.start = datetime.datetime.now()
        self.store.update_item(self.course, self.user.id)

        details = CourseDetails.fetch(self.course.id)
        with self.store.branch_setting(ModuleStoreEnum.Branch.draft_preferred,
                                       self.course.id):
            updated_details = CourseDetails.update_from_json(
                self.course.id, dict(details.__dict__, self_paced=True),
                self.user)
        assert not updated_details.self_paced
    def test_toggle_pacing_during_course_run(self):
        SelfPacedConfiguration(enabled=True).save()
        self.course.start = datetime.datetime.now()
        self.store.update_item(self.course, self.user.id)

        details = CourseDetails.fetch(self.course.id)
        with self.store.branch_setting(ModuleStoreEnum.Branch.draft_preferred, self.course.id):
            updated_details = CourseDetails.update_from_json(
                self.course.id, dict(details.__dict__, self_paced=True), self.user
            )
        self.assertFalse(updated_details.self_paced)
 def test_virgin_fetch(self):
     details = CourseDetails.fetch(self.course.id)
     self.assertEqual(details.org, self.course.location.org, "Org not copied into")
     self.assertEqual(details.course_id, self.course.location.course, "Course_id not copied into")
     self.assertEqual(details.run, self.course.location.name, "Course name not copied into")
     self.assertEqual(details.course_image_name, self.course.course_image)
     self.assertIsNotNone(details.start_date.tzinfo)
     self.assertIsNone(details.end_date, "end date somehow initialized " + str(details.end_date))
     self.assertIsNone(
         details.enrollment_start, "enrollment_start date somehow initialized " + str(details.enrollment_start)
     )
     self.assertIsNone(
         details.enrollment_end, "enrollment_end date somehow initialized " + str(details.enrollment_end)
     )
     self.assertIsNone(details.syllabus, "syllabus somehow initialized" + str(details.syllabus))
     self.assertIsNone(details.intro_video, "intro_video somehow initialized" + str(details.intro_video))
     self.assertIsNone(details.effort, "effort somehow initialized" + str(details.effort))
     self.assertIsNone(details.language, "language somehow initialized" + str(details.language))
     self.assertFalse(details.self_paced)
Exemple #7
0
 def test_virgin_fetch(self):
     details = CourseDetails.fetch(self.course.id)
     assert details.org == self.course.location.org, 'Org not copied into'
     assert details.course_id == self.course.location.course, 'Course_id not copied into'
     assert details.run == self.course.location.block_id, 'Course name not copied into'
     assert details.course_image_name == self.course.course_image
     assert details.start_date.tzinfo is not None
     assert details.end_date is None, ('end date somehow initialized ' + str(details.end_date))
     assert details.enrollment_start is None,\
         ('enrollment_start date somehow initialized ' + str(details.enrollment_start))
     assert details.enrollment_end is None,\
         ('enrollment_end date somehow initialized ' + str(details.enrollment_end))
     assert details.certificate_available_date is None,\
         ('certificate_available_date date somehow initialized ' + str(details.certificate_available_date))
     assert details.syllabus is None, ('syllabus somehow initialized' + str(details.syllabus))
     assert details.intro_video is None, ('intro_video somehow initialized' + str(details.intro_video))
     assert details.effort is None, ('effort somehow initialized' + str(details.effort))
     assert details.language is None, ('language somehow initialized' + str(details.language))
     assert not details.self_paced
    def test_update_and_fetch(self):
        jsondetails = CourseDetails.fetch(self.course.id)
        jsondetails.syllabus = "<a href='foo'>bar</a>"
        # encode - decode to convert date fields and other data which changes form
        with self.store.branch_setting(ModuleStoreEnum.Branch.draft_preferred,
                                       self.course.id):
            assert CourseDetails.update_from_json(self.course.id, jsondetails.__dict__, self.user).syllabus ==\
                   jsondetails.syllabus, 'After set syllabus'
            jsondetails.short_description = "Short Description"
            assert CourseDetails.update_from_json(self.course.id, jsondetails.__dict__, self.user).short_description ==\
                   jsondetails.short_description, 'After set short_description'
            jsondetails.overview = "Overview"
            assert CourseDetails.update_from_json(self.course.id, jsondetails.__dict__, self.user).overview ==\
                   jsondetails.overview, 'After set overview'
            jsondetails.intro_video = "intro_video"
            assert CourseDetails.update_from_json(self.course.id, jsondetails.__dict__, self.user).intro_video ==\
                   jsondetails.intro_video, 'After set intro_video'
            jsondetails.about_sidebar_html = "About Sidebar HTML"
            assert CourseDetails.update_from_json(self.course.id, jsondetails.__dict__, self.user)\
                .about_sidebar_html == jsondetails.about_sidebar_html, 'After set about_sidebar_html'
            jsondetails.effort = "effort"
            assert CourseDetails.update_from_json(self.course.id, jsondetails.__dict__, self.user).effort ==\
                   jsondetails.effort, 'After set effort'
            jsondetails.self_paced = True
            assert CourseDetails.update_from_json(self.course.id, jsondetails.__dict__, self.user).self_paced ==\
                   jsondetails.self_paced
            jsondetails.start_date = datetime.datetime(2010,
                                                       10,
                                                       1,
                                                       0,
                                                       tzinfo=UTC)
            assert CourseDetails.update_from_json(self.course.id, jsondetails.__dict__, self.user).start_date ==\
                   jsondetails.start_date
            jsondetails.end_date = datetime.datetime(2011,
                                                     10,
                                                     1,
                                                     0,
                                                     tzinfo=UTC)
            assert CourseDetails.update_from_json(self.course.id, jsondetails.__dict__, self.user).end_date ==\
                   jsondetails.end_date
            jsondetails.certificate_available_date = datetime.datetime(
                2010, 10, 1, 0, tzinfo=UTC)
            assert CourseDetails.update_from_json(self.course.id, jsondetails.__dict__, self.user)\
                .certificate_available_date == jsondetails.certificate_available_date
            jsondetails.course_image_name = "an_image.jpg"
            assert CourseDetails.update_from_json(self.course.id, jsondetails.__dict__, self.user).course_image_name ==\
                   jsondetails.course_image_name
            jsondetails.banner_image_name = "an_image.jpg"
            assert CourseDetails.update_from_json(self.course.id, jsondetails.__dict__, self.user).banner_image_name ==\
                   jsondetails.banner_image_name
            jsondetails.video_thumbnail_image_name = "an_image.jpg"
            assert CourseDetails.update_from_json(self.course.id, jsondetails.__dict__, self.user)\
                .video_thumbnail_image_name == jsondetails.video_thumbnail_image_name
            jsondetails.language = "hr"
            assert CourseDetails.update_from_json(self.course.id, jsondetails.__dict__, self.user).language ==\
                   jsondetails.language
            jsondetails.learning_info = ["test", "test"]
            assert CourseDetails.update_from_json(self.course.id, jsondetails.__dict__, self.user).learning_info ==\
                   jsondetails.learning_info

            jsondetails.instructor_info = {
                "instructors": [{
                    "name": "test",
                    "title": "test",
                    "organization": "test",
                    "image": "test",
                    "bio": "test"
                }]
            }
            assert CourseDetails.update_from_json(self.course.id, jsondetails.__dict__, self.user).instructor_info ==\
                   jsondetails.instructor_info
 def test_update_and_fetch(self):
     jsondetails = CourseDetails.fetch(self.course.id)
     jsondetails.syllabus = "<a href='foo'>bar</a>"
     # encode - decode to convert date fields and other data which changes form
     with self.store.branch_setting(ModuleStoreEnum.Branch.draft_preferred,
                                    self.course.id):
         self.assertEqual(
             CourseDetails.update_from_json(self.course.id,
                                            jsondetails.__dict__,
                                            self.user).syllabus,
             jsondetails.syllabus, "After set syllabus")
         jsondetails.short_description = "Short Description"
         self.assertEqual(
             CourseDetails.update_from_json(self.course.id,
                                            jsondetails.__dict__,
                                            self.user).short_description,
             jsondetails.short_description, "After set short_description")
         jsondetails.overview = "Overview"
         self.assertEqual(
             CourseDetails.update_from_json(self.course.id,
                                            jsondetails.__dict__,
                                            self.user).overview,
             jsondetails.overview, "After set overview")
         jsondetails.intro_video = "intro_video"
         self.assertEqual(
             CourseDetails.update_from_json(self.course.id,
                                            jsondetails.__dict__,
                                            self.user).intro_video,
             jsondetails.intro_video, "After set intro_video")
         jsondetails.effort = "effort"
         self.assertEqual(
             CourseDetails.update_from_json(self.course.id,
                                            jsondetails.__dict__,
                                            self.user).effort,
             jsondetails.effort, "After set effort")
         jsondetails.self_paced = True
         self.assertEqual(
             CourseDetails.update_from_json(self.course.id,
                                            jsondetails.__dict__,
                                            self.user).self_paced,
             jsondetails.self_paced)
         jsondetails.start_date = datetime.datetime(2010,
                                                    10,
                                                    1,
                                                    0,
                                                    tzinfo=UTC)
         self.assertEqual(
             CourseDetails.update_from_json(self.course.id,
                                            jsondetails.__dict__,
                                            self.user).start_date,
             jsondetails.start_date)
         jsondetails.end_date = datetime.datetime(2011,
                                                  10,
                                                  1,
                                                  0,
                                                  tzinfo=UTC)
         self.assertEqual(
             CourseDetails.update_from_json(self.course.id,
                                            jsondetails.__dict__,
                                            self.user).end_date,
             jsondetails.end_date)
         jsondetails.certificate_available_date = datetime.datetime(
             2010, 10, 1, 0, tzinfo=UTC)
         self.assertEqual(
             CourseDetails.update_from_json(
                 self.course.id, jsondetails.__dict__,
                 self.user).certificate_available_date,
             jsondetails.certificate_available_date)
         jsondetails.course_image_name = "an_image.jpg"
         self.assertEqual(
             CourseDetails.update_from_json(self.course.id,
                                            jsondetails.__dict__,
                                            self.user).course_image_name,
             jsondetails.course_image_name)
         jsondetails.banner_image_name = "an_image.jpg"
         self.assertEqual(
             CourseDetails.update_from_json(self.course.id,
                                            jsondetails.__dict__,
                                            self.user).banner_image_name,
             jsondetails.banner_image_name)
         jsondetails.video_thumbnail_image_name = "an_image.jpg"
         self.assertEqual(
             CourseDetails.update_from_json(
                 self.course.id, jsondetails.__dict__,
                 self.user).video_thumbnail_image_name,
             jsondetails.video_thumbnail_image_name)
         jsondetails.language = "hr"
         self.assertEqual(
             CourseDetails.update_from_json(self.course.id,
                                            jsondetails.__dict__,
                                            self.user).language,
             jsondetails.language)
         jsondetails.learning_info = ["test", "test"]
         self.assertEqual(
             CourseDetails.update_from_json(self.course.id,
                                            jsondetails.__dict__,
                                            self.user).learning_info,
             jsondetails.learning_info)
         jsondetails.instructor_info = {
             "instructors": [{
                 "name": "test",
                 "title": "test",
                 "organization": "test",
                 "image": "test",
                 "bio": "test"
             }]
         }
         self.assertEqual(
             CourseDetails.update_from_json(self.course.id,
                                            jsondetails.__dict__,
                                            self.user).instructor_info,
             jsondetails.instructor_info)
 def test_update_and_fetch(self):
     SelfPacedConfiguration(enabled=True).save()
     jsondetails = CourseDetails.fetch(self.course.id)
     jsondetails.syllabus = "<a href='foo'>bar</a>"
     # encode - decode to convert date fields and other data which changes form
     with self.store.branch_setting(ModuleStoreEnum.Branch.draft_preferred,
                                    self.course.id):
         self.assertEqual(
             CourseDetails.update_from_json(self.course.id,
                                            jsondetails.__dict__,
                                            self.user).syllabus,
             jsondetails.syllabus, "After set syllabus")
         jsondetails.short_description = "Short Description"
         self.assertEqual(
             CourseDetails.update_from_json(self.course.id,
                                            jsondetails.__dict__,
                                            self.user).short_description,
             jsondetails.short_description, "After set short_description")
         jsondetails.overview = "Overview"
         self.assertEqual(
             CourseDetails.update_from_json(self.course.id,
                                            jsondetails.__dict__,
                                            self.user).overview,
             jsondetails.overview, "After set overview")
         jsondetails.intro_video = "intro_video"
         self.assertEqual(
             CourseDetails.update_from_json(self.course.id,
                                            jsondetails.__dict__,
                                            self.user).intro_video,
             jsondetails.intro_video, "After set intro_video")
         jsondetails.effort = "effort"
         self.assertEqual(
             CourseDetails.update_from_json(self.course.id,
                                            jsondetails.__dict__,
                                            self.user).effort,
             jsondetails.effort, "After set effort")
         jsondetails.self_paced = True
         self.assertEqual(
             CourseDetails.update_from_json(self.course.id,
                                            jsondetails.__dict__,
                                            self.user).self_paced,
             jsondetails.self_paced)
         jsondetails.start_date = datetime.datetime(2010,
                                                    10,
                                                    1,
                                                    0,
                                                    tzinfo=UTC())
         self.assertEqual(
             CourseDetails.update_from_json(self.course.id,
                                            jsondetails.__dict__,
                                            self.user).start_date,
             jsondetails.start_date)
         jsondetails.end_date = datetime.datetime(2011,
                                                  10,
                                                  1,
                                                  0,
                                                  tzinfo=UTC())
         self.assertEqual(
             CourseDetails.update_from_json(self.course.id,
                                            jsondetails.__dict__,
                                            self.user).end_date,
             jsondetails.end_date)
         jsondetails.course_image_name = "an_image.jpg"
         self.assertEqual(
             CourseDetails.update_from_json(self.course.id,
                                            jsondetails.__dict__,
                                            self.user).course_image_name,
             jsondetails.course_image_name)
         jsondetails.language = "hr"
         self.assertEqual(
             CourseDetails.update_from_json(self.course.id,
                                            jsondetails.__dict__,
                                            self.user).language,
             jsondetails.language)
 def test_update_and_fetch(self):
     jsondetails = CourseDetails.fetch(self.course.id)
     jsondetails.syllabus = "<a href='foo'>bar</a>"
     # encode - decode to convert date fields and other data which changes form
     with self.store.branch_setting(ModuleStoreEnum.Branch.draft_preferred, self.course.id):
         self.assertEqual(
             CourseDetails.update_from_json(self.course.id, jsondetails.__dict__, self.user).syllabus,
             jsondetails.syllabus, "After set syllabus"
         )
         jsondetails.short_description = "Short Description"
         self.assertEqual(
             CourseDetails.update_from_json(self.course.id, jsondetails.__dict__, self.user).short_description,
             jsondetails.short_description, "After set short_description"
         )
         jsondetails.overview = "Overview"
         self.assertEqual(
             CourseDetails.update_from_json(self.course.id, jsondetails.__dict__, self.user).overview,
             jsondetails.overview, "After set overview"
         )
         jsondetails.intro_video = "intro_video"
         self.assertEqual(
             CourseDetails.update_from_json(self.course.id, jsondetails.__dict__, self.user).intro_video,
             jsondetails.intro_video, "After set intro_video"
         )
         jsondetails.effort = "effort"
         self.assertEqual(
             CourseDetails.update_from_json(self.course.id, jsondetails.__dict__, self.user).effort,
             jsondetails.effort, "After set effort"
         )
         jsondetails.self_paced = True
         self.assertEqual(
             CourseDetails.update_from_json(self.course.id, jsondetails.__dict__, self.user).self_paced,
             jsondetails.self_paced
         )
         jsondetails.start_date = datetime.datetime(2010, 10, 1, 0, tzinfo=UTC)
         self.assertEqual(
             CourseDetails.update_from_json(self.course.id, jsondetails.__dict__, self.user).start_date,
             jsondetails.start_date
         )
         jsondetails.end_date = datetime.datetime(2011, 10, 1, 0, tzinfo=UTC)
         self.assertEqual(
             CourseDetails.update_from_json(self.course.id, jsondetails.__dict__, self.user).end_date,
             jsondetails.end_date
         )
         jsondetails.certificate_available_date = datetime.datetime(2010, 10, 1, 0, tzinfo=UTC)
         self.assertEqual(
             CourseDetails.update_from_json(
                 self.course.id, jsondetails.__dict__, self.user
             ).certificate_available_date,
             jsondetails.certificate_available_date
         )
         jsondetails.course_image_name = "an_image.jpg"
         self.assertEqual(
             CourseDetails.update_from_json(self.course.id, jsondetails.__dict__, self.user).course_image_name,
             jsondetails.course_image_name
         )
         jsondetails.banner_image_name = "an_image.jpg"
         self.assertEqual(
             CourseDetails.update_from_json(self.course.id, jsondetails.__dict__, self.user).banner_image_name,
             jsondetails.banner_image_name
         )
         jsondetails.video_thumbnail_image_name = "an_image.jpg"
         self.assertEqual(
             CourseDetails.update_from_json(self.course.id, jsondetails.__dict__, self.user).video_thumbnail_image_name,
             jsondetails.video_thumbnail_image_name
         )
         jsondetails.language = "hr"
         self.assertEqual(
             CourseDetails.update_from_json(self.course.id, jsondetails.__dict__, self.user).language,
             jsondetails.language
         )
         jsondetails.learning_info = ["test", "test"]
         self.assertEqual(
             CourseDetails.update_from_json(self.course.id, jsondetails.__dict__, self.user).learning_info,
             jsondetails.learning_info
         )
         jsondetails.instructor_info = {
             "instructors": [
                 {
                     "name": "test",
                     "title": "test",
                     "organization": "test",
                     "image": "test",
                     "bio": "test"
                 }
             ]
         }
         self.assertEqual(
             CourseDetails.update_from_json(self.course.id, jsondetails.__dict__, self.user).instructor_info,
             jsondetails.instructor_info
         )
Exemple #12
0
    def get_student_info(self, email):
        if User.objects.filter(email=email).exists():
            student = User.objects.get(email=email)
            # List of courses user is enrolled to
            org_filter_out_set = ''
            course_org_filter = ''
            course_enrollments = list(
                get_course_enrollments(student, course_org_filter,
                                       org_filter_out_set))

            #last login data_email
            last_login_brut = str(student.last_login)
            last_login = last_login_brut.split('.')

            #Check if microsite admin
            if MicrositeAdminManager.objects.filter(user=student).exists():
                check_admin_microsite = True
                microsite_key = MicrositeAdminManager.objects.get(
                    user=student).microsite_id
                microsite_admin_org = Microsite.objects.get(
                    pk=microsite_key).key
            else:
                check_admin_microsite = False

            #Check wich course invited first
            if CourseEnrollment.objects.filter(user=student).exists():
                course_id = CourseEnrollment.objects.filter(
                    user=student).order_by('-created')[0].course_id
                user_org = str(course_id).split('+')[0].replace(
                    "course-v1:", "")
            else:
                user_org = "No organization found for user"

            #Course counters
            compteur_progress = 0
            compteur_finish = 0
            compteur_start = 0
            compteur_certified = 0

            progress_courses = []
            finish_courses = []
            start_courses = []
            certified_courses = []

            _now = int(datetime.datetime.now().strftime("%s"))

            if len(course_enrollments) > 0:
                #For each course user is enrolled to
                for dashboard_index, enrollment in enumerate(
                        course_enrollments):
                    course_id = enrollment.course_overview.id
                    user_id = student.id
                    course_tma = get_course_by_id(enrollment.course_id)
                    try:
                        course_grade_factory = CourseGradeFactory().create(
                            student, course_tma)
                        passed = course_grade_factory.passed
                        percent = course_grade_factory.percent
                    except:
                        passed = False
                        percent = 0
                    course_progression = get_overall_progress(
                        user_id, course_id)
                    try:
                        _end = int(
                            enrollment.course_overview.end.strftime("%s"))
                    except:
                        _end = 0
                    _progress = True
                    if _end > 0 and _end < _now:
                        _progress = False

                    #storing student results for this class
                    q = {}
                    q['passed'] = passed
                    q['percent'] = float(int(percent * 1000) / 10)
                    q['course_id'] = str(enrollment.course_id)
                    q['duration'] = CourseDetails.fetch(
                        enrollment.course_id).effort
                    q['required'] = course_tma.is_required_atp
                    q['content_data'] = course_tma.content_data
                    q['category'] = course_tma.categ
                    q['display_name_with_default'] = enrollment.course_overview.display_name_with_default
                    q['course_progression'] = course_progression

                    if passed == True:
                        compteur_certified += 1
                        certified_courses.append(q)
                    if course_progression > 0 and course_progression < 100 and passed == False and _progress == True:
                        compteur_progress += 1
                        progress_courses.append(q)
                    elif course_progression == 100 or passed or _progress == False:
                        compteur_finish += 1
                        finish_courses.append(q)
                    elif course_progression == 0 and _progress == True:
                        compteur_start += 1
                        start_courses.append(q)

            #Candidate status
            if student.is_staff:
                status = "Staff"
            elif check_admin_microsite:
                status = "Admin Microsite"
            else:
                status = "Student"

            context = {
                'student_id': student.id,
                'status': status,
                'student_mail': student.email,
                'student_name': student.first_name + " " + student.last_name,
                'progress_courses': compteur_progress,
                #'progress_courses': progress_courses,
                'finished_courses': compteur_finish,
                #'finish_courses': finish_courses,
                'started_courses': compteur_start,
                #'start_courses':start_courses,
                'certified_courses': compteur_certified,
                #'certified_course' : certified_courses,
                'user_org': user_org,
                'last login': last_login[0]
            }
            if check_admin_microsite:
                context['microsite_admin_org'] = microsite_admin_org

        else:
            if UserPreprofile.objects.filter(email=email).exists():
                user = UserPreprofile.objects.get(email=email)
                if CourseEnrollmentAllowed.objects.filter(
                        email=email).exists():
                    profile = CourseEnrollmentAllowed.objects.filter(
                        email=email).order_by('-created')
                    course_id = profile[0].course_id
                    user_org = str(course_id).split('+')[0].replace(
                        "course-v1:", "")
                else:
                    user_org = "No organization found for user"

                context = {
                    'student_mail': email,
                    'student_name': user.first_name + " " + user.last_name,
                    'status': "User preregistered on platform",
                    'user_org': user_org
                }
            else:
                context = {
                    'student_mail': email,
                    'status': "Unknown user",
                }

        return context
Exemple #13
0
def course_info_to_ccxcon(course_key):
    """
    Function that gathers informations about the course and
    makes a post request to a CCXCon with the data.

    Args:
        course_key (CourseLocator): the master course key
    """

    try:
        course = get_course_by_id(course_key)
    except Http404:
        log.error('Master Course with key "%s" not found', unicode(course_key))
        return
    if not course.enable_ccx:
        log.debug('ccx not enabled for course key "%s"', unicode(course_key))
        return
    if not course.ccx_connector:
        log.debug('ccx connector not defined for course key "%s"', unicode(course_key))
        return
    if not is_valid_url(course.ccx_connector):
        log.error(
            'ccx connector URL "%s" for course key "%s" is not a valid URL.',
            course.ccx_connector, unicode(course_key)
        )
        return
    # get the oauth credential for this URL
    try:
        ccxcon = CCXCon.objects.get(url=course.ccx_connector)
    except CCXCon.DoesNotExist:
        log.error('ccx connector Oauth credentials not configured for URL "%s".', course.ccx_connector)
        return

    # get an oauth client with a valid token

    oauth_ccxcon = get_oauth_client(
        server_token_url=urlparse.urljoin(course.ccx_connector, CCXCON_TOKEN_URL),
        client_id=ccxcon.oauth_client_id,
        client_secret=ccxcon.oauth_client_secret
    )

    # get the entire list of instructors
    course_instructors = CourseInstructorRole(course.id).users_with_role()
    # get anonymous ids for each of them
    course_instructors_ids = [anonymous_id_for_user(user, course_key) for user in course_instructors]
    # extract the course details
    course_details = CourseDetails.fetch(course_key)

    payload = {
        'course_id': unicode(course_key),
        'title': course.display_name,
        'author_name': None,
        'overview': course_details.overview,
        'description': course_details.short_description,
        'image_url': course_details.course_image_asset_path,
        'instructors': course_instructors_ids
    }
    headers = {'content-type': 'application/json'}

    # make the POST request
    add_course_url = urlparse.urljoin(course.ccx_connector, CCXCON_COURSEXS_URL)
    resp = oauth_ccxcon.post(
        url=add_course_url,
        json=payload,
        headers=headers,
        timeout=CCXCON_REQUEST_TIMEOUT
    )

    if resp.status_code >= 500:
        raise CCXConnServerError('Server returned error Status: %s, Content: %s', resp.status_code, resp.content)
    if resp.status_code >= 400:
        log.error("Error creating course on ccxcon. Status: %s, Content: %s", resp.status_code, resp.content)
    # this API performs a POST request both for POST and PATCH, but the POST returns 201 and the PATCH returns 200
    elif resp.status_code != HTTP_200_OK and resp.status_code != HTTP_201_CREATED:
        log.error('Server returned unexpected status code %s', resp.status_code)
    else:
        log.debug('Request successful. Status: %s, Content: %s', resp.status_code, resp.content)
Exemple #14
0
    def get_student_info(self, student):
        # List of courses user is enrolled to
        org_filter_out_set = ''
        course_org_filter = ''
        course_enrollments = list(
            get_course_enrollments(student, course_org_filter,
                                   org_filter_out_set))

        #last login data_email
        last_login_brut = str(student.last_login)
        last_login = last_login_brut.split('.')

        #Check if user is staff / microsite admin / student
        check_admin_microsite = False
        try:
            microsite_key = MicrositeAdminManager.objects.get(
                user=student).microsite_id
            user_org = microsite = Microsite.objects.get(pk=microsite_key).key
            check_admin_microsite = True
        except:
            user_org = "Not microsite admin"
            pass

        compteur_progress = 0
        compteur_finish = 0
        compteur_start = 0
        compteur_certified = 0

        progress_courses = []
        finish_courses = []
        start_courses = []
        certified_courses = []

        _now = int(datetime.datetime.now().strftime("%s"))

        if len(course_enrollments) > 0:
            #For each course user is enrolled to
            for dashboard_index, enrollment in enumerate(course_enrollments):
                course_id = enrollment.course_overview.id
                user_id = student.id
                course_tma = get_course_by_id(enrollment.course_id)
                try:
                    course_grade_factory = CourseGradeFactory().create(
                        student, course_tma)
                    passed = course_grade_factory.passed
                    percent = course_grade_factory.percent
                except:
                    passed = False
                    percent = 0
                course_progression = get_overall_progress(user_id, course_id)
                try:
                    _end = int(enrollment.course_overview.end.strftime("%s"))
                except:
                    _end = 0
                _progress = True
                if _end > 0 and _end < _now:
                    _progress = False

                #storing student results for this class
                q = {}
                q['passed'] = passed
                q['percent'] = float(int(percent * 1000) / 10)
                q['course_id'] = str(enrollment.course_id)
                q['duration'] = CourseDetails.fetch(
                    enrollment.course_id).effort
                q['required'] = course_tma.is_required_atp
                q['content_data'] = course_tma.content_data
                q['category'] = course_tma.categ
                q['display_name_with_default'] = enrollment.course_overview.display_name_with_default
                q['course_progression'] = course_progression

                if passed == True:
                    compteur_certified += 1
                    certified_courses.append(q)
                if course_progression > 0 and course_progression < 100 and passed == False and _progress == True:
                    compteur_progress += 1
                    progress_courses.append(q)
                elif course_progression == 100 or passed or _progress == False:
                    compteur_finish += 1
                    finish_courses.append(q)
                elif course_progression == 0 and _progress == True:
                    compteur_start += 1
                    start_courses.append(q)

        if student.is_staff:
            status = "Staff"
        elif check_admin_microsite:
            status = "Admin Microsite"
        else:
            status = "Student"

        context = {
            'student_id': student.id,
            'status': status,
            'student_mail': student.email,
            'student_name': student.first_name + " " + student.last_name,
            'progress_courses': compteur_progress,
            #'progress_courses': progress_courses,
            'finished_courses': compteur_finish,
            #'finish_courses': finish_courses,
            'started_courses': compteur_start,
            #'start_courses':start_courses,
            'certified_courses': compteur_certified,
            #'certified_course' : certified_courses,
            'user org': user_org,
            'last login': last_login[0]
        }

        return context