summaryrefslogtreecommitdiffstats
path: root/models
diff options
context:
space:
mode:
authorUnknwon <u@gogs.io>2015-08-10 00:37:42 +0800
committerUnknwon <u@gogs.io>2015-08-10 00:37:42 +0800
commita79586cc545594d8876438e2497c9408945748b2 (patch)
tree689da38141f2e3dc2b33a15132f5eb3116915b00 /models
parent590c464c56c993c461f10470926a96448f4f7d00 (diff)
parent8a3ee795d2d069bbb57b3d134367078c8e8391d5 (diff)
downloadgitea-a79586cc545594d8876438e2497c9408945748b2.tar.gz
gitea-a79586cc545594d8876438e2497c9408945748b2.zip
Merge branch 'develop' of github.com:gogits/gogs into feature/pull_request2
# Conflicts: # modules/bindata/bindata.go # public/css/gogs.min.css # templates/repo/header.tmpl
Diffstat (limited to 'models')
-rw-r--r--models/issue.go20
-rw-r--r--models/user.go33
2 files changed, 42 insertions, 11 deletions
diff --git a/models/issue.go b/models/issue.go
index e757af2d80..39969c7194 100644
--- a/models/issue.go
+++ b/models/issue.go
@@ -658,6 +658,14 @@ type Milestone struct {
ClosedDate time.Time
}
+func (m *Milestone) BeforeUpdate() {
+ if m.NumIssues > 0 {
+ m.Completeness = m.NumClosedIssues * 100 / m.NumIssues
+ } else {
+ m.Completeness = 0
+ }
+}
+
func (m *Milestone) AfterSet(colName string, _ xorm.Cell) {
if colName == "deadline" {
if m.Deadline.Year() == 9999 {
@@ -804,8 +812,6 @@ func ChangeMilestoneIssueStats(issue *Issue) error {
m.NumClosedIssues--
}
- m.Completeness = m.NumClosedIssues * 100 / m.NumIssues
-
return UpdateMilestone(m)
}
@@ -827,13 +833,8 @@ func ChangeMilestoneAssign(oldMid, mid int64, issue *Issue) (err error) {
if issue.IsClosed {
m.NumClosedIssues--
}
- if m.NumIssues > 0 {
- m.Completeness = m.NumClosedIssues * 100 / m.NumIssues
- } else {
- m.Completeness = 0
- }
- if _, err = sess.Id(m.ID).Cols("num_issues,num_completeness,num_closed_issues").Update(m); err != nil {
+ if _, err = sess.Id(m.ID).AllCols().Update(m); err != nil {
sess.Rollback()
return err
}
@@ -860,8 +861,7 @@ func ChangeMilestoneAssign(oldMid, mid int64, issue *Issue) (err error) {
return ErrWrongIssueCounter
}
- m.Completeness = m.NumClosedIssues * 100 / m.NumIssues
- if _, err = sess.Id(m.ID).Cols("num_issues,num_completeness,num_closed_issues").Update(m); err != nil {
+ if _, err = sess.Id(m.ID).AllCols().Update(m); err != nil {
sess.Rollback()
return err
}
diff --git a/models/user.go b/models/user.go
index 3100a45ade..ed64c3973f 100644
--- a/models/user.go
+++ b/models/user.go
@@ -13,7 +13,9 @@ import (
"fmt"
"image"
"image/jpeg"
+ _ "image/jpeg"
"os"
+ "path"
"path/filepath"
"strings"
"time"
@@ -116,11 +118,40 @@ func (u *User) HomeLink() string {
// AvatarLink returns user gravatar link.
func (u *User) AvatarLink() string {
+ defaultImgUrl := setting.AppSubUrl + "/img/avatar_default.jpg"
+ imgPath := path.Join(setting.AvatarUploadPath, com.ToStr(u.Id))
switch {
case u.UseCustomAvatar:
+ if !com.IsExist(imgPath) {
+ return defaultImgUrl
+ }
return setting.AppSubUrl + "/avatars/" + com.ToStr(u.Id)
case setting.DisableGravatar, setting.OfflineMode:
- return setting.AppSubUrl + "/img/avatar_default.jpg"
+ if !com.IsExist(imgPath) {
+ img, err := avatar.RandomImage([]byte(u.Email))
+ if err != nil {
+ log.Error(3, "RandomImage: %v", err)
+ return defaultImgUrl
+ }
+ if err = os.MkdirAll(path.Dir(imgPath), os.ModePerm); err != nil {
+ log.Error(3, "MkdirAll: %v", err)
+ return defaultImgUrl
+ }
+ fw, err := os.Create(imgPath)
+ if err != nil {
+ log.Error(3, "Create: %v", err)
+ return defaultImgUrl
+ }
+ defer fw.Close()
+
+ if err = jpeg.Encode(fw, img, nil); err != nil {
+ log.Error(3, "Encode: %v", err)
+ return defaultImgUrl
+ }
+ log.Info("New random avatar created: %d", u.Id)
+ }
+
+ return setting.AppSubUrl + "/avatars/" + com.ToStr(u.Id)
case setting.Service.EnableCacheAvatar:
return setting.AppSubUrl + "/avatar/" + u.Avatar
}