本文整理汇总了Python中compair.models.Assignment类的典型用法代码示例。如果您正苦于以下问题:Python Assignment类的具体用法?Python Assignment怎么用?Python Assignment使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Assignment类的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: delete
def delete(self, course_uuid, assignment_uuid, answer_uuid):
course = Course.get_active_by_uuid_or_404(course_uuid)
assignment = Assignment.get_active_by_uuid_or_404(assignment_uuid)
answer = Answer.get_active_by_uuid_or_404(answer_uuid)
require(DELETE, answer)
answer.active = False
if answer.file:
answer.file.active = False
db.session.commit()
# update course & assignment grade for user if answer was fully submitted
if not answer.draft:
assignment.calculate_grade(answer.user)
course.calculate_grade(answer.user)
on_answer_delete.send(
self,
event_name=on_answer_delete.name,
user=current_user,
course_id=course.id,
answer=answer,
data={'assignment_id': assignment.id, 'answer_id': answer.id})
return {'id': answer.uuid}
示例2: delete
def delete(self, course_uuid, assignment_uuid, answer_uuid, answer_comment_uuid):
"""
Delete an answer comment
"""
course = Course.get_active_by_uuid_or_404(course_uuid)
assignment = Assignment.get_active_by_uuid_or_404(assignment_uuid)
answer_comment = AnswerComment.get_active_by_uuid_or_404(answer_comment_uuid)
require(DELETE, answer_comment)
data = marshal(answer_comment, dataformat.get_answer_comment(False))
answer_comment.active = False
db.session.commit()
# update course & assignment grade for user if self-evaluation is completed
if not answer_comment.draft and answer_comment.comment_type == AnswerCommentType.self_evaluation:
assignment.calculate_grade(answer_comment.user)
course.calculate_grade(answer_comment.user)
on_answer_comment_delete.send(
self,
event_name=on_answer_comment_delete.name,
user=current_user,
course_id=course.id,
answer_comment=answer_comment,
data=data,
)
return {"id": answer_comment.uuid}
示例3: post
def post(self, course_uuid, assignment_uuid, comparison_example_uuid):
course = Course.get_active_by_uuid_or_404(course_uuid)
assignment = Assignment.get_active_by_uuid_or_404(assignment_uuid)
comparison_example = ComparisonExample.get_active_by_uuid_or_404(comparison_example_uuid)
require(EDIT, comparison_example)
params = existing_comparison_example_parser.parse_args()
answer1_uuid = params.get("answer1_id")
answer2_uuid = params.get("answer2_id")
if answer1_uuid:
answer1 = Answer.get_active_by_uuid_or_404(answer1_uuid)
answer1.practice = True
comparison_example.answer1 = answer1
else:
return {"error": "Comparison examples must have 2 answers"}, 400
if answer2_uuid:
answer2 = Answer.get_active_by_uuid_or_404(answer2_uuid)
answer2.practice = True
comparison_example.answer2 = answer2
else:
return {"error": "Comparison examples must have 2 answers"}, 400
on_comparison_example_modified.send(
self,
event_name=on_comparison_example_modified.name,
user=current_user,
course_id=course.id,
data=get_model_changes(comparison_example))
db.session.add(comparison_example)
db.session.commit()
return marshal(comparison_example, dataformat.get_comparison_example())
示例4: post
def post(self, course_uuid, assignment_uuid, answer_uuid):
"""
Mark an answer as being a top answer
:param course_uuid:
:param assignment_uuid:
:param answer_uuid:
:return: marked answer
"""
course = Course.get_active_by_uuid_or_404(course_uuid)
assignment = Assignment.get_active_by_uuid_or_404(assignment_uuid)
answer = Answer.get_active_by_uuid_or_404(answer_uuid)
require(MANAGE, answer,
title="Answer Not Added",
message="Your role in this course does not allow you to add to the list of instructor-picked answers.")
params = top_answer_parser.parse_args()
answer.top_answer = params.get('top_answer')
db.session.add(answer)
on_set_top_answer.send(
self,
event_name=on_set_top_answer.name,
user=current_user,
course_id=course.id,
assignment_id=assignment.id,
data={'answer_id': answer.id, 'top_answer': answer.top_answer})
db.session.commit()
return marshal(answer, dataformat.get_answer(restrict_user=False))
示例5: delete
def delete(self, course_uuid, assignment_uuid, answer_uuid):
course = Course.get_active_by_uuid_or_404(course_uuid)
assignment = Assignment.get_active_by_uuid_or_404(assignment_uuid)
answer = Answer.get_active_by_uuid_or_404(answer_uuid)
require(DELETE, answer,
title="Answer Not Deleted",
message="Sorry, your role in this course does not allow you to delete this answer.")
if current_app.config.get('DEMO_INSTALLATION', False):
from data.fixtures import DemoDataFixture
if assignment.id in DemoDataFixture.DEFAULT_ASSIGNMENT_IDS and answer.user_id in DemoDataFixture.DEFAULT_STUDENT_IDS:
abort(400, title="Answer Not Deleted", message="Sorry, you cannot delete the default student demo answers.")
answer.active = False
db.session.commit()
# update course & assignment grade for user if answer was fully submitted
if not answer.draft:
if answer.user:
assignment.calculate_grade(answer.user)
course.calculate_grade(answer.user)
elif answer.group:
assignment.calculate_group_grade(answer.group)
course.calculate_group_grade(answer.group)
on_answer_delete.send(
self,
event_name=on_answer_delete.name,
user=current_user,
course_id=course.id,
answer=answer,
data={'assignment_id': assignment.id, 'answer_id': answer.id})
return {'id': answer.uuid}
示例6: delete
def delete(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)
require(DELETE, assignment,
title="Assignment Not Deleted",
message="Sorry, your role in this course does not allow you to delete 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 Deleted", message="Sorry, you cannot remove the default demo assignments.")
formatted_assignment = marshal(assignment, dataformat.get_assignment(False))
# delete file when assignment is deleted
assignment.active = False
assignment.clear_lti_links()
db.session.commit()
# update course grades
course.calculate_grades()
on_assignment_delete.send(
self,
event_name=on_assignment_delete.name,
user=current_user,
course_id=course.id,
assignment=assignment,
data=formatted_assignment)
return {'id': assignment.uuid}
示例7: post
def post(self, course_uuid, assignment_uuid, answer_uuid):
"""
Create comment for an answer
"""
course = Course.get_active_by_uuid_or_404(course_uuid)
assignment = Assignment.get_active_by_uuid_or_404(assignment_uuid)
answer = Answer.get_active_by_uuid_or_404(answer_uuid)
require(CREATE, AnswerComment(course_id=course.id))
answer_comment = AnswerComment(answer_id=answer.id)
params = new_answer_comment_parser.parse_args()
answer_comment.draft = params.get("draft")
answer_comment.content = params.get("content")
# require content not empty if not a draft
if not answer_comment.content and not answer_comment.draft:
return {"error": "The comment content is empty!"}, 400
if params.get("user_id") and current_user.system_role == SystemRole.sys_admin:
user = User.get_by_uuid_or_404(params.get("user_id"))
answer_comment.user_id = user.id
else:
answer_comment.user_id = current_user.id
comment_types = [
AnswerCommentType.public.value,
AnswerCommentType.private.value,
AnswerCommentType.evaluation.value,
AnswerCommentType.self_evaluation.value,
]
comment_type = params.get("comment_type")
if comment_type not in comment_types:
abort(400)
answer_comment.comment_type = AnswerCommentType(comment_type)
db.session.add(answer_comment)
db.session.commit()
# update course & assignment grade for user if self-evaluation is completed
if not answer_comment.draft and answer_comment.comment_type == AnswerCommentType.self_evaluation:
assignment.calculate_grade(answer_comment.user)
course.calculate_grade(answer_comment.user)
on_answer_comment_create.send(
self,
event_name=on_answer_comment_create.name,
user=current_user,
course_id=course.id,
answer_comment=answer_comment,
data=marshal(answer_comment, dataformat.get_answer_comment(False)),
)
return marshal(answer_comment, dataformat.get_answer_comment())
示例8: get
def get(self, course_uuid, assignment_uuid):
"""
Get answers submitted to the assignment submitted by current user
:param course_uuid:
:param assignment_uuid:
:return: answers
"""
course = Course.get_active_by_uuid_or_404(course_uuid)
assignment = Assignment.get_active_by_uuid_or_404(assignment_uuid)
require(READ, Answer(user_id=current_user.id),
title="Answers Unavailable",
message="Sorry, your role in this course does not allow you to view answers for this assignment.")
restrict_user = not allow(MANAGE, assignment)
params = user_answer_list_parser.parse_args()
query = Answer.query \
.options(joinedload('comments')) \
.options(joinedload('file')) \
.options(joinedload('user')) \
.options(joinedload('group')) \
.options(joinedload('score')) \
.filter_by(
active=True,
assignment_id=assignment.id,
course_id=course.id,
draft=params.get('draft')
)
# get group and individual answers for user if applicable
group = current_user.get_course_group(course.id)
if group:
query = query.filter(or_(
Answer.user_id == current_user.id,
Answer.group_id == group.id
))
# get just individual answers for user
else:
query = query.filter(Answer.user_id == current_user.id)
answers = query.all()
on_user_answer_get.send(
self,
event_name=on_user_answer_get.name,
user=current_user,
course_id=course.id,
data={'assignment_id': assignment.id})
return {"objects": marshal(answers, dataformat.get_answer(restrict_user))}
示例9: get
def get(self, course_uuid, assignment_uuid, assignment_comment_uuid):
course = Course.get_active_by_uuid_or_404(course_uuid)
assignment = Assignment.get_active_by_uuid_or_404(assignment_uuid)
assignment_comment = AssignmentComment.get_active_by_uuid_or_404(assignment_comment_uuid)
require(READ, assignment_comment)
on_assignment_comment_get.send(
self,
event_name=on_assignment_comment_get.name,
user=current_user,
course_id=course.id,
data={'assignment_id': assignment.id, 'assignment_comment_id': assignment_comment.id})
return marshal(assignment_comment, dataformat.get_assignment_comment())
示例10: get
def get(self, course_uuid, assignment_uuid, answer_uuid, answer_comment_uuid):
"""
Get an answer comment
"""
course = Course.get_active_by_uuid_or_404(course_uuid)
assignment = Assignment.get_active_by_uuid_or_404(assignment_uuid)
answer = Answer.get_active_by_uuid_or_404(answer_uuid)
answer_comment = AnswerComment.get_active_by_uuid_or_404(answer_comment_uuid)
require(READ, answer_comment)
on_answer_comment_get.send(
self,
event_name=on_answer_comment_get.name,
user=current_user,
course_id=course.id,
data={"assignment_id": assignment.id, "answer_id": answer.id, "answer_comment_id": answer_comment.id},
)
return marshal(answer_comment, dataformat.get_answer_comment())
示例11: get
def get(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)
require(READ, assignment,
title="Assignment Unavailable",
message="Assignments can be saved only by those enrolled in the course. Please double-check your enrollment in this course.")
now = datetime.datetime.utcnow()
if assignment.answer_start and not allow(MANAGE, assignment) and not (assignment.answer_start <= now):
abort(403, title="Assignment Unavailable", message="This assignment is not yet open to students. Please check back after the start date the instructor has set.")
restrict_user = not allow(MANAGE, assignment)
on_assignment_get.send(
self,
event_name=on_assignment_get.name,
user=current_user,
course_id=course.id,
data={'id': assignment.id})
return marshal(assignment, dataformat.get_assignment(restrict_user))
示例12: post
def post(self, course_uuid, assignment_uuid, comparison_example_uuid):
course = Course.get_active_by_uuid_or_404(course_uuid)
assignment = Assignment.get_active_by_uuid_or_404(assignment_uuid)
comparison_example = ComparisonExample.get_active_by_uuid_or_404(comparison_example_uuid)
require(EDIT, comparison_example,
title="Comparison Example Not Saved",
message="Sorry, your role in this course does not allow you to save practice answers.")
params = existing_comparison_example_parser.parse_args()
answer1_uuid = params.get("answer1_id")
answer2_uuid = params.get("answer2_id")
if answer1_uuid:
answer1 = Answer.get_active_by_uuid_or_404(answer1_uuid)
answer1.practice = True
comparison_example.answer1 = answer1
else:
abort(400, title="Comparison Example Not Saved",
message="Please add two answers with content to the practice answers and try again.")
if answer2_uuid:
answer2 = Answer.get_active_by_uuid_or_404(answer2_uuid)
answer2.practice = True
comparison_example.answer2 = answer2
else:
abort(400, title="Comparison Example Not Saved",
message="Please add two answers with content to the practice answers and try again.")
model_changes = get_model_changes(comparison_example)
db.session.add(comparison_example)
db.session.commit()
on_comparison_example_modified.send(
self,
event_name=on_comparison_example_modified.name,
user=current_user,
course_id=course.id,
data=model_changes)
return marshal(comparison_example, dataformat.get_comparison_example())
示例13: delete
def delete(self, course_uuid, assignment_uuid, comparison_example_uuid):
course = Course.get_active_by_uuid_or_404(course_uuid)
assignment = Assignment.get_active_by_uuid_or_404(assignment_uuid)
comparison_example = ComparisonExample.get_active_by_uuid_or_404(comparison_example_uuid)
require(DELETE, comparison_example,
title="Comparison Example Not Deleted",
message="Sorry, your role in this course does not allow you to delete practice answers.")
formatted_comparison_example = marshal(comparison_example,
dataformat.get_comparison_example(with_answers=False))
comparison_example.active = False
db.session.add(comparison_example)
db.session.commit()
on_comparison_example_delete.send(
self,
event_name=on_comparison_example_delete.name,
user=current_user,
course_id=course.id,
data=formatted_comparison_example)
return {'id': comparison_example.uuid}
示例14: get
def get(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)
require(READ, ComparisonExample(course_id=course.id),
title="Comparison Example Unavailable",
message="Sorry, your role in this course does not allow you to view practice answers.")
# Get all comparison examples for this assignment
comparison_examples = ComparisonExample.query \
.filter_by(
active=True,
assignment_id=assignment.id
) \
.all()
on_comparison_example_list_get.send(
self,
event_name=on_comparison_example_list_get.name,
user=current_user,
course_id=course.id,
data={'assignment_id': assignment.id})
return { "objects": marshal(comparison_examples, dataformat.get_comparison_example()) }