<commit_before>class ScriptedController < ApplicationController
  skip_before_filter  :authorize, :verify_authenticity_token
  def referral_report
    response.headers["Content-Type"]        = "text/csv; charset=UTF-8; header=present"
    response.headers["Content-Disposition"] = "attachment; filename=referrals.csv"

    send_data(ReferralReport.csv(current_district),
       :type => 'text/csv; charset=utf-8; header=present',
       :filename => "referrals.csv"
       )
  end

  def district_export
    send_file(DistrictExport.generate(current_district), :x_sendfile => true, :filename => 'sims_export.zip')
  end

  def district_upload
    if request.post?
      DistrictUploadJob.new.async_perform params[:upload_file], current_district, @u.email
      render :text=> ''
    end
      render :layout=>false
  end

  def automated_intervention
    if request.post?
      Spawnling.new(:method => :yield) do
        importer=AutomatedIntervention.new params[:upload_file], @u
        @messages=importer.import
        Notifications.district_upload_results( @messages, @u.email || '<EMAIL>').deliver
      end
        render :text=>"response will be emailed to #{@u.email}" and return
    end
    render :layout=>false
  end


protected
  def authenticate_user!
    authenticate_or_request_with_http_basic do |username, password|
      username == params[:action] && @u=current_district.users.find_by_username(username) and @u.try(:valid_password?,password)
    end
  end

  def current_district<commit_msg>fix double render<commit_after>class ScriptedController < ApplicationController
  skip_before_filter  :authorize, :verify_authenticity_token
  def referral_report
    response.headers["Content-Type"]        = "text/csv; charset=UTF-8; header=present"
    response.headers["Content-Disposition"] = "attachment; filename=referrals.csv"

    send_data(ReferralReport.csv(current_district),
       :type => 'text/csv; charset=utf-8; header=present',
       :filename => "referrals.csv"
       )
  end

  def district_export
    send_file(DistrictExport.generate(current_district), :x_sendfile => true, :filename => 'sims_export.zip')
  end

  def district_upload
    if request.post?
      DistrictUploadJob.new.async_perform params[:upload_file], current_district, @u.email
      render :text=> ''
    else
      render :layout=>false
    end
  end

  def automated_intervention
    if request.post?
      Spawnling.new(:method => :yield) do
        importer=AutomatedIntervention.new params[:upload_file], @u
        @messages=importer.import
        Notifications.district_upload_results( @messages, @u.email || '<EMAIL>').deliver
      end
        render :text=>"response will be emailed to #{@u.email}" and return
    end
    render :layout=>false
  end


protected
  def authenticate_user!
    authenticate_or_request_with_http_basic do |username, password|
      username == params[:action] && @u=current_district.users.find_by_username(username) and @u.try(:valid_password?,password)
    end
  end

  def current_district
{'fraction_non_alphanumeric': 0.10734277247283504, 'fraction_numerical': 0.0013170892327955218, 'mean_word_length': 3.9640522875816995, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 23, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3383910', 'n_tokens_mistral': 938, 'n_tokens_neox': 889, 'n_words': 182}