Exemple #1
0
func (this Picture) AddComment(comment models.Comment) revel.Result {
	this.Validation.Required(comment.Content).Message("娘娘说印象的内容是需要的~~")
	this.Validation.Required(comment.Commentor).Message("还有名称没写额,亲~~")

	id := this.Params.Form.Get("PictureID")

	if this.Validation.HasErrors() {
		this.Validation.Keep()
		this.FlashParams()
		return this.Redirect("Show?id=%s", id)
	}

	manager, err := models.NewDBManager()
	if err != nil {
		log.Println("链接数据库失败")
	}
	defer manager.Close()

	comm := models.Comment{
		PictureID:   id,
		PictureName: this.Params.Form.Get("PictureName"),
		Content:     comment.Content,
		Commentor:   comment.Commentor,
		TimeStamp:   time.Now().Format("2006-01-02 15:04:05")}

	err = manager.AddPictureComment(id, comm)
	if err != nil {
		log.Println(err)
		this.Response.Status = 500
		return this.Redirect("Show?id=%s", id)
	}

	return this.Redirect("Show?id=%s", id)
}
Exemple #2
0
func (this Picture) Show(id string) revel.Result {
	manager, err := models.NewDBManager()
	if err != nil {
		log.Println("链接数据库失败")
	}
	defer manager.Close()

	picture, err := manager.GetPictureById(id)
	if err != nil {
		log.Println(err)
		this.Response.Status = 500
		this.Flash.Error(err.Error())
	}
	comments := []models.Comment{}
	comments, err = manager.GetAllLastTenComments()
	if err != nil {
		log.Println(err)
		this.Response.Status = 500
		this.Flash.Error(err.Error())
	}

	lastPictureInfo := []models.LastPictureInfo{}
	lastPictureInfo, err = manager.GetAllLastPictureInfo()
	if err != nil {
		log.Println(err)
		this.Response.Status = 500
		this.Flash.Error(err.Error())
	}

	this.RenderArgs["Picture"] = picture
	this.RenderArgs["Administrator"] = this.Session["administrator"]
	this.RenderArgs["LastComments"] = comments
	this.RenderArgs["LastPictureInfo"] = lastPictureInfo
	return this.Render()
}
Exemple #3
0
func (this Picture) PostUploadForCheck() revel.Result {
	// 彩色版本照片
	fpCO, err := this.saveFile("COPictureFile")
	if err != nil {
		this.Response.Status = 500
		this.Flash.Error(err.Error())
		return this.Redirect(Picture.UploadForCheck)
	}

	t := time.Now()
	id := strconv.Itoa(t.Year()) + strconv.Itoa((int)(t.Month())) +
		strconv.Itoa(t.Day()) + strconv.Itoa(t.Hour()) +
		strconv.Itoa(t.Minute()) + strconv.Itoa(t.Second())
	fpOnQiNiuCO := "PCO" + id + path.Ext(fpCO)

	// 上传图片到七牛云储存(彩色版本)
	err = models.UploadToQiniu(fpCO, fpOnQiNiuCO, models.QiNiuBucketPre)
	if err != nil {
		this.Response.Status = 500
		this.Flash.Error(err.Error())
		return this.Redirect(Picture.UploadForCheck)
	}

	picture := models.Picture{
		ID:             id,
		Name:           this.Params.Form.Get("Name"),
		Contributor:    this.Params.Form.Get("Contributor"),
		University:     this.Params.Form.Get("University"),
		Classification: this.Params.Form.Get("Classification"),
		Discription:    this.Params.Form.Get("Discription"),
		PathOfColor:    models.QiNiuSpacePre + fpOnQiNiuCO}

	manager, err := models.NewDBManager()
	if err != nil {
		log.Println("链接数据库失败")
	}
	defer manager.Close()

	err = manager.AddPrePicture(picture)
	if err != nil {
		log.Println(err)
		this.Response.Status = 500
		this.Flash.Error(err.Error())
		return this.Redirect(Picture.UploadForCheck)
	}

	// 删除临时图片文件
	err = os.Remove(fpCO)
	if err != nil {
		log.Println("删除临时图片文件失败:", err)
	}

	this.Flash.Success("图片上传成功!")
	return this.Redirect(Picture.UploadForCheck)
}
Exemple #4
0
func addPV(pv models.PV) {
	manager, err := models.NewDBManager()
	if err != nil {
		log.Println("链接数据库失败")
	}
	defer manager.Close()

	err = manager.AddPV(pv)
	if err != nil {
		log.Println("链接数据库失败")
	}
}
Exemple #5
0
// 不建立用户数据库,仅仅通过session 识别管理员身份
func (this Admin) Index() revel.Result {
	manager, err := models.NewDBManager()
	if err != nil {
		log.Println("链接数据库失败")
	}
	defer manager.Close()

	pvs := []models.PV{}
	pvs, err = manager.GetAllPV()
	if err != nil {
		log.Println("链接数据库失败")
	}

	this.RenderArgs["Administrator"] = "true"
	this.RenderArgs["TotalPV"] = len(pvs)
	return this.Render()
}
Exemple #6
0
func (this Picture) Delete(id string) revel.Result {
	manager, err := models.NewDBManager()
	if err != nil {
		log.Println("链接数据库失败")
	}
	defer manager.Close()

	err = manager.DeletePicture(id)
	if err != nil {
		log.Println(err)
		this.Response.Status = 500
		this.Flash.Error(err.Error())
	}

	this.Flash.Success("成功删除图片信息")
	return this.Redirect(App.Index)
}
Exemple #7
0
func (this Picture) Edit(id string) revel.Result {
	manager, err := models.NewDBManager()
	if err != nil {
		log.Println("链接数据库失败")
	}
	defer manager.Close()

	picture, err := manager.GetPictureById(id)
	if err != nil {
		log.Println(err)
		this.Response.Status = 500
		this.Flash.Error(err.Error())
	}

	this.RenderArgs["Picture"] = picture
	return this.Render()
}
Exemple #8
0
func (this Picture) UniversityPictureNums() revel.Result {
	manager, err := models.NewDBManager()
	if err != nil {
		log.Println("链接数据库失败")
	}
	defer manager.Close()

	ps, err := manager.GetAllPicture()
	if err != nil {
		log.Println(err)
		this.Response.Status = 500
		this.Flash.Error(err.Error())
	}

	ups := make(map[string]int)
	for _, p := range ps {
		if ups[p.University] == 0 {
			ups[p.University] = 1
		} else {
			ups[p.University] += 1
		}
	}

	comments := []models.Comment{}
	comments, err = manager.GetAllLastTenComments()
	if err != nil {
		log.Println(err)
		this.Response.Status = 500
		this.Flash.Error(err.Error())
	}

	lastPictureInfo := []models.LastPictureInfo{}
	lastPictureInfo, err = manager.GetAllLastPictureInfo()
	if err != nil {
		log.Println(err)
		this.Response.Status = 500
		this.Flash.Error(err.Error())
	}

	this.RenderArgs["UniversityPictureNums"] = ups
	this.RenderArgs["LastComments"] = comments
	this.RenderArgs["LastPictureInfo"] = lastPictureInfo
	return this.Render()
}
Exemple #9
0
func (this Picture) Search(tag, key string) revel.Result {
	manager, err := models.NewDBManager()
	if err != nil {
		log.Println("链接数据库失败")
	}
	defer manager.Close()

	ps, err := manager.GetPictures(tag, key)
	if err != nil {
		log.Println(err)
		this.Response.Status = 500
		this.Flash.Error(err.Error())
	}

	if tag == "all" {
		this.RenderArgs["FromSearchForm"] = "True"
	}

	comments := []models.Comment{}
	comments, err = manager.GetAllLastTenComments()
	if err != nil {
		log.Println(err)
		this.Response.Status = 500
		this.Flash.Error(err.Error())
	}

	lastPictureInfo := []models.LastPictureInfo{}
	lastPictureInfo, err = manager.GetAllLastPictureInfo()
	if err != nil {
		log.Println(err)
		this.Response.Status = 500
		this.Flash.Error(err.Error())
	}

	this.RenderArgs["Pictures"] = ps
	this.RenderArgs["LastComments"] = comments
	this.RenderArgs["LastPictureInfo"] = lastPictureInfo
	return this.Render()
}
Exemple #10
0
func (this App) Index() revel.Result {
	manager, err := models.NewDBManager()
	if err != nil {
		log.Println("链接数据库失败")
	}
	defer manager.Close()

	ps, err := manager.GetAllPicture()
	if err != nil {
		log.Println(err)
		this.Response.Status = 500
		this.Flash.Error(err.Error())
	}

	comments := []models.Comment{}
	comments, err = manager.GetAllLastTenComments()
	if err != nil {
		log.Println(err)
		this.Response.Status = 500
		this.Flash.Error(err.Error())
	}

	lastPictureInfo := []models.LastPictureInfo{}
	lastPictureInfo, err = manager.GetAllLastPictureInfo()
	if err != nil {
		log.Println(err)
		this.Response.Status = 500
		this.Flash.Error(err.Error())
	}

	this.RenderArgs["Pictures"] = ps
	this.RenderArgs["fromeHomePage"] = "true"
	this.RenderArgs["LastComments"] = comments
	this.RenderArgs["LastPictureInfo"] = lastPictureInfo
	return this.Render()
}
Exemple #11
0
func (this Picture) PostEdit(id string) revel.Result {
	// 黑白版本照片
	fpBW, err := this.saveFile("BWPictureFile")
	if err != nil {
		this.Response.Status = 500
		this.Flash.Error(err.Error())
		return this.Redirect("Edit?id=%s", id)
	}

	// 彩色版本照片
	fpCO, err := this.saveFile("COPictureFile")
	if err != nil {
		this.Response.Status = 500
		this.Flash.Error(err.Error())
		return this.Redirect("Edit?id=%s", id)
	}

	t := time.Now()
	nid := strconv.Itoa(t.Year()) + strconv.Itoa((int)(t.Month())) +
		strconv.Itoa(t.Day()) + strconv.Itoa(t.Hour()) +
		strconv.Itoa(t.Minute()) + strconv.Itoa(t.Second())
	fpOnQiNiuBW := "PBW" + nid + path.Ext(fpBW)
	fpOnQiNiuCO := "PCO" + nid + path.Ext(fpCO)

	// 上传图片到七牛云储存(黑白版本)
	err = models.UploadToQiniu(fpBW, fpOnQiNiuBW, models.QiNiuBucket)
	if err != nil {
		this.Response.Status = 500
		this.Flash.Error(err.Error())
		return this.Redirect("Edit?id=%s", id)
	}

	// 删除临时图片文件
	err = os.Remove(fpBW)
	if err != nil {
		log.Println("删除临时图片文件失败:", err)
	}

	// 上传图片到七牛云储存(彩色版本)
	err = models.UploadToQiniu(fpCO, fpOnQiNiuCO, models.QiNiuBucket)
	if err != nil {
		this.Response.Status = 500
		this.Flash.Error(err.Error())
		return this.Redirect("Edit?id=%s", id)
	}

	err = os.Remove(fpCO)
	if err != nil {
		log.Println("删除临时图片文件失败:", err)
	}

	picture := models.Picture{
		ID:             id,
		Name:           this.Params.Form.Get("Name"),
		University:     this.Params.Form.Get("University"),
		Classification: this.Params.Form.Get("Classification"),
		Discription:    this.Params.Form.Get("Discription"),
		PathOfBW:       models.QiNiuSpace + fpOnQiNiuBW,
		PathOfColor:    models.QiNiuSpace + fpOnQiNiuCO}

	manager, err := models.NewDBManager()
	if err != nil {
		log.Println("链接数据库失败")
	}
	defer manager.Close()

	err = manager.UpdatePicture(&picture)
	if err != nil {
		log.Println(err)
		this.Response.Status = 500
		this.Flash.Error(err.Error())
		return this.Redirect("Edit?id=%s", id)
	}

	this.Flash.Success("图片更新成功!")
	return this.Redirect("Show?id=%s", id)
}