コード例 #1
0
ファイル: content-v.go プロジェクト: Laller/hypecms
func (h *H) contentView(content_map map[string]string) (error, bool) {
	uni := h.uni
	types, ok := jsonp.Get(uni.Opt, "Modules.content.types")
	if !ok {
		return fmt.Errorf("No content types."), false
	}
	slug_keymap := map[string]struct{}{}
	for _, v := range types.(map[string]interface{}) {
		type_conf := v.(map[string]interface{})
		if slugval, has := type_conf["accessed_by"]; has {
			slug_keymap[slugval.(string)] = struct{}{}
		} else {
			slug_keymap["slug"] = struct{}{}
		}
	}
	slug_keys := []string{}
	for i, _ := range slug_keymap {
		slug_keys = append(slug_keys, i)
	}
	content, found := content_model.FindContent(uni.Db, slug_keys, content_map["slug"])
	if !found {
		return nil, false
	}
	dont_query := map[string]interface{}{"password": 0}
	resolver.ResolveOne(uni.Db, content, dont_query)
	uni.Dat["_points"] = []string{"content"}
	uni.Dat["content"] = content
	return nil, true
}
コード例 #2
0
ファイル: content-v.go プロジェクト: Laller/hypecms
func (v *V) editContent(typ, id string) (interface{}, error) {
	uni := v.uni
	hasid := len(id) > 0
	uni.Dat["is_content"] = true
	var indb interface{}
	if hasid {
		uni.Dat["op"] = "update"
		err := uni.Db.C("contents").Find(m{"_id": bson.ObjectIdHex(id)}).One(&indb) // Ugly.
		if err != nil {
			return nil, err
		}
		indb = basic.Convert(indb)
		resolver.ResolveOne(uni.Db, indb, nil)
		uni.Dat["content"] = indb
		latest_draft := content_model.GetUpToDateDraft(uni.Db, bson.ObjectIdHex(id), indb.(map[string]interface{}))
		uni.Dat["latest_draft"] = latest_draft
		timeline, err := content_model.ContentTimeline(uni.Db, indb.(map[string]interface{}))
		if err != nil {
			return nil, err
		}
		uni.Dat["timeline"] = timeline
	} else {
		uni.Dat["op"] = "insert"
	}
	return context.Convert(indb), nil
}
コード例 #3
0
ファイル: content-v.go プロジェクト: Laller/hypecms
func (v *V) editDraft(typ, id string) (interface{}, error) {
	hasid := len(id) > 0
	uni := v.uni
	uni.Dat["is_draft"] = true
	if hasid {
		built, err := content_model.BuildDraft(uni.Db, typ, id)
		if err != nil {
			return nil, err
		}
		d := built["data"].(map[string]interface{})
		if _, draft_of_sg := built["draft_of"]; draft_of_sg {
			uni.Dat["content_parent"] = true
			fresher, err := content_model.IsDraftUpToDate(uni.Db, built, d)
			if err != nil {
				return nil, err
			}
			uni.Dat["up_to_date"] = fresher
			uni.Dat["op"] = "update"
		} else { // It's possible that it has no parent at all, then it is a fresh new draft, first version.
			uni.Dat["op"] = "insert"
		}
		resolver.ResolveOne(uni.Db, d, nil)
		uni.Dat["content"] = d
		timeline, err := content_model.DraftTimeline(uni.Db, patterns.ToIdWithCare(id))
		if err != nil {
			return nil, err
		}
		uni.Dat["timeline"] = timeline
		uni.Dat["draft"] = built
		return d, nil
	}
	uni.Dat["op"] = "insert"
	return map[string]interface{}{}, nil
}
コード例 #4
0
ファイル: content_model.go プロジェクト: Laller/hypecms
// Generates the fulltext field by querying the content, resolving it's foreign keys, then trimming them
func generateFulltext(db *mgo.Database, id bson.ObjectId) []string {
	var res interface{}
	db.C("contents").Find(m{"_id": id}).One(&res)
	dat := basic.Convert(res).(map[string]interface{})
	fields := map[string]interface{}{
		"name":  1,
		"slug":  1,
		"title": 1,
	}
	resolver.ResolveOne(db, dat, fields)
	dat = basic.Convert(dat).(map[string]interface{})
	non_split := walkDeep(dat)
	return simpleFulltext(non_split)
}
コード例 #5
0
ファイル: content-v.go プロジェクト: Laller/hypecms
// You don't actually edit anything on a past version...
func (v *V) editVersion(typ, id string) (interface{}, error) {
	uni := v.uni
	uni.Dat["is_version"] = true
	version_id := patterns.ToIdWithCare(id)
	version, err := content_model.FindVersion(uni.Db, version_id)
	if err != nil {
		return nil, err
	}
	resolver.ResolveOne(uni.Db, version, nil)
	timeline, err := content_model.DraftTimeline(uni.Db, version_id)
	if err != nil {
		return nil, err
	}
	uni.Dat["timeline"] = timeline
	uni.Dat["op"] = "update"
	uni.Dat["content"] = version
	return nil, nil
}