Beispiel #1
0
// view for list model data
func (this *TopicAdminRouter) List() {
	var topics []models.Topic
	qs := models.Topics().OrderBy("-Category__id").RelatedSel()
	if err := this.SetObjects(qs, &topics); err != nil {
		this.Data["Error"] = err
		beego.Error(err)
	}
}
Beispiel #2
0
func (form *TopicAdminForm) Valid(v *validation.Validation) {
	qs := models.Topics()

	if models.CheckIsExist(qs, "Name", form.Name, form.Id) {
		v.SetError("Name", "admin.field_need_unique")
	}

	if models.CheckIsExist(qs, "Slug", form.Slug, form.Id) {
		v.SetError("Slug", "admin.field_need_unique")
	}
}
Beispiel #3
0
// view for delete object
func (this *CategoryAdminRouter) Delete() {
	if this.FormOnceNotMatch() {
		return
	}
	// check whether there are topics under the category
	qs := models.Topics().Filter("Category__Id", this.object.Id)
	cnt, _ := qs.Count()
	if cnt > 0 {
		this.FlashRedirect("/admin/category", 302, "DeleteNotAllowed")
		return
	} else {
		// delete object
		if err := this.object.Delete(); err == nil {
			this.FlashRedirect("/admin/category", 302, "DeleteSuccess")
			return
		} else {
			beego.Error(err)
			this.Data["Error"] = err
		}
	}
}
Beispiel #4
0
func (this *TopicAdminRouter) ObjectQs() orm.QuerySeter {
	return models.Topics().RelatedSel()
}
Beispiel #5
0
func ListTopicsOfCategory(topics *[]models.Topic, cat *models.Category) (int64, error) {
	return models.Topics().Filter("Category__id", cat.Id).OrderBy("-order").All(topics)
}
Beispiel #6
0
func ListTopics(topics *[]models.Topic) (int64, error) {
	return models.Topics().OrderBy("-Followers").All(topics)
}