예제 #1
0
//@URL: /admin/news/(\d+)/status/ @method: POST
func (nc *AdminNews) Status(Nid string) {
	restweb.Logger.Debug("Admin News Status")

	if nc.Privilege != config.PrivilegeAD {
		nc.Err400("Warning", "Error Privilege to change news status")
		return
	}

	nid, err := strconv.Atoi(Nid)
	if err != nil {
		nc.Error("args error", 400)
		return
	}

	newsModle := model.NewsModel{}
	one, err := newsModle.Detail(nid)
	if err != nil {
		nc.Error(err.Error(), 400)
		return
	}
	var status int
	switch one.Status {
	case config.StatusAvailable:
		status = config.StatusReverse
	default:
		status = config.StatusAvailable
	}

	err = newsModle.Status(nid, status)
	if err != nil {
		nc.Error(err.Error(), 400)
		return
	}
	nc.Redirect("/admin/news", http.StatusFound)
}
예제 #2
0
func (this *NewsController) Edit(w http.ResponseWriter, r *http.Request) {
	class.Logger.Debug("Admin News Edit")
	this.Init(w, r)

	args := this.ParseURL(r.URL.String())
	nid, err := strconv.Atoi(args["nid"])
	if err != nil {
		http.Error(w, "args error", 400)
		return
	}

	newsModel := model.NewsModel{}
	one, err := newsModel.Detail(nid)
	this.Data["Detail"] = one
	if err != nil {
		http.Error(w, err.Error(), 400)
		return
	}

	this.Data["Title"] = "Admin - News Edit"
	this.Data["IsNews"] = true
	this.Data["IsList"] = false
	this.Data["IsEdit"] = true

	err = this.Execute(w, "view/admin/layout.tpl", "view/admin/news_edit.tpl")
	if err != nil {
		http.Error(w, "tpl error", 500)
		return
	}
}
예제 #3
0
func (this *NewsController) Status(w http.ResponseWriter, r *http.Request) {
	class.Logger.Debug("Admin News Status")
	if r.Method != "POST" {
		this.Err400(w, r, "Error", "Error Method to change news status")
		return
	}

	this.Init(w, r)

	if this.Privilege != config.PrivilegeAD {
		this.Err400(w, r, "Warning", "Error Privilege to change news status")
		return
	}

	args := this.ParseURL(r.URL.String())
	nid, err := strconv.Atoi(args["nid"])
	if err != nil {
		http.Error(w, "args error", 400)
		return
	}

	newsModle := model.NewsModel{}
	one, err := newsModle.Detail(nid)
	if err != nil {
		http.Error(w, err.Error(), 400)
		return
	}
	var status int
	switch one.Status {
	case config.StatusAvailable:
		status = config.StatusReverse
	default:
		status = config.StatusAvailable
	}

	err = newsModle.Status(nid, status)
	if err != nil {
		http.Error(w, err.Error(), 400)
		return
	}
	http.Redirect(w, r, "/admin/news?list", http.StatusFound)
}
예제 #4
0
//@URL: /news/(\d+) @method: GET
func (nc *NewsController) Detail(Nid string) {
	nid, err := strconv.Atoi(Nid) //获取nid
	if err != nil {
		// http.Error(w, "args error", 400)
		return
	}

	newsModel := model.NewsModel{}
	one, err := newsModel.Detail(nid)
	if err != nil {
		http.Error(nc.W, err.Error(), 500)
	}
	nc.Output["Detail"] = one

	if one.Status == config.StatusReverse {
		nc.Err400("No such news", "No such news")
		return
	}

	nc.Output["Title"] = "News Detail"
	nc.RenderTemplate("view/layout.tpl", "view/news_detail.tpl")
}
예제 #5
0
//列出指定新闻的详细信息
func (this *NewsController) Detail(w http.ResponseWriter, r *http.Request) {
	class.Logger.Debug("News Detail")
	this.Init(w, r)

	args := this.ParseURL(r.URL.String())
	nid, err := strconv.Atoi(args["nid"]) //获取nid
	if err != nil {
		class.Logger.Debug(args["nid"])
		http.Error(w, "args error", 400)
		return
	}

	newsModel := model.NewsModel{}
	one, err := newsModel.Detail(nid)
	if err != nil {
		http.Error(w, err.Error(), 500)
	}
	this.Data["Detail"] = one

	if one.Status == config.StatusReverse && this.Privilege != config.PrivilegeAD { //如果news的状态为普通用户不可见
		this.Data["Title"] = "No such news"
		this.Data["Info"] = "No such news"
		err = this.Execute(w, "view/layout.tpl", "view/400.tpl")
		if err != nil {
			http.Error(w, "tpl error", 500)
			return
		}
		return
	}

	this.Data["Title"] = "News Detail"
	err = this.Execute(w, "view/layout.tpl", "view/news_detail.tpl")
	if err != nil {
		http.Error(w, "tpl error", 500)
		return
	}
}
예제 #6
0
//@URL: /admin/news/(\d+)/ @method: GET
func (nc *AdminNews) Edit(Nid string) {
	restweb.Logger.Debug("Admin News Edit")

	nid, err := strconv.Atoi(Nid)
	if err != nil {
		nc.Error("args error", 400)
		return
	}

	newsModel := model.NewsModel{}
	one, err := newsModel.Detail(nid)
	nc.Output["Detail"] = one
	if err != nil {
		nc.Error(err.Error(), 400)
		return
	}

	nc.Output["Title"] = "Admin - News Edit"
	nc.Output["IsNews"] = true
	nc.Output["IsList"] = false
	nc.Output["IsEdit"] = true

	nc.RenderTemplate("view/admin/layout.tpl", "view/admin/news_edit.tpl")
}