Example #1
0
    def test_create_course_form(self):
        s = Student(
            username='******',
            first_name='Testvorname4',
            last_name='Testnachname4',
            email='*****@*****.**'
        )
        s.save()
        l = Lecturer(
            username='******',
            first_name='Testvorname3',
            last_name='Testnachname3',
            email='*****@*****.**'
        )
        l.save()

        course_form = {
            'lecturer': l.id,
            'start_date': '2021-06-09',
            'end_date': '2023-06-09',
            'student': [s.id],
            'name': 'TestCourse'
        }
        course = CourseForm(course_form)
        self.assertTrue(course.is_valid())
        course.save()
Example #2
0
 def test_public_teacher_dashboard_empty(self):
     user = User(username="******")
     user.save()
     student = Student(user=user)
     student.save()
     result = public_teacher_threads_student(student)
     expected = set()
     self.assertEquals(expected, result)
Example #3
0
class TestDeleteMessage(TestCase):
    def setUp(self):
        self.first_user = User(username="******")
        self.first_user.set_password('12345')
        self.first_user.save()
        self.second_user = User(username="******")
        self.second_user.set_password('12345')
        self.second_user.save()
        self.third_user = User(username="******")
        self.third_user.save()
        self.first_student = Student(user=self.first_user)
        self.first_student.save()
        self.second_student = Student(user=self.second_user)
        self.second_student.save()
        self.teacher = Professor(user=self.third_user)
        self.teacher.save()
        self.stage = Stage(id=1, name="Stage1", level=1)
        self.stage.save()
        self.lesson = Lesson(id=1, name="Lesson 1", stage_id=1)
        self.lesson.save()
        self.thread_lesson = Thread.objects.create(author=self.first_user,
                                                   lesson=self.lesson,
                                                   title="Thread 1",
                                                   id=1)
        self.thread_lesson.save()
        self.thread_id = self.thread_lesson.id
        self.message = Message.objects.create(
            author=self.first_user,
            content="Content of message",
            thread=self.thread_lesson,
            created_date=utc.localize(datetime.now()),
            modified_date=utc.localize(datetime.now()))
        self.message.save()
        self.c = Client()
        self.c.login(username='******', password='******')
        self.c2 = Client()
        self.c2.login(username='******', password='******')

    def test_delete_unknown_thread(self):
        response = self.c.post('/forum/thread/{}/delete/{}'.format(402552, 1))
        self.assertEquals(response.status_code, 404)

    def test_delete_unknown_message(self):
        response = self.c.post('/forum/thread/{}/delete/{}'.format(
            self.thread_lesson.id, 1138282))
        self.assertEquals(response.status_code, 404)

    def test_delete_message(self):
        response = self.c.post('/forum/thread/{}/delete/{}'.format(
            self.thread_lesson.id, self.message.id))

        self.assertEquals(response.status_code, 302)
        self.assertFalse(Message.objects.filter(pk=self.message.id).exists())

    def test_edit_message_unauthorized(self):
        response = self.c2.post('/forum/thread/{}/delete/{}'.format(
            self.thread_lesson.id, self.message.id))
        self.assertEquals(response.status_code, 403)
Example #4
0
    def setUp(self):
        self.user = User(username="******")
        self.user.save()
        self.second_user = User(username="******")
        self.second_user.save()
        self.teacher_user = User(username="******")
        self.teacher_user.save()
        self.second_teacher_user = User(username="******")
        self.second_teacher_user.save()

        self.student = Student(user=self.user)
        self.student.save()
        self.second_student = Student(user=self.second_user)
        self.second_student.save()
        self.teacher = Professor(user=self.teacher_user)
        self.teacher.save()
        self.second_teacher = Professor(user=self.second_teacher_user)
        self.second_teacher.save()

        self.stage = Stage(id=1, name="Stage1", level=1)
        self.stage.save()
        self.second_stage = Stage(id=2, name="Stage2", level=1)
        self.second_stage.save()

        self.lesson = Lesson(id=1, name="English", stage_id=1)
        self.lesson.save()
        self.lesson.students.add(self.student)
        self.lesson.students.add(self.second_student)
        self.lesson.professors.add(self.teacher)
        self.lesson.save()

        self.second_lesson = Lesson(id=2, name="French", stage_id=2)
        self.second_lesson.save()
        self.second_lesson.students.add(self.second_student)
        self.second_lesson.professors.add(self.teacher)
        self.second_lesson.save()

        self.thread = Thread(title="Help",
                             author=self.user,
                             recipient=self.teacher_user)
        self.thread.save()

        self.second_thread = Thread(title="Send help",
                                    author=self.second_user,
                                    lesson=self.second_lesson)
        self.second_thread.save()

        self.third_thread = Thread(title="Information regarding w/e",
                                   author=self.teacher_user,
                                   professor=self.teacher)
        self.third_thread.save()

        self.fourth_thread = Thread(title="Information regarding spam",
                                    author=self.teacher_user,
                                    professor=self.teacher)
        self.fourth_thread.save()
Example #5
0
    def test_create_and_delete_course_view(self):
        self.client.force_login(self.my_admin)
        s = Student(
            username='******',
            first_name='Testvorname4',
            last_name='Testnachname4',
            email='*****@*****.**'
        )
        s.save()
        l = Lecturer(
            username='******',
            first_name='Testvorname3',
            last_name='Testnachname3',
            email='*****@*****.**'
        )
        l.save()

        course_form = {
            'lecturer': l.id,
            'start_date': '2021-06-09',
            'end_date': '2023-06-09',
            'student': [s.id],
            'name': 'TestCourse'
        }

        course_form2 = {
            'lecturer': l.id,
            'start_date': '2021-06-09',
            'end_date': '2023-06-09',
            'student': [s.id],
            'name': 'ChangedCourse'
        }

        response = self.client.post(
            reverse('create_course'), course_form)
        self.assertEqual(response.status_code, HTTPStatus.OK)

        query_set = Course.objects.all()
        self.assertTrue(Course.objects.filter(name='TestCourse').exists())
        my_id = Course.objects.get(name='TestCourse').id

        response = self.client.post(
            reverse('edit_course', kwargs={'id': my_id}), course_form2)
        self.assertEqual(response.status_code, HTTPStatus.OK)
        self.assertTrue(Course.objects.filter(name='ChangedCourse').exists())

        response = self.client.post(
            reverse('detailed_course', args=(my_id,)))
        self.assertEqual(response.status_code, HTTPStatus.OK)

        response = self.client.post(
            reverse('delte_course', args=(my_id,)))
        self.assertEqual(response.status_code, HTTPStatus.OK)

        query_set = Course.objects.all()
        self.assertFalse(Course.objects.filter(name='TestCourse').exists())
Example #6
0
    def setUp(self):
        self.user = User(username="******")
        self.user.set_password('12345')
        self.user.save()
        self.teacher_user = User(username="******")
        self.teacher_user.set_password('12345')
        self.teacher_user.save()

        self.student = Student(user=self.user)
        self.student.save()
        self.teacher = Professor(user=self.teacher_user)
        self.teacher.save()

        res1_content = {"title": "Res1"}
        self.res1 = Resource(added_by=self.teacher_user, content=res1_content)
        self.res1.save()

        self.section = Section(id=1, name="Section1")
        self.section.save()
        self.section.resource.add(self.res1)
        self.section.save()

        self.skill2 = Skill(id=2, name="Skill2", code="2")
        self.skill2.save()

        res2_content = {"title": "Res2"}
        self.res2 = Resource(added_by=self.teacher_user, content=res2_content)
        self.res2.save()

        self.skill3 = Skill(id=3, name="Skill3", code="3")
        self.skill3.save()
        self.skill3.resource.add(self.res2)
        self.skill3.save()

        self.skill4 = Skill(id=4, name="Skill4", code="4")
        self.skill4.section = self.section
        self.skill4.save()

        self.stage = Stage(id=1, name="Stage1", level=1)
        self.stage.save()
        self.stage.skills.add(self.skill3)
        self.stage.skills.add(self.skill4)
        self.stage.save()

        self.lesson = Lesson(id=1, name="English", stage_id=1)
        self.lesson.save()
        self.lesson.students.add(self.student)
        self.lesson.professors.add(self.teacher)
        self.lesson.save()

        self.s1 = Client()
        self.s1.login(username=self.user.username, password='******')

        self.t1 = Client()
        self.t1.login(username=self.teacher_user.username, password='******')
Example #7
0
def start(message):
    classroom_slug = message.text[12:] if message.text[7:] else None
    if classroom_slug:
        teacher = Teacher.get(message.chat.id)
        if teacher:
            ru_text = "Вы учитель и не можете добавляться в классы как ученик"
            en_text = "You are a teacher and can't be added to classrooms as a student"
            text = ru_text if teacher.language_code == 'ru' else en_text

            bot.send_message(message.chat.id, text)
            bot.send_message(
                message.chat.id,
                "Классные комнаты",
                reply_markup=get_classroom_list_inline_markup(teacher))
        else:
            student = Student.get(message.chat.id) or \
                      Student(message.chat.id, language_code='en', registered_utc=datetime.now(timezone.utc)).save()
            classroom = Classroom.get_by_slug(classroom_slug)
            teacher = Teacher.get(classroom.teacher_id)
            if not student.check_classroom_student(classroom.id):
                ClassroomStudent(classroom.id,
                                 student.id,
                                 joined_utc=datetime.now(timezone.utc)).save()
            if not student.fullname:
                student_fullname_request(message)
            else:
                ru_text = f"Вы добавлены в классную комнату *{classroom.name}*. Учитель: _{teacher.fullname}_"
                en_text = f"You have been added to the classroom *{classroom.name}*. Teacher: _{teacher.fullname}_"
                text = ru_text if student.language_code == 'ru' else en_text

                bot.send_message(message.chat.id, text, parse_mode='Markdown')
                bot.send_message(
                    message.chat.id,
                    'Классные комнаты',
                    reply_markup=get_classroom_list_inline_markup(student))
    else:
        user = Student.get(message.chat.id) or Teacher.get(message.chat.id)
        if user:
            ru_text = "Вы уже зарегистрированы"
            en_text = "You are already registered"
            text = ru_text if user.language_code == 'ru' else en_text

            bot.send_message(message.chat.id, text)
            classroom_list_view(user)
        else:
            # teacher = Teacher(message.chat.id, language_code=message.from_user.language_code)
            Teacher(message.chat.id,
                    language_code='en',
                    registered_utc=datetime.now(timezone.utc)).save()
            teacher_fullname_request(message)
Example #8
0
def handle_classroom_assessments_query(call):
    bot.clear_step_handler_by_chat_id(call.message.chat.id)
    data = get_call_data(call)
    student = Student.get(call.message.chat.id)
    classroom = Classroom.get(data['classroom_id'])
    classroom_assessments_view(student, classroom)
    classroom_detail_view(student, classroom)
Example #9
0
def submission_message_list_view(user, submission, task):
    student = Student.get(submission.student_id)

    text = f"Выполненное задание: *{task.name}*. Ученик: _{student.fullname}_" if \
        user.language_code == 'ru' else f"Submission: *{task.name}*. Student: _{student.fullname}_"
    bot.send_message(user.id, text, parse_mode='Markdown')

    ru_text = "Нажмите, чтобы исправить ошибки 👇🏻"
    en_text = "Tap to review 👇🏻"
    text = ru_text if user.language_code == 'ru' else en_text

    for submission_message in submission.messages:
        message = bot.forward_message(user.id, submission_message.student_id,
                                      submission_message.message_id)
        if type(user) is Teacher and message.photo:
            bot.delete_message(message.chat.id, message.message_id)
            message_with_button = bot.send_photo(
                user.id,
                message.photo[-1].file_id,
            )
            bot.send_message(user.id,
                             text,
                             reply_markup=get_drawer_markup(
                                 message.photo[-1].file_id, user,
                                 message_with_button.message_id,
                                 submission.id))
Example #10
0
def handle_task_messages_query(call):
    bot.clear_step_handler_by_chat_id(call.message.chat.id)
    data = get_call_data(call)
    user = Teacher.get(call.message.chat.id) or Student.get(
        call.message.chat.id)
    task = Task.get(data['task_id'])
    task_message_list_view(user, task)
    task_detail_view(user, task)
Example #11
0
def student_fullname_request(message):
    student = Student.get(message.chat.id)

    ru_text = "Введите свою фамилию и имя. Их будут видеть ваши учителя."
    en_text = "Send your full name. Your teachers will see it."
    text = ru_text if student.language_code == 'ru' else en_text

    bot.send_message(message.chat.id, text)
    bot.register_next_step_handler(message, student_fullname_receive)
Example #12
0
def handle_submission_message_list_query(call):
    bot.clear_step_handler_by_chat_id(call.message.chat.id)
    data = get_call_data(call)
    user = Teacher.get(call.message.chat.id) or Student.get(
        call.message.chat.id)
    submission = Submission.get(data['submission_id'])
    task = Task.get(submission.task_id)
    submission_message_list_view(user, submission, task)
    task_detail_view(user, task)
Example #13
0
def handle_submission_review_query(call):
    bot.clear_step_handler_by_chat_id(call.message.chat.id)
    data = get_call_data(call)

    user = Teacher.get(call.message.chat.id) or Student.get(
        call.message.chat.id)
    submission = Submission.get(data['submission_id'])
    task = Task.get(submission.task_id)

    submission_message_list_view(user, submission, task)
    review_submission_scenario.submission_comment_request(
        call.message, data['submission_id'])
Example #14
0
def classroom_student_list_view(teacher, classroom):
    students = Student.get_classroom_students(classroom.id)
    if len(students) == 0:
        ru_text = "В этой классной комнате пока что нет ни одного ученика"
        en_text = "There are no students in this classroom yet"
        text = ru_text if teacher.language_code == 'ru' else en_text
    else:
        text = f"*{classroom.name}*\n\n"
        for student in students:
            text += f"{student.fullname}\n"

    bot.send_message(teacher.id, text, parse_mode='Markdown')
Example #15
0
def new_task_notification(task):
    classroom = Classroom.get(task.classroom_id)
    teacher = Teacher.get(classroom.teacher_id)
    students = Student.get_classroom_students(classroom.id)

    ru_text = f"🔔 Новое задание: *{task.name}*\n\n*{classroom.name}*. Учитель: _{teacher.fullname}_"
    en_text = f"🔔 New task: *{task.name}*\n\n*{classroom.name}*. Teacher: _{teacher.fullname}_"

    for student in students:
        text = ru_text if student.language_code == 'ru' else en_text
        bot.send_message(student.id, text, parse_mode='MarkDown')
        task_detail_view(student, task)
Example #16
0
 def setUp(self):
     self.first_user = User(username="******")
     self.first_user.set_password('12345')
     self.first_user.save()
     self.second_user = User(username="******")
     self.second_user.set_password('12345')
     self.second_user.save()
     self.third_user = User(username="******")
     self.third_user.save()
     self.first_student = Student(user=self.first_user)
     self.first_student.save()
     self.second_student = Student(user=self.second_user)
     self.second_student.save()
     self.teacher = Professor(user=self.third_user)
     self.teacher.save()
     self.stage = Stage(id=1, name="Stage1", level=1)
     self.stage.save()
     self.lesson = Lesson(id=1, name="Lesson 1", stage_id=1)
     self.lesson.save()
     self.thread_lesson = Thread.objects.create(author=self.first_user,
                                                lesson=self.lesson,
                                                title="Thread 1",
                                                id=1)
     self.thread_lesson.save()
     self.thread_id = self.thread_lesson.id
     self.message = Message.objects.create(
         author=self.first_user,
         content="Content of message",
         thread=self.thread_lesson,
         created_date=utc.localize(datetime.now()),
         modified_date=utc.localize(datetime.now()))
     self.message.save()
     self.c = Client()
     self.c.login(username='******', password='******')
     self.c2 = Client()
     self.c2.login(username='******', password='******')
     self.file = SimpleUploadedFile('file.txt', b'OOOOOOOOOOOOOOOOOOOO')
     self.attachment = MessageAttachment.objects.create(
         name=self.file.name, file=self.file, message=self.message)
     self.attachment.save()
Example #17
0
def new_submission_review_result_notification(submission):
    task = Task.get(submission.task_id)
    classroom = Classroom.get(task.classroom_id)
    student = Student.get(submission.student_id)
    teacher = Teacher.get(classroom.teacher_id)

    ru_text = f"🔔 Ваше задание проверено\n\n*{classroom.name}*\n_{teacher.fullname}_"
    en_text = f"🔔 New submission review\n\n*{classroom.name}*\n_{teacher.fullname}_"
    text = ru_text if student.language_code == 'ru' else en_text

    bot.send_message(student.id, text, parse_mode='MarkDown')
    submission_review_result_view(student, submission, task)
    task_detail_view(student, task)
Example #18
0
def create_student():
    user = create_appuser()

    courses = Course.objects.all()
    course_list = [course for course in courses]

    faculties = Faculty.objects.all()
    faculty_list = [faculty for faculty in faculties]

    student = Student(
        app_user=user,
        number=random.randrange(1, 10000000000),
        call=random.choice([1, 2]),
        entry_grade=random.randrange(0, 201),
        statute=random.choice([
            "worker", "athlete", "fireman", "military", "union", "special",
            "parent"
        ]),
        faculty=random.choice(faculty_list),
    )

    student.save()
    student.course.add(random.choice(course_list))
Example #19
0
 def setUp(self):
     self.user1 = User(username='******')
     self.user1.set_password('12345')
     self.user1.save()
     self.teacher = Professor(user=self.user1)
     self.teacher.save()
     self.user2 = User(username="******")
     self.user2.save()
     self.student = Student(user=self.user2)
     self.student.save()
     self.stage = Stage(id=1, name="Stage1", level=1)
     self.stage.save()
     self.lesson = Lesson(id=1, name="Lesson 1", stage_id=1)
     self.lesson.save()
     self.skill1 = Skill(code=422230,
                         name="Compter deux par deux",
                         description="")
     self.skill1.save()
     self.skill2 = Skill(code=422231,
                         name="Lacer ses chaussures",
                         description="")
     self.skill2.save()
     self.c = Client()
     self.c.login(username='******', password='******')
Example #20
0
def student_fullname_receive(message):
    student = Student.get(message.chat.id)

    student.fullname = message.text
    student.save()

    classroom = student.get_classrooms()[-1]
    teacher = Teacher.get(classroom.teacher_id)

    ru_text = f"Вы добавлены в классную комнату *{classroom.name}*. Учитель: _{teacher.fullname}_"
    en_text = f"You have been added to the classroom *{classroom.name}*. Teacher: _{teacher.fullname}_"
    text = ru_text if student.language_code == 'ru' else en_text

    bot.send_message(message.chat.id, text, parse_mode='Markdown')

    classroom_list_view(student)
Example #21
0
def get_submissions_for_review_inline_markup(teacher, task):
    inline_markup = types.InlineKeyboardMarkup(row_width=1)

    for submission in task.submissions_for_review:
        student = Student.get(submission.student_id)
        inline_markup.add(
            types.InlineKeyboardButton(
                text=f"{student.fullname} ({submission.created_utc.strftime('%d.%m.%Y')})",
                callback_data='@@SUBMISSION_REVIEW/{"submission_id": ' + str(submission.id) + '}'
            )
        )

    inline_markup.add(
        types.InlineKeyboardButton(
            text="🔙 Назад" if teacher.language_code == 'ru' else '🔙 Back',
            callback_data='@@TASK/{"task_id": ' + str(task.id) + '}'
        )
    )

    return inline_markup
Example #22
0
def handle_new_submission_query(call):
    bot.clear_step_handler_by_chat_id(call.message.chat.id)
    data = get_call_data(call)

    student = Student.get(call.message.chat.id)
    submission = Submission(data['task_id'],
                            student.id,
                            status=SubmissionStatus.DRAFT.value,
                            created_utc=datetime.now(timezone.utc)).save()

    ru_text = "Отправьте мне выполненное задание в любом формате: " \
              "текст, фото, видео, файлы или аудиосообщения; одним или несколькими сообщениями."
    en_text = "Send me the submission in any format: " \
              "text, photo, video, files or audio messages; one or more messages."
    text = ru_text if student.language_code == 'ru' else en_text

    bot.send_message(call.message.chat.id, text, parse_mode='Markdown')

    bot.register_next_step_handler(
        call.message, create_submission_scenario.compose_submission,
        submission)
def compose_submission(message, submission):
    student = Student.get(message.chat.id)

    if message.text in ['Отправить на проверку', 'Submit for review']:
        submission.status = SubmissionStatus.REVIEW.value
        submission.save()

        ru_text = "Ваше задание отправлено, ждите результата"
        en_text = "Your submission is sent, wait for the review result"
        text = ru_text if student.language_code == 'ru' else en_text

        bot.send_message(message.chat.id, text, reply_markup=remove_markup())

        task = Task.get(submission.task_id)
        task_detail_view(student, task)
    elif message.text in ['❌ Отмена', '❌ Cancel']:
        ru_text = "Отмена"
        en_text = "Cancel"
        text = ru_text if student.language_code == 'ru' else en_text

        bot.send_message(message.chat.id, text, reply_markup=remove_markup())

        task = Task.get(submission.task_id)
        task_detail_view(student, task)
        submission.delete()
    else:
        submission.add(message)

        ru_text = "Отправьте ещё что-то или нажмите *Отправить на проверку*"
        en_text = "Send something else or tap *Submit for review*"
        text = ru_text if student.language_code == 'ru' else en_text

        bot.send_message(
            message.chat.id,
            text,
            reply_markup=markups.get_compose_submission_markup(student),
            parse_mode='Markdown',
        )

        bot.register_next_step_handler(message, compose_submission, submission)
Example #24
0
def handle_classroom_query(call):
    data = get_call_data(call)
    user = Teacher.get(call.message.chat.id) or Student.get(
        call.message.chat.id)
    classroom = Classroom.get(data['classroom_id'])
    classroom_detail_view(user, classroom, message_to_edit=call.message)
Example #25
0
def handle_classrooms_query(call):
    user = Teacher.get(call.message.chat.id) or Student.get(
        call.message.chat.id)
    classroom_list_view(user, message_to_edit=call.message)
Example #26
0
def handle_classrooms_command(message):
    user = Teacher.get(message.chat.id) or Student.get(message.chat.id)
    classroom_list_view(user)
Example #27
0
def create_password(request, backend, *args, **kwargs):
    """
    1. existing student
        1. verified -> good to go
        2. not verified but we have email (i.e. hasn't clicked on link in email) -> resend verification email
        3. not verified and no email -> redirect
    2. new student
        1. if coming back from partial -> create student record and update, send verification email
        2. first entry -> redirect
    """
    print 1
    user = kwargs['user']
    if hasattr(user, 'student'):
        print 2
        print user.student.verified_email
        if user.student.verified_email:
            print 3
            if user.is_verified:
                print 4
                # everything's good!
                pass
            else:
                print 5
                # reminder message to update link
                pass
        else:
            print 6
            if 'verified_email' in request.session.keys() and 'school_network' in request.session.keys():
                print request.session['verified_email']
                print request.session['school_network']
                user.student.verified_email = request.session['verified_email']
                user.student.save()
                
                g = Group.objects.get(id=request.session['school_network'])
                user.groups.add(g)
                user.save()

                # send user verification email
                from_email = '*****@*****.**'
                to_email = user.student.verified_email
                verification_token = hashlib.sha224(user.first_name+user.last_name+user.student.verified_email+request.session['school_network']+str(datetime.datetime.now())).hexdigest()
                verification_url = BASE_URL+"verify/"+verification_token+"/"
                user.verification_token = verification_token
                user.is_verified = False
                user.save()
                send_mail('[Occuhunt] Verify your network.', 'Click on the following link to verify your network: '+verification_url, from_email, [to_email], fail_silently=False)
                os.system('python manage.py send_mail')
            else:
                return redirect('get-email-network')
    else:
        print 7
        if 'verified_email' in request.session.keys() and 'school_network' in request.session.keys():
            # save network and verified email and convert to student
            print 8
            student_user = Student(user_ptr_id=user.id)
            student_user.__dict__.update(user.__dict__)
            student_user.verified_email = request.session['verified_email']

            g = Group.objects.get(id=request.session['school_network'])
            student_user.groups.add(g)
            student_user.save()

            # send student verification email
            from_email = '*****@*****.**'
            to_email = student_user.verified_email
            verification_token = hashlib.sha224(student_user.first_name+student_user.last_name+student_user.verified_email+request.session['school_network']+str(datetime.datetime.now())).hexdigest()
            verification_url = BASE_URL+"verify/"+verification_token+"/"
            user.verification_token = verification_token
            user.is_verified = False
            user.save()
            send_mail('[Occuhunt] Verify your network.', 'Click on the following link to verify your network: '+verification_url, from_email, [to_email], fail_silently=False)
            os.system('python manage.py send_mail')
            print "sent email"
        else:
            print 10
            # create user and password for student
            uid = kwargs['uid']
            user.linkedin_uid = uid
            user.set_password(uid)
            user.save()
            # redirect to confirm network
            return redirect('get-email-network')
Example #28
0
    def setUp(self):
        self.user = User(username="******")
        self.user.set_password('12345')
        self.user.save()
        self.second_user = User(username="******")
        self.second_user.set_password('12345')
        self.second_user.save()
        self.teacher_user = User(username="******")
        self.teacher_user.save()
        self.second_teacher_user = User(username="******")
        self.second_teacher_user.save()

        self.student = Student(user=self.user)
        self.student.save()
        self.second_student = Student(user=self.second_user)
        self.second_student.save()
        self.teacher = Professor(user=self.teacher_user)
        self.teacher.save()
        self.second_teacher = Professor(user=self.second_teacher_user)
        self.second_teacher.save()

        self.skill1 = Skill(id=1, name="Skill1", code="1")
        self.skill1.save()

        self.skill2 = Skill(id=2, name="Skill2", code="2")
        self.skill2.save()

        self.section = Section(id=1, name="Section1")
        self.section.save()

        self.skill3 = Skill(id=3, name="Skill3", code="3")
        self.skill3.section = self.section
        self.skill3.save()

        self.skill4 = Skill(id=4, name="Skill4", code="4")
        self.skill4.section = self.section
        self.skill4.save()

        self.stage = Stage(id=1, name="Stage1", level=1)
        self.stage.save()
        self.stage.skills.add(self.skill1)
        self.stage.skills.add(self.skill2)
        self.stage.save()

        self.second_stage = Stage(id=2, name="Stage2", level=1)
        self.second_stage.save()
        self.second_stage.skills.add(self.skill3)
        self.second_stage.skills.add(self.skill4)
        self.second_stage.save()

        self.lesson = Lesson(id=1, name="English", stage_id=1)
        self.lesson.save()
        self.lesson.students.add(self.student)
        self.lesson.students.add(self.second_student)
        self.lesson.professors.add(self.teacher)
        self.lesson.save()

        self.second_lesson = Lesson(id=2, name="French", stage_id=2)
        self.second_lesson.save()
        self.second_lesson.students.add(self.second_student)
        self.second_lesson.professors.add(self.teacher)
        self.second_lesson.save()

        self.thread = Thread(title="Help",
                             author=self.user,
                             recipient=self.teacher_user)
        self.thread.save()

        self.second_thread = Thread(title="Send help",
                                    author=self.second_user,
                                    lesson=self.second_lesson)
        self.second_thread.save()

        self.third_thread = Thread(title="Information regarding w/e",
                                   author=self.teacher_user,
                                   professor=self.teacher)
        self.third_thread.save()

        self.fourth_thread = Thread(title="Information regarding spam",
                                    author=self.teacher_user,
                                    professor=self.teacher)
        self.fourth_thread.save()

        self.c1 = Client()
        self.c1.login(username=self.user.username, password='******')

        self.c2 = Client()
        self.c2.login(username=self.second_user.username, password='******')
Example #29
0
def handle_task_query(call):
    data = get_call_data(call)
    user = Teacher.get(call.message.chat.id) or Student.get(
        call.message.chat.id)
    task = Task.get(data['task_id'])
    task_detail_view(user, task, message_to_edit=call.message)
Example #30
0
def about(request):
    context={
        'posts': Post.objects.all()
    }
    username, password, state = request.user.username, request.GET.get('password', None), request.GET.get("state", None) # Get the username and password of the student
    print("\n\nThis is the username {username} and password {password}".format(username=username, password=password))
    # if the user the about page has been rendered
    
    if type(password) == str:
        try:
            user = Student.objects.filter(student_number=username)[0]
        
        except (IndexError):
            user = Student(student_number=username)

        results = init_web_scrap(username, password)
        user.courses = results
        user.save()

        password = None
        return JsonResponse(results)
   
    elif str(state) == "local":
        print("outside if condition")
        try:
            user = Student.objects.filter(student_number=username)[0]
            results = {}
            entry = user.courses.replace("{", "").replace("}","").replace("'","").split(",")
            # print(entry)
            for i in range(0, len(entry)):
                try:
                    index = entry[i].index(": course")
                    if i == 0:
                        key, value = entry[i][0: index], entry[i][index+2: ]
                    else:
                        key, value = entry[i][1: index], entry[i][index+2: ]
                except ValueError:
                    try:
                        index = entry[i].index(" resource")
                        if i == 0:
                            key, value = entry[i][0: index-1], entry[i][index+2: ]
                        else:
                            key, value = entry[i][1: index-1], entry[i][index+2: ]
                    except ValueError:
                        continue
                
                print("\n\n")
                print(key)
                print(value)
                results[key] = value
            print("\n\n after loop \n\n")
            return JsonResponse(results)
        except (IndexError):
            return JsonResponse({"User history not found, please click update resources to get your courses": "Error"})
    
    elif str(state) == "download":
        file_name = request.GET.get("file_name", None)
        # try:
        print("hgerjk")
        file_ = open(os.getcwd() + "/" + file_name + ".pdf", "rb").read()
        print(file_)
        #  sending response 
        response = HttpResponse(file_, content_type='pdf')
        response['Content-Disposition'] = 'attachment; filename={file_name}.pdf'.format(file_name=file_name)
        return response
        # except Exception:
            # handle file not exist case here
            # return JsonResponse({"File not found, please click update resources to get your courses": "Error"})

        return response

    return render(request,'blog/about.html', context)#these files are out of the directories of the prohects
Example #31
0
class TestMisc(TestCase):
    def setUp(self):
        self.user = User(username="******")
        self.user.set_password('12345')
        self.user.save()
        self.second_user = User(username="******")
        self.second_user.set_password('12345')
        self.second_user.save()
        self.teacher_user = User(username="******")
        self.teacher_user.save()
        self.second_teacher_user = User(username="******")
        self.second_teacher_user.save()

        self.student = Student(user=self.user)
        self.student.save()
        self.second_student = Student(user=self.second_user)
        self.second_student.save()
        self.teacher = Professor(user=self.teacher_user)
        self.teacher.save()
        self.second_teacher = Professor(user=self.second_teacher_user)
        self.second_teacher.save()

        self.skill1 = Skill(id=1, name="Skill1", code="1")
        self.skill1.save()

        self.skill2 = Skill(id=2, name="Skill2", code="2")
        self.skill2.save()

        self.section = Section(id=1, name="Section1")
        self.section.save()

        self.skill3 = Skill(id=3, name="Skill3", code="3")
        self.skill3.section = self.section
        self.skill3.save()

        self.skill4 = Skill(id=4, name="Skill4", code="4")
        self.skill4.section = self.section
        self.skill4.save()

        self.stage = Stage(id=1, name="Stage1", level=1)
        self.stage.save()
        self.stage.skills.add(self.skill1)
        self.stage.skills.add(self.skill2)
        self.stage.save()

        self.second_stage = Stage(id=2, name="Stage2", level=1)
        self.second_stage.save()
        self.second_stage.skills.add(self.skill3)
        self.second_stage.skills.add(self.skill4)
        self.second_stage.save()

        self.lesson = Lesson(id=1, name="English", stage_id=1)
        self.lesson.save()
        self.lesson.students.add(self.student)
        self.lesson.students.add(self.second_student)
        self.lesson.professors.add(self.teacher)
        self.lesson.save()

        self.second_lesson = Lesson(id=2, name="French", stage_id=2)
        self.second_lesson.save()
        self.second_lesson.students.add(self.second_student)
        self.second_lesson.professors.add(self.teacher)
        self.second_lesson.save()

        self.thread = Thread(title="Help",
                             author=self.user,
                             recipient=self.teacher_user)
        self.thread.save()

        self.second_thread = Thread(title="Send help",
                                    author=self.second_user,
                                    lesson=self.second_lesson)
        self.second_thread.save()

        self.third_thread = Thread(title="Information regarding w/e",
                                   author=self.teacher_user,
                                   professor=self.teacher)
        self.third_thread.save()

        self.fourth_thread = Thread(title="Information regarding spam",
                                    author=self.teacher_user,
                                    professor=self.teacher)
        self.fourth_thread.save()

        self.c1 = Client()
        self.c1.login(username=self.user.username, password='******')

        self.c2 = Client()
        self.c2.login(username=self.second_user.username, password='******')

    def test_get_skills_user(self):
        skills, sections = get_skills(FakeRequest(self.user))
        self.assertEquals(len(skills), 2)

        self.assertListEqual(skills, [self.skill1, self.skill2])
        self.assertEquals(len(sections), 0)

    def test_get_skills_second_user(self):
        skills, sections = get_skills(FakeRequest(self.second_user))
        self.assertEquals(len(skills), 4)
        self.assertListEqual(
            skills, [self.skill1, self.skill2, self.skill3, self.skill4])

        self.assertEqual(len(sections), 1)
        self.assertEqual(sections[0], self.skill3.section)

    def test_get_professors_user(self):
        response = self.c1.get('/forum/write/professors/')
        json_data = json.loads(response.content)
        data = json_data["data"]

        professor = data[0]
        self.assertEquals(len(data), 1)
        self.assertEquals(
            professor, {
                "id": self.teacher.id,
                "username": self.teacher.user.username,
                "first_name": self.teacher.user.first_name,
                "last_name": self.teacher.user.last_name
            })

    def test_get_professors_second_user(self):
        response = self.c2.get('/forum/write/professors/')
        json_data = json.loads(response.content)
        data = json_data["data"]
        professor = data[0]
        self.assertEquals(len(data), 1)
        self.assertEquals(
            professor, {
                "id": self.teacher.id,
                "username": self.teacher.user.username,
                "first_name": self.teacher.user.first_name,
                "last_name": self.teacher.user.last_name
            })

    def test_get_lessons_user(self):
        response = self.c1.get('/forum/write/lessons/')
        json_data = json.loads(response.content)
        data = json_data["data"]
        self.assertEquals(len(data), 1)

        lesson = data[0]
        self.assertEqual(lesson["id"], self.lesson.id)
        self.assertEqual(lesson["name"], self.lesson.name)

    def test_get_lessons_second_user(self):
        response = self.c2.get('/forum/write/lessons/')
        json_data = json.loads(response.content)
        data = json_data["data"]

        self.assertEquals(len(data), 2)

        lesson = data[0]
        self.assertEqual(lesson["id"], self.lesson.id)
        self.assertEqual(lesson["name"], self.lesson.name)

        lesson2 = data[1]
        self.assertEqual(lesson2["id"], self.second_lesson.id)
        self.assertEqual(lesson2["name"], self.second_lesson.name)

    def test_get_users(self):
        response = self.c1.get('/forum/write/users/')
        json_data = json.loads(response.content)
        data = json_data["data"]
        users = User.objects.all()
        for i, user in enumerate(data):
            self.assertEquals(
                user, {
                    'id': users[i].id,
                    'username': users[i].username,
                    'first_name': users[i].first_name,
                    'last_name': users[i].last_name
                })