Ejemplo n.º 1
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")
	}
}
Ejemplo n.º 2
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")
	}
}
Ejemplo n.º 3
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")
	}

	if len(form.LangAdds) > 0 {
		adds := make(models.SliceStringField, 0, len(form.LangAdds))
		for _, l := range form.LangAdds {
			if d, err := utils.StrTo(l).Int(); err == nil {
				if form.Lang == d {
					continue
				}
				if len(i18n.GetLangByIndex(form.Lang)) == 0 {
					v.SetError("Lang", "Can not be empty")
					return
				}
				adds = append(adds, l)
			}
		}
		form.LangAdds = adds
	}
}
Ejemplo n.º 4
0
// view for list model data
func (this *UserAdminRouter) List() {
	var users []models.User
	qs := models.Users()
	if err := this.SetObjects(qs, &users); err != nil {
		this.Data["Error"] = err
		beego.Error(err)
	}
}
Ejemplo n.º 5
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)
	}
}
Ejemplo n.º 6
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")
	}
}
Ejemplo n.º 7
0
func (this *UserAdminRouter) ObjectQs() orm.QuerySeter {
	return models.Users().RelatedSel()
}