当前位置: 首页>>代码示例>>Python>>正文


Python Assignment.validate_periods方法代码示例

本文整理汇总了Python中compair.models.Assignment.validate_periods方法的典型用法代码示例。如果您正苦于以下问题:Python Assignment.validate_periods方法的具体用法?Python Assignment.validate_periods怎么用?Python Assignment.validate_periods使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在compair.models.Assignment的用法示例。


在下文中一共展示了Assignment.validate_periods方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: post

# 需要导入模块: from compair.models import Assignment [as 别名]
# 或者: from compair.models.Assignment import validate_periods [as 别名]
    def post(self, course_uuid, assignment_uuid):
        course = Course.get_active_by_uuid_or_404(course_uuid)
        assignment = Assignment.get_active_by_uuid_or_404(assignment_uuid)
        assignment_criteria = assignment.assignment_criteria
        require(EDIT, assignment,
            title="Assignment Not Saved",
            message="Sorry, your role in this course does not allow you to save assignments.")

        if current_app.config.get('DEMO_INSTALLATION', False):
            from data.fixtures import DemoDataFixture
            if assignment.id in DemoDataFixture.DEFAULT_ASSIGNMENT_IDS:
                abort(400, title="Assignment Not Saved", message="Sorry, you cannot edit the default demo assignments.")

        params = existing_assignment_parser.parse_args()

        # make sure the assignment id in the url and the id matches
        if params['id'] != assignment_uuid:
            abort(400, title="Assignment Not Saved", message="The assignment's ID does not match the URL, which is required in order to update the assignment.")

        old_file = assignment.file

        # make sure that file attachment exists
        file_uuid = params.get('file_id')
        attachment = None
        if file_uuid:
            attachment = File.get_by_uuid_or_404(file_uuid)
            assignment.file_id = attachment.id
        else:
            assignment.file_id = None

        # modify assignment according to new values, preserve original values if values not passed
        assignment.name = params.get("name", assignment.name)
        assignment.description = params.get("description", assignment.description)
        assignment.peer_feedback_prompt = params.get("peer_feedback_prompt", assignment.peer_feedback_prompt)
        assignment.answer_start = datetime.datetime.strptime(
            params.get('answer_start', assignment.answer_start),
            '%Y-%m-%dT%H:%M:%S.%fZ')
        assignment.answer_end = datetime.datetime.strptime(
            params.get('answer_end', assignment.answer_end),
            '%Y-%m-%dT%H:%M:%S.%fZ')
        # if nothing in request, assume user doesn't want comparison date
        assignment.compare_start = params.get('compare_start', None)
        if assignment.compare_start is not None:
            assignment.compare_start = datetime.datetime.strptime(
                assignment.compare_start,
                '%Y-%m-%dT%H:%M:%S.%fZ')
        assignment.compare_end = params.get('compare_end', None)
        if assignment.compare_end is not None:
            assignment.compare_end = datetime.datetime.strptime(
                params.get('compare_end', assignment.compare_end),
                '%Y-%m-%dT%H:%M:%S.%fZ')

        assignment.enable_self_evaluation = params.get('enable_self_evaluation', assignment.enable_self_evaluation)
        assignment.self_eval_instructions = params.get('self_eval_instructions', None)
        assignment.self_eval_start = params.get('self_eval_start', None)
        if assignment.self_eval_start is not None:
            assignment.self_eval_start = datetime.datetime.strptime(
                assignment.self_eval_start,
                '%Y-%m-%dT%H:%M:%S.%fZ')
        assignment.self_eval_end = params.get('self_eval_end', None)
        if assignment.self_eval_end is not None:
            assignment.self_eval_end = datetime.datetime.strptime(
                params.get('self_eval_end', assignment.self_eval_end),
                '%Y-%m-%dT%H:%M:%S.%fZ')

        # validate answer + comparison period + self-eval start & end times
        valid, error_message = Assignment.validate_periods(course.start_date, course.end_date,
             assignment.answer_start, assignment.answer_end,
             assignment.compare_start, assignment.compare_end,
             assignment.self_eval_start, assignment.self_eval_end)
        if not valid:
            abort(400, title="Assignment Not Saved", message=error_message)

        assignment.students_can_reply = params.get('students_can_reply', False)
        assignment.number_of_comparisons = params.get('number_of_comparisons', assignment.number_of_comparisons)

        if assignment.student_answer_count == 0:
            assignment.enable_group_answers = params.get('enable_group_answers')
        elif assignment.enable_group_answers != params.get('enable_group_answers'):
            abort(400, title="Assignment Not Saved",
                message='Group answer settings selection cannot be changed for this assignment because there are already submitted answers.')

        assignment.answer_grade_weight = params.get(
            'answer_grade_weight', assignment.answer_grade_weight)
        assignment.comparison_grade_weight = params.get(
            'comparison_grade_weight', assignment.comparison_grade_weight)
        assignment.self_evaluation_grade_weight = params.get(
            'self_evaluation_grade_weight', assignment.self_evaluation_grade_weight)

        pairing_algorithm = params.get("pairing_algorithm")
        check_valid_pairing_algorithm(pairing_algorithm)
        if not assignment.compared:
            assignment.pairing_algorithm = PairingAlgorithm(pairing_algorithm)
        elif assignment.pairing_algorithm != PairingAlgorithm(pairing_algorithm):
            abort(400, title="Assignment Not Saved",
                message='The answer pair selection algorithm cannot be changed for this assignment because it has already been used in one or more comparisons.')

        assignment.educators_can_compare = params.get("educators_can_compare")

        assignment.rank_display_limit = params.get("rank_display_limit", None)
#.........这里部分代码省略.........
开发者ID:ubc,项目名称:acj-versus,代码行数:103,代码来源:assignment.py

示例2: post

# 需要导入模块: from compair.models import Assignment [as 别名]
# 或者: from compair.models.Assignment import validate_periods [as 别名]
    def post(self, course_uuid):
        """
        Duplicate a course
        """
        course = Course.get_active_by_uuid_or_404(course_uuid)
        require(EDIT, course,
            title="Course Not Duplicated",
            message="Sorry, your role in this course does not allow you to duplicate it.")

        params = duplicate_course_parser.parse_args()

        start_date = datetime.datetime.strptime(
            params.get("start_date"), '%Y-%m-%dT%H:%M:%S.%fZ'
        ) if params.get("start_date") else None

        end_date = datetime.datetime.strptime(
            params.get("end_date"), '%Y-%m-%dT%H:%M:%S.%fZ'
        ) if params.get("end_date") else None

        if start_date is None:
            abort(400, title="Course Not Saved", message="Course start time is required.")
        elif start_date and end_date and start_date > end_date:
            abort(400, title="Course Not Saved", message="Course end time must be after course start time.")

        assignments = [assignment for assignment in course.assignments if assignment.active]
        assignments_copy_data = params.get("assignments")

        if len(assignments) != len(assignments_copy_data):
            abort(400, title="Course Not Saved", message="The course is missing assignments. Please reload the page and try duplicating again.")

        for assignment_copy_data in assignments_copy_data:
            if assignment_copy_data.get('answer_start'):
                assignment_copy_data['answer_start'] = datetime.datetime.strptime(
                    assignment_copy_data.get('answer_start'), '%Y-%m-%dT%H:%M:%S.%fZ')

            if assignment_copy_data.get('answer_end'):
                assignment_copy_data['answer_end'] = datetime.datetime.strptime(
                    assignment_copy_data.get('answer_end'), '%Y-%m-%dT%H:%M:%S.%fZ')

            if assignment_copy_data.get('compare_start'):
                assignment_copy_data['compare_start'] = datetime.datetime.strptime(
                    assignment_copy_data.get('compare_start'), '%Y-%m-%dT%H:%M:%S.%fZ')

            if assignment_copy_data.get('compare_end'):
                assignment_copy_data['compare_end'] = datetime.datetime.strptime(
                    assignment_copy_data.get('compare_end'), '%Y-%m-%dT%H:%M:%S.%fZ')

            if 'enable_self_evaluation' not in assignment_copy_data:
                assignment_copy_data['enable_self_evaluation'] = False

            if assignment_copy_data.get('self_eval_start'):
                assignment_copy_data['self_eval_start'] = datetime.datetime.strptime(
                    assignment_copy_data.get('self_eval_start'), '%Y-%m-%dT%H:%M:%S.%fZ')

            if assignment_copy_data.get('self_eval_end'):
                assignment_copy_data['self_eval_end'] = datetime.datetime.strptime(
                    assignment_copy_data.get('self_eval_end'), '%Y-%m-%dT%H:%M:%S.%fZ')

            valid, error_message = Assignment.validate_periods(start_date, end_date,
                assignment_copy_data.get('answer_start'), assignment_copy_data.get('answer_end'),
                assignment_copy_data.get('compare_start'), assignment_copy_data.get('compare_end'),
                assignment_copy_data.get('self_eval_start'), assignment_copy_data.get('self_eval_end'))
            if not valid:
                error_message = error_message.replace(".", "") + " for assignment "+text_type(assignment_copy_data.get('name', ''))+"."
                abort(400, title="Course Not Saved", message=error_message)

        # duplicate course
        duplicate_course = Course(
            name=params.get("name"),
            year=params.get("year"),
            term=params.get("term"),
            sandbox=params.get("sandbox"),
            start_date=start_date,
            end_date=end_date
        )
        db.session.add(duplicate_course)

        # also need to enrol the user as an instructor
        new_user_course = UserCourse(
            course=duplicate_course,
            user_id=current_user.id,
            course_role=CourseRole.instructor
        )
        db.session.add(new_user_course)

        # duplicate assignments
        for assignment in assignments:
            # this should never be null due
            assignment_copy_data = next((assignment_copy_data
                for assignment_copy_data in assignments_copy_data
                if assignment_copy_data.get('id') == assignment.uuid),
                None
            )

            if not assignment_copy_data:
                abort(400, title="Course Not Saved", message="Missing information for assignment "+assignment.name+". Please try duplicating again.")

            duplicate_assignment = Assignment(
                course=duplicate_course,
                user_id=current_user.id,
#.........这里部分代码省略.........
开发者ID:ubc,项目名称:acj-versus,代码行数:103,代码来源:course.py


注:本文中的compair.models.Assignment.validate_periods方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。