本文整理汇总了Python中tasks.models.Task.set_position_in_new_group方法的典型用法代码示例。如果您正苦于以下问题:Python Task.set_position_in_new_group方法的具体用法?Python Task.set_position_in_new_group怎么用?Python Task.set_position_in_new_group使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类tasks.models.Task
的用法示例。
在下文中一共展示了Task.set_position_in_new_group方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: contest_task_import
# 需要导入模块: from tasks.models import Task [as 别名]
# 或者: from tasks.models.Task import set_position_in_new_group [as 别名]
def contest_task_import(request):
if not request.method == 'POST':
return HttpResponseForbidden()
course_id = int(request.POST['course_id'])
course = get_object_or_404(Course, id=course_id)
contest_id = int(request.POST['contest_id_for_task'])
tasks = []
common_params = get_task_params(request, course.issue_status_system.has_accepted_after_deadline())
got_info, contest_info = get_contest_info(contest_id)
problem_req = requests.get(PROBLEMS_API.format(lang='ru', cont_id=str(contest_id)),
headers=HEADERS)
problems = []
if 'result' in problem_req.json():
problems = problem_req.json()['result']['problems']
problems_with_score = {problem['id']: problem.get('score') for problem in problems}
if got_info:
if problems:
sort_order = [problem['id'] for problem in problems]
contest_info['problems'].sort(key=lambda x: sort_order.index(x['problemId']))
contest_problems = dict(request.POST)['contest_problems[]']
for problem in contest_info['problems']:
if problem['problemId'] in contest_problems:
current_params = common_params['attrs'].copy()
current_params.update({
'title': problem['problemTitle'],
'task_text': problem['statement'],
'short_title': current_params['short_title'] or problem['alias'],
'contest_integrated': True,
'contest_id': contest_id,
'problem_id': problem['alias']
})
if not current_params['score_max'] and problems_with_score:
current_params['score_max'] = problems_with_score[problem['problemId']] or 0
if not current_params['deadline_time'] and 'endTime' in contest_info:
current_params['deadline_time'] = make_aware(
datetime.datetime.strptime(contest_info['endTime'][:-12], '%Y-%m-%dT%H:%M'),
timezone(settings.CONTEST_TIME_ZONE)
)
tasks.append(current_params)
elif "You're not allowed to view this contest." in contest_info:
return HttpResponse(json.dumps({'is_error': True,
'error': _(u"net_prav_na_kontest")}),
content_type="application/json")
else:
return HttpResponseForbidden()
if not course.user_can_edit_course(request.user):
return HttpResponseForbidden()
for task in tasks:
real_task = Task()
real_task.course = course
for attr_name, attr_value in task.items():
setattr(real_task, attr_name, attr_value)
real_task.save()
task_groups = common_params['groups']
real_task.groups = task_groups
real_task.set_position_in_new_group(task_groups)
reversion.set_user(request.user)
reversion.set_comment("Import task")
return HttpResponse("OK")
示例2: task_create_or_edit
# 需要导入模块: from tasks.models import Task [as 别名]
# 或者: from tasks.models.Task import set_position_in_new_group [as 别名]
def task_create_or_edit(request, course, task_id=None):
params = get_task_params(request, course.issue_status_system.has_accepted_after_deadline())
lang = request.user.get_profile().language
changed_score_after_deadline = False
if task_id:
task = get_object_or_404(Task, id=task_id)
task_text = task.is_text_json()
if task_text:
task_title = json.loads(task.title, strict=False)
task_title[lang] = params['attrs']['title']
task_text[lang] = params['attrs']['task_text']
params['attrs']['title'] = json.dumps(task_title, ensure_ascii=False)
params['attrs']['task_text'] = json.dumps(task_text, ensure_ascii=False)
changed_score_after_deadline = task.score_after_deadline != params['attrs']['score_after_deadline']
params['attrs']['nb_assignment_name'] = task.nb_assignment_name
else:
task = Task()
task.course = course
for attr_name, attr_value in params['attrs'].items():
setattr(task, attr_name, attr_value)
if task.parent_task:
if task.parent_task.is_hidden:
task.is_hidden = True
task.save()
for subtask in Task.objects.filter(parent_task=task):
subtask.is_hidden = task.is_hidden
subtask.save()
children = params['children']
for course_task in Task.objects.filter(course=course):
if children and course_task.id in map(int, children):
course_task.parent_task = task
course_task.save()
elif course_task.parent_task == task:
course_task.parent_task = None
course_task.save()
task_groups = params['groups']
task.groups = task_groups
task.set_position_in_new_group(task_groups)
if task_id and changed_score_after_deadline and task.parent_task:
student_ids = User.objects.filter(group__in=task_groups).values_list('id', flat=True)
for student_id in student_ids:
parent_issue, created = Issue.objects.get_or_create(task_id=task.parent_task.id, student_id=student_id)
total_mark = Issue.objects \
.filter(task=task, student_id=student_id) \
.exclude(task__is_hiddne=True) \
.exclude(
task__score_after_deadline=False,
status_field__tag=IssueStatus.STATUS_ACCEPTED_AFTER_DEADLINE) \
.aggregate(Sum('mark'))['mark__sum'] or 0
if task.score_after_deadline:
parent_issue.mark += total_mark
else:
parent_issue.mark -= total_mark
parent_issue.set_status_seminar()
if task.type == task.TYPE_SEMINAR:
student_ids = User.objects.filter(group__in=task_groups).values_list('id', flat=True)
for student_id in student_ids:
issue, created = Issue.objects.get_or_create(task_id=task.id, student_id=student_id)
issue.mark = Issue.objects \
.filter(task__parent_task=task, student_id=student_id) \
.exclude(task__is_hidden=True) \
.exclude(
task__score_after_deadline=False,
status_field__tag=IssueStatus.STATUS_ACCEPTED_AFTER_DEADLINE) \
.aggregate(Sum('mark'))['mark__sum'] or 0
issue.set_status_seminar()
task.save()
reversion.set_user(request.user)
if task_id:
reversion.set_comment("Edit task")
else:
reversion.set_comment("Create task")
return HttpResponse(json.dumps({'page_title': task.get_title(lang) + ' | ' + course.name + ' | ' + str(course.year),
'redirect_page': '/task/edit/' + str(task.id) if not task_id else None}),
content_type="application/json")