Merge branch 'preload_school'

This commit is contained in:
Andrea Fazzi 2022-03-15 11:23:44 +01:00
commit a602eced73
3 changed files with 9 additions and 6 deletions

View file

@ -111,11 +111,11 @@ func (model *Participant) exists(db *Database) (*User, error) {
if err := db._db.First(&user, &User{Username: model.username()}).Error; err != nil && err != gorm.ErrRecordNotFound { if err := db._db.First(&user, &User{Username: model.username()}).Error; err != nil && err != gorm.ErrRecordNotFound {
return nil, err return nil, err
} else if err == gorm.ErrRecordNotFound { } else if err == gorm.ErrRecordNotFound {
log.Printf("User %s doesn't exist", user) log.Printf("User %s doesn't exist", user.Username)
return nil, nil return nil, nil
} }
log.Printf("User %s exists", user) log.Printf("User %s exists", user.Username)
return &user, nil return &user, nil
} }
@ -219,7 +219,7 @@ func (model *Participant) Create(db *Database, args map[string]string, w http.Re
if err := db._db.First(&school, participant.SchoolID).Error; err != nil { if err := db._db.First(&school, participant.SchoolID).Error; err != nil {
return nil, err return nil, err
} }
log.Printf("Check if a participant of the same category exists for school %s", school) log.Printf("Check if a participant of the same category exists for school %s", school.Name)
hasCategory, err := school.HasCategory(db, participant) hasCategory, err := school.HasCategory(db, participant)
if err != nil { if err != nil {
return nil, err return nil, err
@ -321,6 +321,7 @@ func (model *Participant) ReadAll(db *Database, args map[string]string, w http.R
} }
if err := db._db. if err := db._db.
Preload("Category"). Preload("Category").
Preload("School.Region").
Preload("School"). Preload("School").
Preload("Contests"). Preload("Contests").
Order("lastname"). Order("lastname").

View file

@ -69,8 +69,8 @@ type School struct {
SelectedRegion map[uint]string `gorm:"-"` SelectedRegion map[uint]string `gorm:"-"`
AllRegions []*Region `gorm:"-"` AllRegions []*Region `gorm:"-"`
CaptchaID string `gorm:"-",schema:"-"` CaptchaID string `gorm:"-" schema:"-"`
CaptchaSolution string `gorm:"-",schema:"-"` CaptchaSolution string `gorm:"-" schema:"-"`
mailSender *mail.MailSender mailSender *mail.MailSender
} }

View file

@ -1,2 +1,4 @@
*.csv *.csv
*.xlsx *.xlsx
export_participants