Ejemplo n.º 1
0
def index_post(request):
    ink_form = InkForm(request.POST)
    password_form = NonSavingCustomSetPasswordForm(request.POST)
    if ink_form.is_valid() and password_form.is_valid():
        fname = ink_form.cleaned_data['fname']
        lname = ink_form.cleaned_data['lname']
        email = ink_form.cleaned_data['email']
        classroom = ink_form.cleaned_data['section']

        username = build_username(fname, lname)
        group = HWCentralGroup.refs.STUDENT
        school = request.user.userinfo.school

        password = password_form.cleaned_data['new_password2']

        user = User.objects.create_user(username=username,
                                        email=email,
                                        password=password)
        user.first_name = fname
        user.last_name = lname
        user.save()
        userinfo = UserInfo(user=user)
        userinfo.group = group
        userinfo.school = school
        userinfo.save()

        # student has been created, now add the student to the right classroom and subjectrooms
        classroom.students.add(user)
        classroom.save()

        for subjectroom in classroom.subjectroom_set.all():
            subjectroom.students.add(user)
            subjectroom.save()

        # finally, save the dossier on the new user - TODO: part of ink form should be replaced by dossier modelform
        dossier = Dossier(user=user)
        dossier.flagged = ink_form.cleaned_data['flagged']
        dossier.phone = ink_form.cleaned_data['phone']
        if ink_form.cleaned_data['secondaryPhone']:
            dossier.secondaryPhone = ink_form.cleaned_data['secondaryPhone']
        if ink_form.cleaned_data['secondaryEmail']:
            dossier.secondaryEmail = ink_form.cleaned_data['secondaryEmail']

        dossier.save()

        return render_with_success_toast(
            request,
            '<div>The new account has been activated!</div><h3>username: %s</h3>'
            % username, InkUrlNames.INDEX.template,
            AuthenticatedVM(
                request.user,
                IndexBody(InkForm(),
                          NonSavingCustomSetPasswordForm())).as_context())
    else:
        return render_with_error_toast(
            request,
            'There was a problem with your information. Please fix the errors and try again.',
            InkUrlNames.INDEX.template,
            AuthenticatedVM(request.user,
                            IndexBody(ink_form, password_form)).as_context())
Ejemplo n.º 2
0
    def student_endpoint(self):
        if not self.student_valid():
            raise Http404

        if not self.submission.revised:
            return render(
                self.request, UrlNames.SUBMISSION_ID.get_template('revision'),
                AuthenticatedVM(
                    self.user,
                    RevisionSubmissionIdBody(
                        self.user, self.submission,
                        AssignmentInfo.CAT_DUE)).as_context())

        # we can assume at this point that a shell submission exists at the very least
        # get the submission data from the cabinet
        submission_dm = cabinet_api.get_submission(self.submission)
        # get a 'protected' version of the submission data (without solutions and targets)
        submission_vm = SubmissionVMProtected(submission_dm)
        # build the submission form using the submission data
        submission_form = SubmissionForm(submission_vm, True)
        return render(
            self.request, self.template,
            AuthenticatedVM(
                self.user,
                UncorrectedSubmissionIdBody(
                    self.user, submission_form, self.submission,
                    AssignmentInfo.CAT_DUE)).as_context())
Ejemplo n.º 3
0
    def handle(self):
        parent_form = ParentForm(self.request.POST)
        if parent_form.is_valid():
            # make parent account
            fname = parent_form.cleaned_data['fname']
            lname = parent_form.cleaned_data['lname']
            email = parent_form.cleaned_data['email']

            username = build_username(fname, lname)
            group = HWCentralGroup.refs.PARENT
            school = self.user.userinfo.school

            password = build_parent_password()

            parent = User.objects.create_user(username=username,
                                              email=email,
                                              password=password)
            parent.first_name = fname
            parent.last_name = lname
            parent.save()

            userinfo = UserInfo(user=parent)
            userinfo.group = group
            userinfo.school = school
            userinfo.save()

            # finally, save the dossier on the new user
            dossier = Dossier(user=parent)
            dossier.flagged = False
            dossier.phone = parent_form.cleaned_data['phone']
            dossier.save()

            # make home
            home = Home(parent=parent)
            home.save()
            home.children.add(self.student)
            home.save()

            # send activation sms
            notify_activate(parent, password)

            return render_with_success_toast(
                self.request,
                '<div>The new account has been activated!</div><h3>username: %s</h3>'
                % username, self.template,
                AuthenticatedVM(self.user,
                                ParentIdBody(self.student,
                                             ParentForm())).as_context())
        else:
            return render_with_error_toast(
                self.request,
                'There was a problem with your information. Please fix the errors and try again.',
                self.template,
                AuthenticatedVM(self.user,
                                ParentIdBody(self.student,
                                             parent_form)).as_context())
Ejemplo n.º 4
0
 def admin_endpoint(self):
     if self.classroom.school != self.user.userinfo.school:
         raise Http404
     return render(
         self.request, self.template,
         AuthenticatedVM(self.user,
                         ClassroomIdBody(self.classroom)).as_context())
Ejemplo n.º 5
0
 def open_student_endpoint(self):
     return render(
         self.request, self.template,
         AuthenticatedVM(
             self.user,
             OpenStudentHomeBody(self.user, OpenAssignmentForm(
                 self.user))).as_context())
Ejemplo n.º 6
0
def index_get(request):
    return render(
        request, InkUrlNames.INDEX.template,
        AuthenticatedVM(request.user,
                        IndexBody(
                            InkForm(),
                            NonSavingCustomSetPasswordForm())).as_context())
Ejemplo n.º 7
0
 def teacher_endpoint(self):
     # form to create assignment from assignmentquestionslist
     form = AssignmentForm(self.user, self.override)
     return render(
         self.request, self.template,
         AuthenticatedVM(self.user,
                         AssignmentBody(form, self.override)).as_context())
Ejemplo n.º 8
0
    def teacher_endpoint(self):
        # form to create assignment from assignmentquestionslist
        form = AssignmentForm(self.user, self.override, self.request.POST)
        if form.is_valid():
            assignmentQuestionsList = form.cleaned_data['question_set']
            subjectRoom = form.cleaned_data['subjectroom']
            assigned = form.cleaned_data['assigned']
            due = form.cleaned_data['due']
            # check if same aql has been assigned in this subjectroom before, if yes increase number
            number = Assignment.get_new_assignment_number(
                assignmentQuestionsList, subjectRoom)
            new_assignment = Assignment.objects.create(
                assignmentQuestionsList=assignmentQuestionsList,
                content_object=subjectRoom,
                assigned=assigned,
                due=due,
                number=number)
            return redirect_with_success_toast(
                self.request,
                'Assignment %s for SubjectRoom %s was assigned successfully.' %
                (new_assignment.get_title(),
                 get_subjectroom_label(new_assignment.get_subjectroom())))

        else:
            return render(
                self.request, self.template,
                AuthenticatedVM(self.user,
                                AssignmentBody(form,
                                               self.override)).as_context())
Ejemplo n.º 9
0
 def teacher_endpoint(self):
     if self.classroom.classTeacher != self.user:
         raise Http404
     return render(
         self.request, self.template,
         AuthenticatedVM(self.user,
                         ClassroomIdBody(self.classroom)).as_context())
Ejemplo n.º 10
0
    def student_endpoint(self):
        if not self.student_valid():
            raise Http404

        if not self.submission.revised:
            # make sure that the revised flag is POSTed
            return handle_unrevised_post(self.request, self.submission)

        submission_dm, submission_form = self.process_form()

        if submission_form.is_valid():
            self.update_submission(submission_dm, submission_form)
            if 'correct' in self.request.POST:
                self.update_assignment(False)
                return redirect_with_success_toast(
                    self.request,
                    SubmissionIdPostStudent.build_corrected_message(True),
                    [UrlNames.SUBMISSION_ID.name, self.submission.pk])
            elif 'save' in self.request.POST:
                renderer = render_with_success_toast
                message = "Your submission has been saved."
            else:
                raise InvalidStateError

        else:
            renderer = render_with_error_toast
            message = 'Some of the answers were invalid. Please fix the errors below and try again.'

        return renderer(
            self.request, message, self.template,
            AuthenticatedVM(
                self.user,
                UncorrectedSubmissionIdBody(
                    self.user, submission_form, self.submission,
                    AssignmentInfo.CAT_PRACTICE)).as_context())
Ejemplo n.º 11
0
    def common_endpoint(self):
        form = CustomPasswordChangeForm(user=self.user, data=self.request.POST)
        if form.is_valid():
            form.save()
            return redirect_with_success_toast(self.request, 'Your password was changed successfully.')

        return render(self.request, self.template,
                      AuthenticatedVM(self.user, PasswordBody(form)).as_context())
Ejemplo n.º 12
0
 def parent_endpoint(self):
     # validation: parent should only see this page if the have a home rel with the child
     if not is_parent_child_relationship(self.user, self.child):
         raise Http404
     return render(self.request, self.template, AuthenticatedVM(self.user,
                                                                ParentFocusIdBody(self.child,
                                                                                  self.focusroom))
                   .as_context())
Ejemplo n.º 13
0
    def student_endpoint(self):
        if not is_subjectroom_student_relationship(self.focusroom.subjectRoom, self.user):
            raise Http404

        return render(self.request, self.template, AuthenticatedVM(self.user,
                                                                   StudentFocusIdBody(self.user,
                                                                                      self.focusroom))
                      .as_context())
Ejemplo n.º 14
0
    def teacher_endpoint(self):
        if self.focusroom.subjectRoom.teacher != self.user and (
                not is_subjectroom_classteacher_relationship(self.focusroom.subjectRoom, self.user)):
            raise Http404

        return render(self.request, self.template, AuthenticatedVM(self.user,
                                                                   TeacherFocusIdBody(self.user,
                                                                                      self.focusroom))
                      .as_context())
Ejemplo n.º 15
0
 def render_corrected_submission(self, categorization):
     submission_vm = SubmissionVMUnprotected(
         cabinet_api.get_submission(self.submission))
     return render(
         self.request, self.template,
         AuthenticatedVM(
             self.user,
             CorrectedSubmissionIdBodySubmissionUser(
                 self.user, self.submission, submission_vm,
                 categorization)).as_context())
Ejemplo n.º 16
0
 def teacher_endpoint(self):
     if not self.teacher_valid():
         raise Http404
     return render(
         self.request, self.template,
         AuthenticatedVM(
             self.user,
             CorrectedSubmissionIdBodyDifferentUser(
                 self.submission, self.submission_vm, self.user,
                 self.categorization)).as_context())
Ejemplo n.º 17
0
    def open_student_endpoint(self):
        if not is_subjectroom_student_relationship(self.subjectroom,
                                                   self.user):
            raise Http404

        return render(
            self.request, self.template,
            AuthenticatedVM(
                self.user,
                OpenStudentSubjectIdBody(self.user,
                                         self.subjectroom)).as_context())
Ejemplo n.º 18
0
 def render_uncorrected_submission(self, categorization):
     # we can assume at this point that a shell submission exists at the very least
     # get the submission data from the cabinet
     submission_dm = cabinet_api.get_submission(self.submission)
     # get a 'protected' version of the submission data (without solutions and targets)
     submission_vm = SubmissionVMProtected(submission_dm)
     # build the submission form using the submission data
     submission_form = SubmissionForm(submission_vm, True)
     return render(
         self.request, self.template,
         AuthenticatedVM(
             self.user,
             UncorrectedSubmissionIdBody(self.user, submission_form,
                                         self.submission,
                                         categorization)).as_context())
Ejemplo n.º 19
0
    def admin_endpoint(self):

        form = AdminAnnouncementForm(self.request.POST)
        if form.is_valid():
            content_object = self.user.userinfo.school
            message = form.cleaned_data['message']
            new_announcement = Announcement.objects.create(
                content_object=content_object,
                message=message,
                announcer=self.user)
            return self.redirect_with_toast(new_announcement)
        else:
            return render(
                self.request, self.template,
                AuthenticatedVM(self.user,
                                AnnouncementBody(form)).as_context())
Ejemplo n.º 20
0
    def student_endpoint(self):
        form = PracticeForm(self.user, self.request.POST)
        if form.is_valid():
            assignmentQuestionsList = form.cleaned_data['question_set']
            submission = self.create_new_student_assignment(
                assignmentQuestionsList)
            return redirect_with_success_toast(
                self.request,
                self.build_success_message('Practice Assignment %s' %
                                           submission.assignment.get_title()),
                [UrlNames.SUBMISSION_ID.name, submission.pk])

        else:
            return render(
                self.request, self.template,
                AuthenticatedVM(self.user, PracticeBody(form)).as_context())
Ejemplo n.º 21
0
    def open_student_endpoint(self):
        form = OpenAssignmentForm(self.user, self.request.POST)
        if form.is_valid():
            assignmentQuestionsList = form.cleaned_data['question_set']
            submission = self.create_new_student_assignment(
                assignmentQuestionsList)
            return redirect_with_success_toast(
                self.request,
                self.build_success_message('Assignment %s' %
                                           submission.assignment.get_title()),
                [UrlNames.SUBMISSION_ID.name, submission.pk])

        else:
            return render(
                self.request,
                UrlNames.HOME.get_template(HWCentralGroup.refs.OPEN_STUDENT),
                AuthenticatedVM(self.user,
                                OpenStudentHomeBody(self.user,
                                                    form)).as_context())
Ejemplo n.º 22
0
    def common_student_endpoint(self, categorization):
        """
        Handles both practice (for student) and open (for open student) assignments
        """
        if self.type == HWCentralStudentAssignmentSubmissionType.CORRECTED:
            return self.render_corrected_submission(categorization)

        elif self.type == HWCentralStudentAssignmentSubmissionType.UNCORRECTED:
            if not self.submission.revised:
                return render(
                    self.request,
                    UrlNames.SUBMISSION_ID.get_template('revision'),
                    AuthenticatedVM(
                        self.user,
                        RevisionSubmissionIdBody(self.user, self.submission,
                                                 categorization)).as_context())
            return self.render_uncorrected_submission(categorization)
        else:
            raise InvalidHWCentralAssignmentTypeError(self.type)
Ejemplo n.º 23
0
    def teacher_endpoint(self):
        classteacher = False
        subjectteacher = False
        if self.user.classes_managed_set.exists():
            classteacher = True
        if self.user.subjects_managed_set.exists():
            subjectteacher = True

        if classteacher and (not subjectteacher):
            form = ClassAnnouncementForm(self.user)
        elif classteacher and subjectteacher:
            form = ClassSubjectAnnouncementForm(self.user)
        elif (not classteacher) and subjectteacher:
            form = SubjectAnnouncementForm(self.user)
        else:  # (not classteacher) and (not subjectteacher)
            raise Http404

        return render(
            self.request, self.template,
            AuthenticatedVM(self.user, AnnouncementBody(form)).as_context())
Ejemplo n.º 24
0
    def render_preview_assignment(self):
        questions_randomized_dealt = croupier_api.build_assignment_user_seed(
            self.user, self.assignment_questions_list)

        # now build a shell submission
        shell_submission_dm = SubmissionDM.build_shell(
            questions_randomized_dealt)

        # use an unprotected version of the submission data
        shell_submission_vm = SubmissionVMUnprotected(shell_submission_dm)

        # and use it to build a readonly submission form which will help us easily render the assignment
        assignment_preview_form = ReadOnlySubmissionFormUnprotected(
            shell_submission_vm)

        authenticated_body = AssignmentPreviewIdBody(
            self.user, self.assignment_questions_list, assignment_preview_form)

        return render(
            self.request, self.template,
            AuthenticatedVM(self.user, authenticated_body).as_context())
Ejemplo n.º 25
0
    def student_endpoint(self):
        if not self.student_valid():
            raise Http404

        if not self.submission.revised:
            # make sure that the revised flag is POSTed
            return handle_unrevised_post(self.request, self.submission)

        # we can assume at this point that a shell submission exists at the very least
        # get the submission data from the cabinet
        submission_dm = cabinet_api.get_submission(self.submission)
        submission_vm = SubmissionVMProtected(submission_dm)
        submission_form = SubmissionForm(submission_vm, False,
                                         self.request.POST)
        if submission_form.is_valid():
            # update the submission data with the form data
            submission_dm.update_answers(submission_form.get_answers())
            # update the submission data in cabinet
            cabinet_api.update_submission(self.submission, submission_dm)
            # update the submisssion in db
            self.submission.timestamp = django.utils.timezone.now()
            self.submission.completion = submission_dm.calculate_completion()
            self.submission.save()

            renderer = render_with_success_toast
            message = "Your submission has been saved."
        else:
            renderer = render_with_error_toast
            message = 'Some of the answers were invalid. Please fix the errors below and try again.'

        return renderer(
            self.request, message, self.template,
            AuthenticatedVM(
                self.user,
                UncorrectedSubmissionIdBody(
                    self.user, submission_form, self.submission,
                    AssignmentInfo.CAT_DUE)).as_context())
Ejemplo n.º 26
0
 def admin_endpoint(self):
     return render(
         self.request, self.template,
         AuthenticatedVM(self.user,
                         AdminSettingsBody(self.user)).as_context())
Ejemplo n.º 27
0
 def open_student_endpoint(self):
     return render(
         self.request, self.template,
         AuthenticatedVM(self.user,
                         OpenStudentSettingsBody(self.user)).as_context())
Ejemplo n.º 28
0
 def student_endpoint(self):
     form = PracticeForm(self.user)
     return render(
         self.request, self.template,
         AuthenticatedVM(self.user, PracticeBody(form)).as_context())
Ejemplo n.º 29
0
 def handle(self):
     return render(
         self.request, self.template,
         AuthenticatedVM(self.user,
                         ParentIdBody(self.student,
                                      ParentForm())).as_context())
Ejemplo n.º 30
0
    def open_student_endpoint(self):
        if not self.student_valid():
            raise Http404

        if not self.submission.revised:
            # make sure that the revised flag is POSTed
            return handle_unrevised_post(self.request, self.submission)

        submission_dm, submission_form = self.process_form()
        if submission_form.is_valid():
            self.update_submission(submission_dm, submission_form)
            if 'correct' in self.request.POST:
                # log the old proficiency
                utils = OpenStudentUtils(self.user)
                subjectroom = self.submission.assignment.get_subjectroom()
                old_proficiency = utils.get_proficiency(subjectroom)
                old_proficiency = ProficiencyClass(old_proficiency)

                self.update_assignment(True)
                calculate_edge_data()
                # update the OpenStudentHighest if required
                try:
                    highest = OpenStudentHighest.objects.get(
                        student=self.user,
                        submission__assignment__assignmentQuestionsList=self.
                        submission.assignment.assignmentQuestionsList)
                    if highest.submission.marks < self.submission.marks:
                        highest.submission = self.submission
                        highest.save()
                except OpenStudentHighest.DoesNotExist:
                    OpenStudentHighest.objects.create(
                        student=self.user, submission=self.submission)

                # check if proficiency has improved
                new_proficiency = utils.get_proficiency(subjectroom)
                new_proficiency = ProficiencyClass(new_proficiency)

                self.update_badges(subjectroom, new_proficiency,
                                   old_proficiency)

                return redirect_with_success_toast(
                    self.request,
                    SubmissionIdPostStudent.build_corrected_message(False),
                    [UrlNames.SUBMISSION_ID.name, self.submission.pk])
            elif 'save' in self.request.POST:
                renderer = render_with_success_toast
                message = "Your submission has been saved."
            else:
                raise InvalidStateError

        else:
            renderer = render_with_error_toast
            message = 'Some of the answers were invalid. Please fix the errors below and try again.'

        return renderer(
            self.request, message, self.template,
            AuthenticatedVM(
                self.user,
                UncorrectedSubmissionIdBody(
                    self.user, submission_form, self.submission,
                    AssignmentInfo.CAT_OPEN)).as_context())