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).
This commit is contained in:
@@ -5,6 +5,7 @@ package models
|
||||
import (
|
||||
"time"
|
||||
|
||||
"git.golem15.com/golem15/summercms/modules/lagoon/attach"
|
||||
"gorm.io/gorm"
|
||||
)
|
||||
|
||||
@@ -19,17 +20,17 @@ const MaterialFilesField = "files"
|
||||
// tied to a course. A material without published_at is a draft and is not
|
||||
// served by the API.
|
||||
type Material struct {
|
||||
ID uint `gorm:"column:id;primaryKey"`
|
||||
CourseID *uint `gorm:"column:course_id"`
|
||||
Course *Course `gorm:"foreignKey:CourseID"`
|
||||
Title string `gorm:"column:title"`
|
||||
Type string `gorm:"column:type"`
|
||||
Body *string `gorm:"column:body"`
|
||||
Source *string `gorm:"column:source"`
|
||||
URL *string `gorm:"column:url"`
|
||||
PublishedAt *DateTime `gorm:"column:published_at"`
|
||||
CreatedAt time.Time `gorm:"column:created_at"`
|
||||
UpdatedAt time.Time `gorm:"column:updated_at"`
|
||||
ID uint `gorm:"column:id;primaryKey"`
|
||||
CourseID *uint `gorm:"column:course_id"`
|
||||
Course *Course `gorm:"foreignKey:CourseID"`
|
||||
Title string `gorm:"column:title"`
|
||||
Type string `gorm:"column:type"`
|
||||
Body *string `gorm:"column:body"`
|
||||
Source *string `gorm:"column:source"`
|
||||
URL *string `gorm:"column:url"`
|
||||
PublishedAt *time.Time `gorm:"column:published_at"`
|
||||
CreatedAt time.Time `gorm:"column:created_at"`
|
||||
UpdatedAt time.Time `gorm:"column:updated_at"`
|
||||
|
||||
Tags []Tag `gorm:"many2many:jz_bm_material_tag;joinForeignKey:material_id;joinReferences:tag_id"`
|
||||
}
|
||||
@@ -55,21 +56,14 @@ func (Material) Rules() map[string]string {
|
||||
}
|
||||
}
|
||||
|
||||
// TemporalErrors checks published_at, which lagoon.Validate cannot.
|
||||
func (m *Material) TemporalErrors() map[string][]string {
|
||||
e := temporalErrors{}
|
||||
if m.PublishedAt != nil {
|
||||
e.dateTime("published_at", *m.PublishedAt, false)
|
||||
}
|
||||
return e.result()
|
||||
// AttachRelations declares the attachMany "files". The files are public:
|
||||
// the student app links them by their storage URL.
|
||||
func (Material) AttachRelations() []attach.Relation {
|
||||
return []attach.Relation{{Name: MaterialFilesField, Many: true, Public: true}}
|
||||
}
|
||||
|
||||
// BeforeSave stores NULL for empty optional text and an empty publication
|
||||
// time.
|
||||
// BeforeSave stores NULL for empty optional text.
|
||||
func (m *Material) BeforeSave(*gorm.DB) error {
|
||||
blank(&m.Body, &m.Source, &m.URL)
|
||||
if m.PublishedAt != nil && *m.PublishedAt == "" {
|
||||
m.PublishedAt = nil
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user