示例#1
0
// trimFilter trims the filter to just essential parts
func trimFilter(f database.Filter) database.Filter {

	f.PP = ""
	f.EAL = ""
	f.Gender = ""
	f.SEN = []string{}
	f.KS2Bands = []string{}
	f.Ethnicities = []string{}

	return f
}
示例#2
0
// GetFilter produces a Filter object from the query string
// provided in the http Request
func getFilter(e env.Env, r *http.Request) database.Filter {

	query := r.URL.Query()
	if len(query) == 0 {
		return e.Config.DefaultFilter()
	}

	f := database.Filter{}
	f.Date = query.Get("date")
	f.Resultset = query.Get("resultset")
	f.NatYear = query.Get("natyear")
	f.Year = query.Get("year")
	f.PP = query.Get("pp")
	f.EAL = query.Get("eal")
	f.Gender = query.Get("gender")
	f.SEN = query["sen"]
	f.KS2Bands = query["ks2band"]

	// Change "Other" ethnicity to actual values
	ethnicities := query["ethnicity"]
	other := false
	for _, e := range ethnicities {
		if e == "Other" {
			other = true
		}
		f.Ethnicities = append(f.Ethnicities, e)
	}

	if other {
		for key, oth := range e.OtherEths {
			if oth {
				f.Ethnicities = append(f.Ethnicities, key)
			}
		}
	}
	return f
}