Exemplo n.º 1
0
 def test_must_have_person_type(self):
     lecture = Lecture(zosia=self.zosia,
                       title="foo",
                       duration="5",
                       lecture_type="1",
                       abstract="0",
                       author=self.user)
     with self.assertRaises(ValidationError):
         lecture.full_clean()
Exemplo n.º 2
0
    def test_lecture_is_invalid_without_lecture_type(self):
        lecture = Lecture(zosia=self.zosia,
                          title="foo",
                          abstract="foo",
                          duration=10,
                          author=self.user)

        with self.assertRaises(ValidationError):
            lecture.full_clean()
Exemplo n.º 3
0
    def test_lecture_is_invalid_without_author(self):
        lecture = Lecture(zosia=self.zosia,
                          title="foo",
                          abstract="foo",
                          duration=10,
                          lecture_type=LectureInternals.TYPE_LECTURE)

        with self.assertRaises(ValidationError):
            lecture.full_clean()
Exemplo n.º 4
0
    def test_workshop_is_invalid_with_duration_less_than_30(self):
        lecture = Lecture(zosia=self.zosia,
                          title="foo",
                          abstract="bar",
                          duration=15,
                          lecture_type=LectureInternals.TYPE_WORKSHOP,
                          person_type=LectureInternals.PERSON_NORMAL,
                          author=self.user)

        with self.assertRaises(ValidationError):
            lecture.full_clean()
Exemplo n.º 5
0
    def test_lecture_is_invalid_without_duration(self):
        lecture = Lecture(
            zosia=self.zosia,
            title="foo",
            abstract="foo",
            lecture_type=LectureInternals.TYPE_LECTURE,
            person_type=LectureInternals.PERSON_NORMAL,
            author=self.user
        )

        with self.assertRaises(ValidationError):
            lecture.full_clean()
Exemplo n.º 6
0
    def test_lecture_is_invalid_for_guest_person_with_duration_more_than_60(
            self):
        lecture = Lecture(zosia=self.zosia,
                          title="foo",
                          abstract="bar",
                          duration=90,
                          lecture_type=LectureInternals.TYPE_LECTURE,
                          person_type=LectureInternals.PERSON_GUEST,
                          author=self.user)

        with self.assertRaises(ValidationError):
            lecture.full_clean()
Exemplo n.º 7
0
    def test_patch_rud(self):
        self.authorize_client_lecture()
        url = reverse('groups:group-rud', args=[Group.objects.get().pk])
        lectures = User.objects.filter(is_lecture=True)
        group = Group.objects.get()
        group.course = 'python2'
        group.lectures_list.append(Lecture(lecture=lectures[1]))
        data = {'group': GroupSerializer(group).data}

        response = self.client.patch(url, data, format='json')

        self.assertEqual(response.status_code, status.HTTP_200_OK)
        self.assertEqual(LectureGroups.objects.count(), 2)
        self.assertEqual(Group.objects.all()[0].course, 'python2')
Exemplo n.º 8
0
    def test_create(self):
        lecture = Lecture(zosia=self.zosia,
                          title="foo",
                          abstract="bar",
                          duration="5",
                          lecture_type="1",
                          person_type="0",
                          author=self.user)

        count = Lecture.objects.count()
        try:
            lecture.full_clean()
        except ValidationError:
            self.fail("Full clean fail!")
        lecture.save()
        self.assertEqual(count + 1, Lecture.objects.count())
Exemplo n.º 9
0
    def setUp(self):
        lecture = User(email='*****@*****.**', first_name='John', last_name='Snow', is_student=False, is_lecture=True)
        lecture2 = User(email='*****@*****.**', first_name='Harry', last_name='Potter', is_student=False, is_lecture=True)
        lecture.set_password("randPassword")
        lecture.save()
        lecture2.save()
        student = User(email='*****@*****.**', first_name='Frodo', last_name='Baggins')
        student2 = User(email='*****@*****.**', first_name='Titus', last_name='Flavius')
        student3 = User(email='*****@*****.**', first_name='Philip', last_name='Capet')
        student.save()
        student2.save()
        student3.save()

        group = Group(course='python', lectures_list=[Lecture(lecture=lecture)],
                      enrolled_list=[Enrolled(student=student,
                                              marks_list=[Mark(value=5, max_points=10, for_what="exercise", note=""),
                                                          Mark(value=2, max_points=10, for_what="quiz", note="")]),
                                     Enrolled(student=student2,
                                              marks_list=[Mark(value=7, max_points=10, for_what="exercise", note=""),
                                                          Mark(value=10, max_points=10, for_what="quiz", note="")]
                                              )])
        group.save()
Exemplo n.º 10
0
    def test_workshop_is_valid_with_maximal_duration(self):
        lecture = Lecture(zosia=self.zosia,
                          title="foo",
                          abstract="bar",
                          duration=120,
                          lecture_type=LectureInternals.TYPE_WORKSHOP,
                          person_type=LectureInternals.PERSON_GUEST,
                          author=self.user)

        count = Lecture.objects.count()

        try:
            lecture.full_clean()
        except ValidationError as e:
            self.fail("Full clean failed! {}".format(e.message_dict))

        lecture.save()
        self.assertEqual(count + 1, Lecture.objects.count())
Exemplo n.º 11
0
    def test_lecture_is_valid_for_normal_person(self):
        lecture = Lecture(zosia=self.zosia,
                          title="foo",
                          abstract="bar",
                          duration=60,
                          lecture_type=LectureInternals.TYPE_LECTURE,
                          person_type=LectureInternals.PERSON_NORMAL,
                          author=self.user)

        count = Lecture.objects.count()

        try:
            lecture.full_clean()
        except ValidationError as e:
            self.fail("Full clean failed! {}".format(e.message_dict))

        lecture.save()
        self.assertEqual(count + 1, Lecture.objects.count())
Exemplo n.º 12
0
    def post(self, request, *args, **kwargs):
        message_type = 'Share Lecture'
        context_dict = {'message_type': message_type}
        print(request.POST)
        school_id = request.POST.get('school_id')
        print('school_id = %s' % school_id)
        school = School.objects.get(id=school_id)
        print('school = %s' % school)
        teacher_email = request.POST.get('teacher')
        teacher = Teacher.objects.get(email=teacher_email)
        print('teacher = %s' % teacher)
        print('school = %s' % school)
        standard = request.POST.get('the_class')
        the_class = Class.objects.get(school=school, standard=standard)
        print('the_class = %s' % the_class)

        sec = request.POST.get('section')
        print('sec = %s' % sec)
        if sec != '':
            section = sec.split(',')
            # section = Section.objects.get(school=school, section=sec)
            print('section = %s' % section)
        all_sections = request.POST.get('all_sections')
        print(all_sections)

        sub = request.POST.get('subject')
        subject = Subject.objects.get(school=school, subject_name=sub)
        print('subject = %s' % subject)
        youtube_link = request.POST.get('youtube_link')
        print('youtube_link = %s' % youtube_link)
        if youtube_link == '':
            youtube_link = 'N/A'
        lesson_topic = request.POST.get('lesson_topic')
        print('lesson_topic = %s' % lesson_topic)
        try:
            lecture = Lecture(teacher=teacher,
                              the_class=the_class,
                              subject=subject,
                              topic=lesson_topic,
                              youtube_link=youtube_link)
            lecture.save()
        except Exception as e:
            print('exception 29032020-A from lecture views.py %s %s' %
                  (e.message, type(e)))
            print('failed in creating lecture record')

        file_included = request.POST.get('file_included')
        print('file_included = %s' % file_included)

        if file_included == 'true' or file_included == 'yes':
            include_link = True
            doc_file = request.FILES['file']
            print(type(doc_file))
            print('doc_file = %s' % doc_file)
            print(doc_file)

            # 05/04/2020 - a lot of stupid teachers use characters like (, ), & in file name which causes issues
            file_name3 = request.POST.get('file_name').replace(' ', '_')
            file_name2 = file_name3.replace('&', '_')
            file_name1 = file_name2.replace('(', '_')
            file_name = file_name1.replace(')', '_')
            # long_link = 'https://storage.cloud.google.com/classup/classup2/media/prod/image_video/%s' % \
            #             image_name.replace('@', '')
            long_link = 'https://classup2.s3.us-east-2.amazonaws.com/media/prod/image_video/%s' % \
                        file_name.replace('@', '')
            print('long_link = %s' % long_link)
            short_link = long_link

            # prepare short link
            global_conf = GlobalConf.objects.get(pk=1)
            key = global_conf.short_link_api
            url = 'https://cutt.ly/api/api.php?'
            url += 'key=%s&short=%s' % (key, long_link)
            print('url for generating short link = %s' % url)
            try:
                req = urllib2.Request(url,
                                      headers={'User-Agent': "Magic Browser"})
                response = urllib2.urlopen(req)
                print('response for generating short link = %s' % response)
                outcome = json.loads(response.read())
                print('ouctome = ')
                print(outcome)
                status = outcome['url']['status']
                print('status = %i' % status)
                if status == 7:
                    short_link = outcome['url']['shortLink']
                    print('short_lint = %s' % short_link)
            except Exception as e:
                print('exception 14122019-B-A from lecture views.py %s %s' %
                      (e.message, type(e)))
                print(
                    'failed to generate short link  for the lesson doc uploaded by %s'
                    % teacher)

            try:
                print('doc_file = ')
                print(doc_file)
                lecture.pdf_link = short_link
                lecture.doc_file = doc_file
                lecture.save()
            except Exception as e:
                print('exception 29032020-B from lecture views.py %s %s' %
                      (e.message, type(e)))
                print('error in saving document pdf')

        if all_sections == 'true' or all_sections == 'yes':
            print('this lecture to be shared with all sections of class %s' %
                  the_class)
            students = Student.objects.filter(current_class=the_class,
                                              active_status=True)
        else:
            print('this lecture to be shared with class %s-%s' %
                  (the_class, section))
            sections = reduce(lambda x, y: x | y, [
                Q(current_section=Section.objects.get(school=school,
                                                      section=a_section))
                for a_section in section
            ])
            print(sections)
            try:
                students = Student.objects.filter(sections,
                                                  current_class=the_class,
                                                  active_status=True)
                print(students)
            except Exception as e:
                print('exception 07042020-A from lecture views.py %s %s' %
                      (e.message, type(e)))

        for student in students:
            message = 'Dear %s, class %s %s %s lecture shared. Link:  %s ' % \
                      (student, standard, sub, lesson_topic, youtube_link)
            if file_included == 'true' or file_included == 'yes':
                message += '  Assignment link: %s' % short_link
            print(message)
            p = student.parent
            m1 = p.parent_mobile1
            sms.send_sms1(school, teacher_email, m1, message, message_type)
        return JSONResponse(context_dict, status=200)