<commit_before>require 'net/http'
require 'uri'

class PlaylistsController < BaseController

  include PlaylistUtilities

  before_filter :playlist_admin_preload, :except => [:embedded_pager, :metadata]
  before_filter :load_playlist, :except => [:metadata, :embedded_pager, :index, :destroy]
  before_filter :require_user, :except => [:metadata, :embedded_pager, :show, :index]
  before_filter :list_tags, :only => [:index, :show, :edit]
  
  access_control do
    allow all, :to => [:embedded_pager, :show, :index]
    allow logged_in, :to => [:new, :create, :copy, :spawn_copy]
    allow :admin, :playlist_admin, :superadmin
    allow :owner, :of => :playlist
    allow :editor, :of => :playlist, :to => [:edit, :update]
    #    allow :user, :of => :playlist, :to => [:index, :show]
  end

  def embedded_pager
    super Playlist
  end

  def list_tags
    @playlist_tags = Tag.all #really slow: Playlist.all.collect { |p| p.tags }.flatten.uniq
  end

  # GET /playlists
  # GET /playlists.xml
  def index
    @playlists = Sunspot.new_search(Playlist)

	if !params.has_key?(:sort)
	  params[:sort] = "display_name"
	end

    sort_base_url = ''
	@playlists.build do
	  if params.has_key?(:keywords)
	    keywords params[:keywords]
        sort_base_url += "&keywords=#{params[:keywords]}"
	  end
	  if params.has_key?(:tag)
	    with :tags, params[:tag]
	  end
	  with :public, true
	  paginate :page => params[:page], :per_page => cookies[:per_page] || nil
	  order_by params[:sort].to_sym, :asc
	end

	@playlists.execute!

    generate_sort_list("/playlists?#{sort_base_url}", {"display_name" => "DISPLAY NAME", "created_at" => "BY DATE"})

    # TODO: Update this to be linked through user / foreign key
    @my_bookmarks = current_user && !current_user.bookmark_id.nil? ? Playlist.find(current_user.bookmark_id): nil

    # TODO: Update this to exclude my bookmark
    @my_playlists = current_user ? current_user.playlists : []

    
    respond_to do |format|
      format.html # index.html.erb
      format.xml  { render :xml => @playlists }<commit_msg>Excluding bookmark playlist from my playlists.<commit_after>require 'net/http'
require 'uri'

class PlaylistsController < BaseController

  include PlaylistUtilities

  before_filter :playlist_admin_preload, :except => [:embedded_pager, :metadata]
  before_filter :load_playlist, :except => [:metadata, :embedded_pager, :index, :destroy]
  before_filter :require_user, :except => [:metadata, :embedded_pager, :show, :index]
  before_filter :list_tags, :only => [:index, :show, :edit]
  
  access_control do
    allow all, :to => [:embedded_pager, :show, :index]
    allow logged_in, :to => [:new, :create, :copy, :spawn_copy]
    allow :admin, :playlist_admin, :superadmin
    allow :owner, :of => :playlist
    allow :editor, :of => :playlist, :to => [:edit, :update]
    #    allow :user, :of => :playlist, :to => [:index, :show]
  end

  def embedded_pager
    super Playlist
  end

  def list_tags
    @playlist_tags = Tag.all #really slow: Playlist.all.collect { |p| p.tags }.flatten.uniq
  end

  # GET /playlists
  # GET /playlists.xml
  def index
    @playlists = Sunspot.new_search(Playlist)

	if !params.has_key?(:sort)
	  params[:sort] = "display_name"
	end

    sort_base_url = ''
	@playlists.build do
	  if params.has_key?(:keywords)
	    keywords params[:keywords]
        sort_base_url += "&keywords=#{params[:keywords]}"
	  end
	  if params.has_key?(:tag)
	    with :tags, params[:tag]
	  end
	  with :public, true
	  paginate :page => params[:page], :per_page => cookies[:per_page] || nil
	  order_by params[:sort].to_sym, :asc
	end

	@playlists.execute!

    generate_sort_list("/playlists?#{sort_base_url}", {"display_name" => "DISPLAY NAME", "created_at" => "BY DATE"})

    # TODO: Update this to be linked through user / foreign key
    @my_bookmarks = current_user && !current_user.bookmark_id.nil? ? Playlist.find(current_user.bookmark_id): nil

    # TODO: Update this to exclude my bookmark
    @my_playlists = current_user ? current_user.playlists.select { |p| p != @my_bookmarks } : []
    
    respond_to do |format|
      format.html # index.html.erb
      format.xml  { render :xml => @playlists }
{'fraction_non_alphanumeric': 0.13866348448687352, 'fraction_numerical': 0.0, 'mean_word_length': 3.9597633136094674, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 35, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 6}, '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': '6632009', 'n_tokens_mistral': 1496, 'n_tokens_neox': 1431, 'n_words': 352}