<commit_before>class ExamTemplatesController < ApplicationController

  before_filter      :authorize_only_for_admin

  layout 'assignment_content'

  def index
    @assignment = Assignment.find(params[:assignment_id])
    @exam_templates = ExamTemplate.find_by(assignment: @assignment)
  end

  def download
    assignment = Assignment.find(params[:assignment_id])
    exam_template = ExamTemplate.find_by(assignment: assignment, id: params[:id]) # look up a specific exam template based on the params[:id]
    filename = exam_template.filename
    basename = File.basename(filename, ".pdf")
    send_file("#{EXAM_TEMPLATE_DIR}/#{basename}/#{filename}",
              filename: "#{filename}",
              type: "application/pdf")
  end

  def update
    new_uploaded_io = params[:new_template]
    # error checking when new_uploaded_io is not pdf
    if new_uploaded_io.content_type != 'application/pdf'
      flash_message(:failure, 'Exam Template should be in pdf format')
      redirect_to action: 'index'
    else
      assignment = Assignment.find(params[:assignment_id])
      old_exam_template = ExamTemplate.find_by(assignment: assignment, id: params[:id])
      old_template_filename = old_exam_template.filename
      ExamTemplate.create_with_file(new_uploaded_io.read, assignment_id: assignment.id, filename: old_template_filename)
      flash_message(:success, 'Exam Template has been successfully uploaded')
      redirect_to action: 'index'
    end
  end
end<commit_msg>fixed parsing error for pdf<commit_after>class ExamTemplatesController < ApplicationController

  before_filter      :authorize_only_for_admin

  layout 'assignment_content'

  def index
    @assignment = Assignment.find(params[:assignment_id])
    @exam_templates = ExamTemplate.find_by(assignment: @assignment)
  end

  def download
    assignment = Assignment.find(params[:assignment_id])
    exam_template = ExamTemplate.find_by(assignment: assignment, id: params[:id]) # look up a specific exam template based on the params[:id]
    filename = exam_template.filename
    basename = File.basename(filename, ".pdf")
    send_file("#{EXAM_TEMPLATE_DIR}/#{basename}/#{filename}",
              filename: "#{filename}",
              type: "application/pdf")
  end

  def update
    new_uploaded_io = params[:new_template]
    # error checking when new_uploaded_io is not pdf
    if new_uploaded_io.content_type != 'application/pdf'
      flash_message(:failure, 'Exam Template should be in pdf format')
      redirect_to action: 'index'
      return
    end
    assignment = Assignment.find(params[:assignment_id])
    old_exam_template = ExamTemplate.find_by(assignment: assignment, id: params[:id])
    old_template_filename = old_exam_template.filename
    ExamTemplate.create_with_file(new_uploaded_io.read, assignment_id: assignment.id, filename: old_template_filename)
    flash_message(:success, 'Exam Template has been successfully uploaded')
    redirect_to action: 'index'
  end
end
{'fraction_non_alphanumeric': 0.09194630872483221, 'fraction_numerical': 0.0, 'mean_word_length': 4.390596745027125, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5991054', 'n_tokens_mistral': 880, 'n_tokens_neox': 876, 'n_words': 199}