Exemple #1
0
func (this *AdminRouter) ModelSelect() {
	search := this.GetString("search")
	model := this.GetString("model")
	result := map[string]interface{}{
		"success": false,
	}

	var data []orm.ParamsList

	defer func() {
		if len(data) > 0 {
			result["success"] = true
			result["data"] = data
		}
		this.Data["json"] = result
		this.ServeJson()
	}()

	if len(search) < 3 {
		return
	}

	switch model {
	case "User":
		models.Users().Filter("UserName__icontains", search).Limit(10).ValuesList(&data, "Id", "UserName")
	}
}
Exemple #2
0
func (this *AdminRouter) ModelGet() {
	id := this.GetString("id")
	model := this.GetString("model")
	result := map[string]interface{}{
		"success": false,
	}

	var data []orm.ParamsList

	defer func() {
		if len(data) > 0 {
			result["success"] = true
			result["data"] = data[0]
		}
		this.Data["json"] = result
		this.ServeJson()
	}()

	var qs orm.QuerySeter

	switch model {
	case "User":
		qs = models.Users()
	}

	qs = qs.Filter("Id", id).Limit(1)

	switch model {
	case "User":
		qs.ValuesList(&data, "Id", "UserName")
	}
}
Exemple #3
0
// view for list model data
func (this *UserAdminRouter) List() {
	var q = this.GetString("q")
	var users []models.User
	var qs orm.QuerySeter
	if q != "" {
		cond := orm.NewCondition()
		cond = cond.Or("Email", q)
		cond = cond.Or("UserName", q)
		qs = models.Users().SetCond(cond)
	} else {
		qs = models.Users()
	}
	this.Data["q"] = q
	if err := this.SetObjects(qs, &users); err != nil {
		this.Data["Error"] = err
		beego.Error(err)
	}
}
Exemple #4
0
func (form *UserAdminForm) Valid(v *validation.Validation) {
	qs := models.Users()

	if models.CheckIsExist(qs, "UserName", form.UserName, form.Id) {
		v.SetError("UserName", "auth.username_already_taken")
	}

	if models.CheckIsExist(qs, "Email", form.Email, form.Id) {
		v.SetError("Email", "auth.email_already_taken")
	}

	if len(i18n.GetLangByIndex(form.Lang)) == 0 {
		v.SetError("Lang", "Can not be empty")
	}
}
Exemple #5
0
func (this *UserAdminRouter) ObjectQs() orm.QuerySeter {
	return models.Users().RelatedSel()
}