Files
sm-bm-plugin/models/nullable.go
Jakub Zych 71b848a376 Adopt SummerCMS v0.1.1 admin features
Datepickers on native time.Time / lagoon.Date fields, file uploads on
materials, readings and class sessions managed from the course form
(course_id made nullable).
2026-10-03 06:03:34 +02:00

33 lines
870 B
Go

package models
import "strings"
// blank clears each optional text column whose value is empty or only
// whitespace, so an emptied admin text input stores NULL rather than "".
func blank(fields ...**string) {
for _, f := range fields {
if *f != nil && strings.TrimSpace(**f) == "" {
*f = nil
}
}
}
// temporalErrors is a field-to-messages map in the shape of lagoon.Validate.
type temporalErrors map[string][]string
func (e temporalErrors) add(field, msg string) { e[field] = append(e[field], msg) }
func (e temporalErrors) result() map[string][]string {
if len(e) == 0 {
return nil
}
return e
}
// TemporalValidator is implemented by models whose dates must be in order.
// The admin controllers call it before a save, because lagoon.Validate
// cannot compare two fields.
type TemporalValidator interface {
TemporalErrors() map[string][]string
}