diff --git a/orm/contest.go b/orm/contest.go index b7786a1f..f9dcc2ef 100644 --- a/orm/contest.go +++ b/orm/contest.go @@ -94,10 +94,10 @@ func (c *Contest) Read(db *Database, args map[string]string, w http.ResponseWrit Preload("Participants"). Preload("Responses"). Preload("StartedResponses", func(tx *gorm.DB) *gorm.DB { - return db.DB().Debug().Where("start_time <> ?", time.Time{}) + return db.DB().Where("start_time <> ?", time.Time{}) }). Preload("SavedResponses", func(tx *gorm.DB) *gorm.DB { - return db.DB().Debug().Where("end_time <> ?", time.Time{}) + return db.DB().Where("end_time <> ?", time.Time{}) }). Preload("Questions"). First(&contest, id).Error; err != nil { @@ -182,7 +182,7 @@ func (c *Contest) Update(db *Database, args map[string]string, w http.ResponseWr // Optionally reset participant start time if contest.(*Contest).ResetStartTime { - err := db._db.Debug().Model(&Response{}).Where("contest_id=?", contest.(*Contest).ID).Update("start_time", time.Time{}).Error + err := db._db.Model(&Response{}).Where("contest_id=?", contest.(*Contest).ID).Update("start_time", time.Time{}).Error if err != nil { return nil, err } @@ -218,7 +218,7 @@ func SaveContest(db *Database, contest interface{}) (interface{}, error) { return contest, nil } -func (c *Contest) isAlwaysActive() bool { +func (c *Contest) IsAlwaysActive() bool { return c.StartTime.IsZero() || c.EndTime.IsZero() || c.Duration == 0 } diff --git a/orm/response.go b/orm/response.go index 3325d824..1c1e223c 100644 --- a/orm/response.go +++ b/orm/response.go @@ -60,7 +60,10 @@ func (model *Response) String() string { } func (model *Response) IsActive() bool { - return (!time.Now().Before(model.Contest.StartTime) && !time.Now().After(model.Contest.EndTime)) || model.Contest.isAlwaysActive() + if !model.StartTime.IsZero() { + return !time.Now().After(model.EndTime) || model.Contest.IsAlwaysActive() + } + return (!time.Now().Before(model.Contest.StartTime) && !time.Now().After(model.Contest.EndTime)) || model.Contest.IsAlwaysActive() } func (model *Response) SetCreatorID(id uint) { @@ -216,7 +219,7 @@ func (model *Response) Update(db *Database, args map[string]string, w http.Respo // Write StartTime for the first time if user is a participant - if isParticipant(r) && !response.Contest.isAlwaysActive() { + if isParticipant(r) && !response.Contest.IsAlwaysActive() { if !response.IsActive() { return nil, errors.OutOfTime } diff --git a/templates/responses_show.html.tpl b/templates/responses_show.html.tpl index 312a6ea2..aaf7cdeb 100644 --- a/templates/responses_show.html.tpl +++ b/templates/responses_show.html.tpl @@ -19,24 +19,41 @@