def submit_review(filecontent, filename, task, user, points, comment="", submit=None): if filecontent is None and submit is None: raise ValidationError(_("You should upload a file or specify parent submit.")) if filecontent is not None: submit_id = str(int(time())) sfiletarget = os.path.join( get_path(task, user), "%s-%s-%s" % (user.last_name, submit_id, filename) ) sfiletarget = unidecode(sfiletarget) if hasattr(filecontent, "chunks"): write_chunks_to_file(sfiletarget, filecontent.chunks()) else: write_chunks_to_file(sfiletarget, [filecontent]) else: sfiletarget = submit.filepath sub = Submit( task=task, user=user, points=points, submit_type=submit_constants.SUBMIT_TYPE_DESCRIPTION, testing_status=submit_constants.SUBMIT_STATUS_REVIEWED, filepath=sfiletarget, reviewer_comment=comment, ) sub.save()
def update_points(user): points = UserLevel.objects.filter(user=user.id, solved=True).count() * 1.5 submit = Submit( task=get_task(), user=user, points=points, submit_type=SUBMIT_TYPE_EXTERNAL, testing_status="OK", ) submit.save()
def update_points(user): points = UserLevel.objects.filter(user=user.id, solved=True).count() submit = Submit( task=get_task(), user=user, points=points, submit_type=SUBMIT_TYPE_EXTERNAL, filepath="", testing_status="OK", tester_response="", protocol_id="", ) submit.save()
def update_points(user): aggr = UserCategory.objects.filter(user=user).aggregate(sum=Sum("points")) submit = Submit( task=Task.objects.get(pk=TASK_ID), user=user, points=aggr["sum"], submit_type=SUBMIT_TYPE_EXTERNAL, filepath="", testing_status=SUBMIT_STATUS_FINISHED, tester_response=SUBMIT_RESPONSE_OK, protocol_id="", ) submit.save()
def process_submit(uid, sid, lid, l_submit_id, taskpoints, program, level_path): user = User.objects.get(pk=uid) level_submit = LevelSubmit.objects.get(pk=l_submit_id) with open(os.path.join(DATA_ROOT, level_path)) as f: level = json.load(f) test_script = os.path.join(DATA_ROOT, 'tester.sh') data = json.dumps({'program': program, 'level': level}) p = Popen(['/usr/bin/env', 'bash', test_script], stdin=PIPE, stdout=PIPE) p.communicate(data) if p.returncode == 0: from .views import load_level_index index_data = load_level_index() level_submit.status = 'OK' LevelSolved.objects.get_or_create(user=user, series=sid, level=lid) for (task_id, _) in taskpoints: # Look if there are another series with same task_id and sum points points = 0 _sid = 0 for serie in index_data['series']: for (other_task_id, multiple) in serie['taskpoints']: if task_id == other_task_id: points += multiple * LevelSolved.objects.filter( user=user, series=_sid).count() _sid += 1 submit = Submit( task=Task.objects.get(pk=task_id), user=user, points=points, submit_type=SUBMIT_TYPE_EXTERNAL, filepath='', testing_status=SUBMIT_STATUS_FINISHED, tester_response=SUBMIT_RESPONSE_OK, protocol_id='', ) submit.save() else: level_submit.status = 'WA' level_submit.save()
def update_points(user): uls = UserLevel.objects.filter(user=user.id) points = 0 for ul in uls: points += {1: 2, 2: 3, 3: 4, 4: 6}.get(ul.level, 0) submit = Submit( task=get_task(), user=user, points=points, submit_type=SUBMIT_TYPE_EXTERNAL, filepath="", testing_status="OK", tester_response="", protocol_id="", ) submit.save()
def task_view(request): task = get_object_or_404(Task, pk=TASK_ID) if not task.visible(request.user): raise Http404 best_points = Submit.objects.filter( user=request.user, task=task).aggregate(Max("points"))["points__max"] if best_points is None: best_points = 0 if request.method == "POST": form = SubmitForm(request.POST) if form.is_valid(): queries = request.session.get("plugin_prask_2_4_1/questions", list()) selection = form.cleaned_data["selection"] points, message = process_answer(queries, selection) if points: if points > best_points: submit = Submit( task=task, user=request.user, points=points, submit_type=SUBMIT_TYPE_EXTERNAL, filepath="", testing_status="OK", tester_response="", protocol_id="", ) submit.save() request.session["plugin_prask_2_4_1/last_points"] = points messages.add_message( request, messages.SUCCESS if points else messages.ERROR, message) return redirect(reverse("plugin_prask_2_4_1:task_view")) else: form = SubmitForm() context = dict( task=task, form=form, last_points=request.session.get("plugin_prask_2_4_1/last_points", 0), best_points=int(best_points), ) return render(request, "plugin_prask_2_4_1/task_view.html", context=context)