def upload(request): # The assumption here is that jQuery File Upload # has been configured to send files one at a time. # If multiple files can be uploaded simulatenously, # 'file' may be a list of files. issue = get_object_or_404(Issue, id=int(request.POST['issue_id'])) if 'update_issue' in request.POST: event_value = {'files':[], 'comment':'', 'compilers':[]} event_value['comment'] = request.POST['comment'] for field, value in dict(request.POST).iteritems(): if 'compiler' in field: pk = int(field[13:]) file = File.objects.get(pk = pk) compiler_id = value event_value['files'].append(file.file) event_value['compilers'].append(compiler_id) if 'pk' in field: pk = int(value[0]) file = File.objects.get(pk = pk) event_value['files'].append(file.file) event_value['compilers'].append(None) issue.set_byname('comment', event_value, request.user) return redirect(issue_page, issue_id=int(request.POST['issue_id'])) file = upload_receive(request) field = get_object_or_404(IssueField, name='file') event = Event.objects.create(issue_id=issue.id, field=field) problem_compilers = [] chosen_compiler = None send_to_contest = False if issue.task.course.contest_integrated: problem_compilers = get_problem_compilers(issue.task.problem_id, issue.task.contest_id) for ext in settings.CONTEST_EXTENSIONS: filename, extension = os.path.splitext(file.name) if ext == extension: send_to_contest = True if not problem_compilers: chosen_compiler = settings.CONTEST_EXTENSIONS[ext] if settings.CONTEST_EXTENSIONS[ext] in problem_compilers: chosen_compiler = settings.CONTEST_EXTENSIONS[ext] problem_compilers.remove(chosen_compiler) file.name = unidecode(file.name) instance = File(file=file, event=event) instance.save() basename = instance.filename() file_dict = { 'name' : basename, 'size' : file.size, 'url': instance.file.url, 'thumbnailUrl': instance.file.url, 'delete_url': reverse('jfu_delete', kwargs = { 'pk': instance.pk }), 'delete_type': 'POST', 'problem_compilers': problem_compilers, 'chosen_compiler' : chosen_compiler, 'pk': instance.pk, 'send_to_contest': send_to_contest, } return UploadResponse(request, file_dict)
def handle(self, *args, **options): start_time = time.time() if len(args) == 0: print "Specify file name" return with open(args[0], 'r') as f: issues_ids = set(f.read().splitlines()) issues = Issue.objects.filter(id__in=issues_ids) issues_ids_used = set() problem_compilers_used = {} message = "Log\n" for issue in issues: contest_id = issue.task.contest_id problem_id = issue.task.problem_id if not issue.task.contest_integrated or not contest_id or not problem_id: message += write_message(issue.id, "No contest settings in task") continue if issue.contestsubmission_set.exists(): message += write_message(issue.id, "Already have contest submissions") continue old_event = issue.event_set.filter(field__name='file').exclude( file__isnull=True).order_by("-timestamp") if len(old_event) == 0: message += write_message(issue.id, "No file submissions in issue") continue old_event = old_event[0] file = old_event.file_set.all()[0] problem_compilers_key = (problem_id, contest_id) if problem_compilers_key in problem_compilers_used: problem_compilers = get_problem_compilers( issue.task.problem_id, issue.task.contest_id) else: problem_compilers = get_problem_compilers( issue.task.problem_id, issue.task.contest_id) problem_compilers_used[ problem_compilers_key] = problem_compilers chosen_compiler = get_compiler(file.file.name, problem_compilers) if not chosen_compiler: message += write_message(issue.id, "Can't determinate compiler") continue event_value = {'files': [], 'comment': '', 'compilers': []} event_value['files'].append(file.file) event_value['compilers'].append(chosen_compiler) translation.activate(issue.student.get_profile().language) issue.set_byname('comment', event_value, issue.student) translation.deactivate() issues_ids_used.add(str(issue.id)) message += write_message(issue.id, "Completed!") message += "Fixed: {0}/{1}\nNot fixed issues: {2}\nTime: {3}".format( len(issues_ids_used), len(issues_ids), ", ".join(issues_ids - issues_ids_used), time.time() - start_time) print message
def upload(request): # The assumption here is that jQuery File Upload # has been configured to send files one at a time. # If multiple files can be uploaded simulatenously, # 'file' may be a list of files. issue = get_object_or_404(Issue, id=int(request.POST['issue_id'])) if 'update_issue' in request.POST: event_value = {'files': [], 'comment': '', 'compilers': []} event_value['comment'] = request.POST['comment'] file_counter = 0 for field, value in dict(request.POST).iteritems(): if 'compiler' in field: pk = int(field[13:]) file = File.objects.get(pk=pk) compiler_id = value event_value['files'].append(file.file) event_value['compilers'].append(compiler_id) if 'pk' in field: pk = int(value[0]) file = File.objects.get(pk=pk) file_counter += 1 event_value['files'].append(file.file) event_value['compilers'].append(None) if not (issue.task.one_file_upload and file_counter > 1): event = issue.set_byname('comment', event_value, request.user) if not (issue.task.course.easyCI is None or issue.task.course.easyCI == ''): print(issue.task.course.easyCI) files = [] for sent_file in event_value['files']: print(request.build_absolute_uri(sent_file.url)) files.append(request.build_absolute_uri(sent_file.url)) if len(files) != 0: check_request_dict = { 'files': files, 'course_id': issue.task.course_id, 'title': issue.task.get_title(), 'issue_id': issue.id, 'event': { 'id': event.id, 'timestamp': event.timestamp.isoformat() } } requests.post(issue.task.course.easyCI + "/api/add_task", json=check_request_dict) return redirect(issue_page, issue_id=int(request.POST['issue_id'])) file = upload_receive(request) field = get_object_or_404(IssueField, name='file') event = Event.objects.create(issue_id=issue.id, field=field) problem_compilers = [] chosen_compiler = None send_to_contest = False if issue.task.contest_integrated: problem_compilers = get_problem_compilers(issue.task.problem_id, issue.task.contest_id) for ext in settings.CONTEST_EXTENSIONS: filename, extension = os.path.splitext(file.name) if ext == extension: send_to_contest = True if not problem_compilers: chosen_compiler = settings.CONTEST_EXTENSIONS[ext] if settings.CONTEST_EXTENSIONS[ext] in problem_compilers: chosen_compiler = settings.CONTEST_EXTENSIONS[ext] problem_compilers.remove(chosen_compiler) one_file_upload = False if issue.task.one_file_upload: filename, extension = os.path.splitext(file.name) file.name = 'upload' + extension one_file_upload = True else: file.name = unidecode(file.name) instance = File(file=file, event=event) instance.save() basename = instance.filename() file_dict = { 'name': basename, 'size': file.size, 'url': instance.file.url, 'thumbnailUrl': instance.file.url, 'delete_url': reverse('jfu_delete', kwargs={'pk': instance.pk}), 'delete_type': 'POST', 'problem_compilers': problem_compilers, 'chosen_compiler': chosen_compiler, 'pk': instance.pk, 'send_to_contest': send_to_contest, 'one_file_upload': one_file_upload, } return UploadResponse(request, file_dict)
def handle(self, *args, **options): start_time = time.time() if len(args) == 0: print "Specify file name" return with open(args[0], 'r') as f: issues_ids = set(f.read().splitlines()) issues = Issue.objects.filter(id__in=issues_ids) issues_ids_used = set() problem_compilers_used = {} message = "Log\n" for issue in issues: contest_id = issue.task.contest_id problem_id = issue.task.problem_id if not issue.task.contest_integrated or not contest_id or not problem_id: message += write_message(issue.id, "No contest settings in task") continue if issue.contestsubmission_set.exists(): message += write_message(issue.id, "Already have contest submissions") continue old_event = issue.event_set.filter(field__name='file').exclude(file__isnull=True).order_by("-timestamp") if len(old_event) == 0: message += write_message(issue.id, "No file submissions in issue") continue old_event = old_event[0] file = old_event.file_set.all()[0] problem_compilers_key = (problem_id, contest_id) if problem_compilers_key in problem_compilers_used: problem_compilers = get_problem_compilers(issue.task.problem_id, issue.task.contest_id) else: problem_compilers = get_problem_compilers(issue.task.problem_id, issue.task.contest_id) problem_compilers_used[problem_compilers_key] = problem_compilers chosen_compiler = get_compiler(file.file.name, problem_compilers) if not chosen_compiler: message += write_message(issue.id, "Can't determinate compiler") continue event_value = {'files': [], 'comment': '', 'compilers': []} event_value['files'].append(file.file) event_value['compilers'].append(chosen_compiler) translation.activate(issue.student.get_profile().language) issue.set_byname('comment', event_value, issue.student) translation.deactivate() issues_ids_used.add(str(issue.id)) message += write_message(issue.id, "Completed!") message += "Fixed: {0}/{1}\nNot fixed issues: {2}\nTime: {3}".format( len(issues_ids_used), len(issues_ids), ", ".join(issues_ids - issues_ids_used), time.time() - start_time ) print message