<commit_before>class Portal::TeachersController < ApplicationController
  include RestrictedPortalController
  public
  
  # GET /portal_teachers
  # GET /portal_teachers.xml
  def index
    @portal_teachers = Portal::Teacher.all

    respond_to do |format|
      format.html # index.html.erb
      format.xml  { render :xml => @portal_teachers }
    end
  end

  # GET /portal_teachers/1
  # GET /portal_teachers/1.xml
  def show
    @portal_teacher = Portal::Teacher.find(params[:id])
    respond_to do |format|
      format.html # show.html.erb
      format.xml  { render :xml => @portal_teacher }
    end
  end

  # GET /portal_teachers/new
  # GET /portal_teachers/new.xml
  def new
    @portal_teacher = Portal::Teacher.new
    # order @portal_districts so the virtual districts appear first in the list of Districts and Schools
    domains_and_grades
    respond_to do |format|
      format.html # new.html.erb
      format.xml  { render :xml => @portal_teacher }
    end
  end

  # GET /portal_teachers/1/edit
  def edit
    @portal_teacher = Portal::Teacher.find(params[:id])
    @user = @portal_teacher.user
  end

  # POST /portal_teachers
  # POST /portal_teachers.xml
  def create
    if params[:school][:id]
      @portal_school = Portal::School.find(params[:school][:id])
    else
      @portal_school = Portal::School.find_by_name(APP_CONFIG[:site_school])
    end
    @portal_grade = Portal::Grade.find(params[:grade][:id])
    @domain = RiGse::Domain.find(params[:domain][:id])
    domains_and_grades
    @user = User.new(params[:user])
    if @user && @user.valid?
      @user.register!
      @user.save
    end
    
    @portal_teacher = Portal::Teacher.new do |t|
      t.user = @user
      t.domain = @domain
      t.schools << @portal_school
      t.grades << @portal_grade
    end
    
    if @user.errors.empty? && @portal_teacher.save
      # will redirect:
      successful_creation(@user)    
    else 
      # will redirect:
      failed_creation
    end
    
  end

  # PUT /portal_teachers/1
  # PUT /portal_teachers/1.xml
  def update<commit_msg>Quick fix for demo: fix missing gse in form<commit_after>class Portal::TeachersController < ApplicationController
  include RestrictedPortalController
  public
  
  # GET /portal_teachers
  # GET /portal_teachers.xml
  def index
    @portal_teachers = Portal::Teacher.all

    respond_to do |format|
      format.html # index.html.erb
      format.xml  { render :xml => @portal_teachers }
    end
  end

  # GET /portal_teachers/1
  # GET /portal_teachers/1.xml
  def show
    @portal_teacher = Portal::Teacher.find(params[:id])
    respond_to do |format|
      format.html # show.html.erb
      format.xml  { render :xml => @portal_teacher }
    end
  end

  # GET /portal_teachers/new
  # GET /portal_teachers/new.xml
  def new
    @portal_teacher = Portal::Teacher.new
    # order @portal_districts so the virtual districts appear first in the list of Districts and Schools
    domains_and_grades
    respond_to do |format|
      format.html # new.html.erb
      format.xml  { render :xml => @portal_teacher }
    end
  end

  # GET /portal_teachers/1/edit
  def edit
    @portal_teacher = Portal::Teacher.find(params[:id])
    @user = @portal_teacher.user
  end

  # POST /portal_teachers
  # POST /portal_teachers.xml
  def create
    if params[:school][:id]
      @portal_school = Portal::School.find(params[:school][:id])
    else
      @portal_school = Portal::School.find_by_name(APP_CONFIG[:site_school])
    end
    @portal_grade = Portal::Grade.find(params[:grade][:id])
    @domain = nil
    if params[:domain]
      @domain = RiGse::Domain.find(params[:domain][:id])
    end
    domains_and_grades
    @user = User.new(params[:user])
    if @user && @user.valid?
      @user.register!
      @user.save
    end
    
    @portal_teacher = Portal::Teacher.new do |t|
      t.user = @user
      t.domain = @domain
      t.schools << @portal_school
      t.grades << @portal_grade
    end
    
    if @user.errors.empty? && @portal_teacher.save
      # will redirect:
      successful_creation(@user)    
    else 
      # will redirect:
      failed_creation
    end
    
  end

  # PUT /portal_teachers/1
  # PUT /portal_teachers/1.xml
  def update
{'fraction_non_alphanumeric': 0.1080953504838329, 'fraction_numerical': 0.002360160490913382, 'mean_word_length': 2.807726864330638, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 22}, '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': '3008234', 'n_tokens_mistral': 1451, 'n_tokens_neox': 1460, 'n_words': 304}