// 获取查询列表 func ListObjects(qs orm.QuerySeter, objs interface{}) (int64, error) { nums, err := qs.All(objs) if err != nil { beego.Error("models.ListObjects ", err) return 0, err } return nums, err }
func (this *TeamController) Teams() { query := strings.TrimSpace(this.GetString("query", "")) if utils.HasDangerousCharacters(query) { this.ServeErrJson("query is invalid") return } per := this.MustGetInt("per", 10) me := this.Ctx.Input.GetData("CurrentUser").(*User) var teams orm.QuerySeter if me.Role == ROOT_ADMIN_ROLE { teams = QueryAllTeams(query) } else { var err error teams, err = QueryMineTeams(query, me.Id) if err != nil { this.ServeErrJson("occur error " + err.Error()) return } } total, err := teams.Count() if err != nil { this.ServeErrJson("occur error " + err.Error()) return } pager := this.SetPaginator(per, total) teams = teams.Limit(per, pager.Offset()) var ts []Team _, err = teams.All(&ts) if err != nil { this.ServeErrJson("occur error " + err.Error()) return } nteams := make([]map[string]interface{}, 0) for _, v := range ts { cu := ReadUserById(v.Creator) t := make(map[string]interface{}) t["Id"] = v.Id t["Name"] = v.Name t["Resume"] = v.Resume t["CreatorCnname"] = cu.Cnname t["CreatorName"] = cu.Name t["IsAdmin"] = (v.IsAdmin(me.Id) || me.Role == ROOT_ADMIN_ROLE) nteams = append(nteams, t) } this.Data["Teams"] = nteams this.Data["Query"] = query this.Data["Me"] = me this.Data["IamRoot"] = me.Role == ROOT_ADMIN_ROLE this.TplName = "team/list.html" }
func GetUser(email, passwd string) ([]User, error) { o := orm.NewOrm() var users []User var cond *orm.Condition cond = orm.NewCondition() cond = cond.And("email", email) cond = cond.And("passwd", passwd) var qs orm.QuerySeter qs = o.QueryTable("user").SetCond(cond) _, err := qs.All(&users) return users, err }