<commit_before># The filters added to this controller will be run for all controllers in the application.
# Likewise will all the methods added be available for all controllers.
class ApplicationController < ActionController::Base
	
	before_filter :init

	protected

	def init
		@title   = "TeamSquad"
		@scripts = Array.new
	end
	
	def get_organisation
		@organisation = Organisation.find_by_url_slug(request.subdomains.first)
		did_we_find? @organisation
		if @organisation then @sport = @organisation.sport end
	end
	
	def get_team
		@team = @organisation.find_team_by_url_slug @params["team_slug"]
		did_we_find? @team			
	end
	
	def get_current_season
		get_organisation
		@season = @organisation.current_season
		did_we_find? @season
	end
	
	def get_competition
		@competition = @season.find_competition_by_url_slug @params["competition_slug"]
		did_we_find? @competition
		@other_competitions = @season.competitions.find :all, :conditions => ["id!=?" ,@competition.id]
	end
	
	def get_stage
		get_competition
		@stage = @competition.find_stage_by_url_slug @params["stage_slug"]
		did_we_find? @stage
	end
	
	def get_group
		get_stage
		@group = @stage.find_group_by_url_slug @params["group_slug"]
		did_we_find? @group
	end
	
	private
	
	def did_we_find?(thing)
		if thing.nil?
			redirect_to "/404.html"
			false
		else
			if thing.respond_to? :title then @title += " - #{thing.title}" end 
			true
		end
	end
	
end<commit_msg>Improved initial data look ups to better handle missing data etc.<commit_after># The filters added to this controller will be run for all controllers in the application.
# Likewise will all the methods added be available for all controllers.
class ApplicationController < ActionController::Base
	
	before_filter :init

	protected

	def init
		@title   = "TeamSquad"
		@scripts = Array.new
	end
	
	def get_organisation
		@organisation = Organisation.find_by_url_slug(request.subdomains.first)	
		if @organisation then @sport = @organisation.sport end
		did_we_find? @organisation
	end
	
	def get_team
		@team = @organisation.find_team_by_url_slug @params["team_slug"]
		did_we_find? @team			
	end
	
	def get_current_season
		get_organisation
		@season = @organisation.current_season
		did_we_find? @season
	end
	
	def get_competition
		@competition = @season.find_competition_by_url_slug @params["competition_slug"]
		@other_competitions = @season.competitions.find :all, :conditions => ["id!=?" ,@competition.id]
	  did_we_find? @competition
	end
	
	def get_stage
		if get_competition
		 @stage = @competition.find_stage_by_url_slug @params["stage_slug"]
		end
		did_we_find? @stage
	end
	
	def get_group
		if get_stage
		  @group = @stage.find_group_by_url_slug @params["group_slug"]
		end
		did_we_find? @group
	end
	
	private
	
	def did_we_find?(thing)
	  if thing.respond_to? :title then @title += " - #{thing.title}" end 
		!(thing.nil? && redirect_to("/404.html"))
	end
	
end
{'fraction_non_alphanumeric': 0.0877914951989026, 'fraction_numerical': 0.00205761316872428, 'mean_word_length': 4.535104364326376, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, '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': '4528580', 'n_tokens_mistral': 1086, 'n_tokens_neox': 991, 'n_words': 249}