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


Python Assignment.file方法代码示例

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


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

示例1: post

# 需要导入模块: from compair.models import Assignment [as 别名]
# 或者: from compair.models.Assignment import file [as 别名]
    def post(self, course_uuid):
        """
        Duplicate a course
        """
        course = Course.get_active_by_uuid_or_404(course_uuid)
        require(EDIT, course)

        params = duplicate_course_parser.parse_args()

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

        if len(assignments) != len(assignments_copy_data):
            return {"error": "Not enough assignment data provided to duplication course"}, 400

        for assignment_copy_data in assignments_copy_data:
            if not assignment_copy_data.get('answer_start'):
                return {"error": "No answer start date provided for assignment "+assignment_copy_data.id}, 400

            if not assignment_copy_data.get('answer_end'):
                return {"error": "No answer end date provided for assignment "+assignment_copy_data.id}, 400

            assignment_copy_data['answer_start'] = datetime.datetime.strptime(
                assignment_copy_data.get('answer_start'), '%Y-%m-%dT%H:%M:%S.%fZ')
            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')

        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

        # duplicate course
        duplicate_course = Course(
            name=params.get("name"),
            year=params.get("year"),
            term=params.get("term"),
            description=course.description,
            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)

        assignment_files_to_duplicate = []
        answer_files_to_duplicate = []

        # 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:
                return {"error": "No assignment data provided for assignment "+assignment.uuid}, 400

            duplicate_assignment = Assignment(
                course=duplicate_course,
                user_id=current_user.id,
                name=assignment.name,
                description=assignment.description,

                answer_start=assignment_copy_data.get('answer_start'),
                answer_end=assignment_copy_data.get('answer_end'),
                compare_start=assignment_copy_data.get('compare_start'),
                compare_end=assignment_copy_data.get('compare_end'),

                #TODO: uncomment when grade pull request is accepted
                #answer_grade_weight=assignment.answer_grade_weight,
                #comparison_grade_weight=assignment.comparison_grade_weight,
                #self_evaluation_grade_weight=assignment.self_evaluation_grade_weight,

                number_of_comparisons=assignment.number_of_comparisons,
                students_can_reply=assignment.students_can_reply,
                enable_self_evaluation=assignment.enable_self_evaluation,
                pairing_algorithm=assignment.pairing_algorithm
            )

            # register assignemnt files for later
#.........这里部分代码省略.........
开发者ID:,项目名称:,代码行数:103,代码来源:


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