예제 #1
0
파일: post-admin.go 프로젝트: migege/milog
func (this *AdminController) PostEdit() {
	this.TplName = "admin-post.tpl"
	id := this.Ctx.Input.Param(":id")
	post_id, _ := strconv.Atoi(id)

	post, err := models.NewPostModel().ById(post_id, true)
	if err != nil {
		panic(err)
	} else if post.Author.AuthorId != this.loggedUser.AuthorId {
		panic(errors.New("error: can't edit another one's post"))
	}

	tags, _ := models.NewTagModel().AllTags()
	this.Data["Post"] = post
	this.Data["AllTags"] = tags
	this.Data["PageTitle"] = fmt.Sprintf("Editing Post: %s - %s", post.PostTitle, blogTitle)
}
예제 #2
0
파일: base.go 프로젝트: migege/milog
func (this *BaseController) LoadSidebar(widgets []string) {
	for _, widget := range widgets {
		if widget == "LatestComments" {
			if latest_comments, err := models.NewCommentModel().Latest(10); err == nil {
				this.Data["LatestComments"] = latest_comments
			}
		} else if widget == "MostPopular" {
			if posts, err := models.NewPostModel().MostPopular(10); err == nil {
				this.Data["MostPopular"] = posts
			}
		} else if widget == "Links" {
			if links, err := models.NewLinkModel().AllLinks(); err == nil {
				this.Data["Links"] = links
			}
		} else if widget == "TagCloud" {
			if tags, err := models.NewTagModel().MostPopular(20); err == nil {
				this.Data["TagCloud"] = tags
			}
		}
	}
}
예제 #3
0
파일: tag.go 프로젝트: migege/milog
func (this *TagController) ByName() {
	this.TplName = "home.tpl"
	tag_name := this.Ctx.Input.Param(":tag")

	post_count, err := models.NewPostModel().Count("Tags__Tag__TagSlug", tag_name)
	if err != nil {
		panic(err)
	}
	paginator := pagination.SetPaginator(this.Ctx, postsPerPage, post_count)

	posts, err := models.NewPostModel().ByTagName(tag_name, "-PostId", paginator.Offset(), postsPerPage, false, true, true)
	if err != nil {
		this.Abort("404")
	}
	this.Data["Posts"] = posts

	this.SetPostViews(posts)
	this.LoadSidebar([]string{"LatestComments", "MostPopular"})

	if tag, err := models.NewTagModel().BySlug(tag_name); err == nil {
		this.Data["Content"] = fmt.Sprintf("Tag - %s", tag.TagName)
		this.Data["PageTitle"] = fmt.Sprintf("%s - Tag - %s", tag.TagName, blogTitle)
	}
}
예제 #4
0
파일: post-admin.go 프로젝트: migege/milog
func (this *AdminController) PostNew() {
	this.TplName = "admin-post.tpl"
	tags, _ := models.NewTagModel().AllTags()
	this.Data["AllTags"] = tags
	this.Data["PageTitle"] = fmt.Sprintf("New Post - Admin - %s", blogTitle)
}