<commit_before>Tiralabomba::Admin.controllers :posts do
  get :index do
    @title = "Posts"
    @posts = Post.all(:order => :created_at.desc)
    render 'posts/index'
  end

  get :new do
    @title = pat(:new_title, :model => 'post')
    @post = Post.new
    render 'posts/new'
  end

  post :create do
    @post = Post.new(params[:post])
    @post = Post.load_from_tweet(@post.tweet_id) unless @post.tweet_id.nil?
    
    if @post.save
      @title = pat(:create_title, :model => "post #{@post.id}")
      flash[:success] = pat(:create_success, :model => 'Post')
      params[:save_and_continue] ? redirect(url(:posts, :index)) : redirect(url(:posts, :edit, :id => @post.id))
    else
      @title = pat(:create_title, :model => 'post')
      flash.now[:error] = pat(:create_error, :model => 'post')
      render 'posts/new'
    end
  end

  get :edit, :with => :id do
    @title = pat(:edit_title, :model => "post #{params[:id]}")
    @post = Post.find(params[:id])
    if @post
      render 'posts/edit'
    else
      flash[:warning] = pat(:create_error, :model => 'post', :id => "#{params[:id]}")
      halt 404
    end
  end

  put :update, :with => :id do
    @title = pat(:update_title, :model => "post #{params[:id]}")
    @post = Post.find(params[:id])
    if @post
      @post.set_categories(params[:post][:categories_in_short_name])
      if @post.update_attributes(params[:post])
        flash[:success] = pat(:update_success, :model => 'Post', :id =>  "#{params[:id]}")
        params[:save_and_continue] ?
          redirect(url(:posts, :index)) :
          redirect(url(:posts, :edit, :id => @post.id))
      else
        flash.now[:error] = pat(:update_error, :model => 'post')
        render 'posts/edit'
      end
    else
      flash[:warning] = pat(:update_warning, :model => 'post', :id => "#{params[:id]}")
      halt 404
    end
  end

  post :publish, :with => :id do
    @title = "Publicao"
    post = Post.find(params[:id])
    if post
      if post.publish
        flash[:success] = pat(:publish_success, :model => 'Post', :id => "#{params[:id]}")
      else
        flash[:error] = pat(:publish_error, :model => 'post')
      end
      redirect url(:posts, :index)
    else
      flash[:warning] = pat(:publish_warning, :model => 'post', :id => "#{params[:id]}")
      halt 404
    end
  end

  post :publish_many, :csrf_protection => false do
    @title = "Publicaos"
    unless params[:post_ids]
      flash[:error] = pat(:publish_many_error, :model => 'post')
      redirect(url(:posts, :index))<commit_msg>ammend<commit_after>Tiralabomba::Admin.controllers :posts do
  get :index do
    @title = "Posts"
    @posts = Post.all(:order => :created_at.desc)
    render 'posts/index'
  end

  get :new do
    @title = pat(:new_title, :model => 'post')
    @post = Post.new
    render 'posts/new'
  end

  post :create do
    @post = Post.new(params[:post])
    @post = Post.load_from_tweet(@post.tweet_id) unless @post.tweet_id.nil?
    
    if @post.save
      @title = pat(:create_title, :model => "post #{@post.id}")
      flash[:success] = pat(:create_success, :model => 'Post')
      params[:save_and_continue] ? redirect(url(:posts, :index)) : redirect(url(:posts, :edit, :id => @post.id))
    else
      @title = pat(:create_title, :model => 'post')
      flash.now[:error] = pat(:create_error, :model => 'post')
      render 'posts/new'
    end
  end

  get :edit, :with => :id do
    @title = pat(:edit_title, :model => "post #{params[:id]}")
    @post = Post.find(params[:id])
    if @post
      render 'posts/edit'
    else
      flash[:warning] = pat(:create_error, :model => 'post', :id => "#{params[:id]}")
      halt 404
    end
  end

  put :update, :with => :id do
    @title = pat(:update_title, :model => "post #{params[:id]}")
    @post = Post.find(params[:id])
    if @post
      @post.set_categories(params[:post][:categories_in_short_name])
      if @post.update_attributes(params[:post])
        flash[:success] = pat(:update_success, :model => 'Post', :id =>  "#{params[:id]}")
        params[:save_and_continue] ?
          redirect(url(:posts, :index)) :
          redirect(url(:posts, :edit, :id => @post.id))
      else
        flash.now[:error] = pat(:update_error, :model => 'post')
        render 'posts/edit'
      end
    else
      flash[:warning] = pat(:update_warning, :model => 'post', :id => "#{params[:id]}")
      halt 404
    end
  end

  post :publish, :with => :id do
    @title = "Publicao"
    post = Post.find(params[:id])
    if post
      if post.publish
        flash[:success] = pat(:publish_success, :model => 'Post', :id => "#{params[:id]}")
      else
        flash[:error] = pat(:publish_error, :model => 'post')
      end
      redirect url(:posts, :index)
    else
      flash[:warning] = pat(:publish_warning, :model => 'post', :id => "#{params[:id]}")
      halt 404
    end
  end

  post :publish_many do
    @title = "Publicaos"
    unless params[:post_ids]
      flash[:error] = pat(:publish_many_error, :model => 'post')
      redirect(url(:posts, :index))
{'fraction_non_alphanumeric': 0.18376237623762376, 'fraction_numerical': 0.0035643564356435645, 'mean_word_length': 2.9960443037974684, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 56, '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': '3712646', 'n_tokens_mistral': 1737, 'n_tokens_neox': 1707, 'n_words': 389}