libfic: Can indicate that an exercice is WIP

This commit is contained in:
nemunaire 2022-11-05 15:26:57 +01:00
commit c415e06237
10 changed files with 63 additions and 6 deletions

View file

@ -71,6 +71,7 @@ type ExerciceFlagChoice struct {
// ExerciceParams contains values parsed from defines.txt.
type ExerciceParams struct {
WIP bool `toml:"wip"`
Gain int64
Tags []string
Files []ExerciceFile `toml:"file"`

View file

@ -16,6 +16,9 @@ import (
"srs.epita.fr/fic-server/libfic"
)
// Set AllowWIPExercice if WIP exercices are accepted.
var AllowWIPExercice bool = false
func fixnbsp(s string) string {
return strings.Replace(strings.Replace(strings.Replace(s, " ?", " ?", -1), " !", " !", -1), " :", " :", -1)
}
@ -116,6 +119,11 @@ func BuildExercice(i Importer, theme *fic.Theme, epath string, dmap *map[int64]*
}
}
// Character reserved for WIP exercices
if len(e.Title) > 0 && e.Title[0] == '%' {
errs = append(errs, NewExerciceError(e, fmt.Errorf("title can't contain start by '%%'"), theme))
}
e.URLId = fic.ToURLid(e.Title)
e.Title = fixnbsp(e.Title)
@ -207,6 +215,11 @@ func BuildExercice(i Importer, theme *fic.Theme, epath string, dmap *map[int64]*
}
}
e.WIP = p.WIP
if p.WIP && !AllowWIPExercice {
errs = append(errs, NewExerciceError(e, fmt.Errorf("exercice declared Work In Progress in challenge.txt"), theme))
}
if p.Gain == 0 {
errs = append(errs, NewChallengeTxtError(e, 0, fmt.Errorf("Undefined gain for challenge"), theme))
} else {