|
@@ -6,7 +6,6 @@ import (
|
|
|
"log"
|
|
|
"os"
|
|
|
"path/filepath"
|
|
|
- "strings"
|
|
|
"sync"
|
|
|
"text/template"
|
|
|
"time"
|
|
@@ -15,6 +14,7 @@ import (
|
|
|
|
|
|
karmen_client "gogs.carducci-dante.gov.it/karmen/client"
|
|
|
"gogs.carducci-dante.gov.it/karmen/core/config"
|
|
|
+ "gogs.carducci-dante.gov.it/karmen/core/generator/funcmap"
|
|
|
"gogs.carducci-dante.gov.it/karmen/core/orm"
|
|
|
"gogs.carducci-dante.gov.it/karmen/util/fileutil"
|
|
|
"gogs.carducci-dante.gov.it/karmen/util/libreoffice"
|
|
@@ -53,13 +53,6 @@ func (l *JobLogger) Write(p []byte) (n int, err error) {
|
|
|
return origLen, nil
|
|
|
}
|
|
|
|
|
|
-var funcMap template.FuncMap = template.FuncMap{
|
|
|
- "comma": comma,
|
|
|
- "groupClasses": groupClasses,
|
|
|
- "abbrev": abbrev,
|
|
|
- "nbsp": nbsp,
|
|
|
-}
|
|
|
-
|
|
|
func (generator *ListGenerator) generate(outputPath string, cloudPath string, teachers []*orm.Teacher, funcMap template.FuncMap) {
|
|
|
filename := filepath.Join(outputPath, "elenco_docenti")
|
|
|
|
|
@@ -112,58 +105,6 @@ func (generator *ListGenerator) generate(outputPath string, cloudPath string, te
|
|
|
|
|
|
}
|
|
|
|
|
|
-func comma(classes []*orm.Class) string {
|
|
|
- var names []string
|
|
|
- for _, c := range classes {
|
|
|
- names = append(names, c.Name)
|
|
|
- }
|
|
|
- return strings.Join(names, ",")
|
|
|
-}
|
|
|
-
|
|
|
-func abbrev(name string) string {
|
|
|
- var result string
|
|
|
- splits := strings.Split(name, " ")
|
|
|
- for i := len(splits) - 1; i >= 0; i-- {
|
|
|
- if i == len(splits)-1 {
|
|
|
- result += splits[i] + " "
|
|
|
- continue
|
|
|
- }
|
|
|
- result += strings.ToUpper(string(splits[i][0]) + ".")
|
|
|
- }
|
|
|
- return result
|
|
|
-}
|
|
|
-
|
|
|
-func nbsp(num int, text string) string {
|
|
|
- return text + strings.Repeat(" ", num)
|
|
|
-}
|
|
|
-
|
|
|
-func groupClasses(classes []*orm.Class) string {
|
|
|
- var groups []string
|
|
|
-
|
|
|
- groupByAddresses := make(map[string][]string)
|
|
|
- addressesAbbrev := map[string]string{
|
|
|
- "Linguistico": "LIN",
|
|
|
- "Classico": "CLA",
|
|
|
- "Musicale": "M",
|
|
|
- "Economico sociale": "ES",
|
|
|
- "Scienze umane": "SU",
|
|
|
- }
|
|
|
- for _, c := range classes {
|
|
|
- groupByAddresses[c.Field] = append(groupByAddresses[c.Field], fmt.Sprintf("%d%s", c.Year, c.Section))
|
|
|
- }
|
|
|
-
|
|
|
- for address, classes := range groupByAddresses {
|
|
|
- var group string
|
|
|
- if len(classes) > 1 {
|
|
|
- group = fmt.Sprintf("[%s]%s", strings.Join(classes, ","), addressesAbbrev[address])
|
|
|
- } else {
|
|
|
- group = fmt.Sprintf("%s %s", strings.Join(classes, ","), addressesAbbrev[address])
|
|
|
- }
|
|
|
- groups = append(groups, group)
|
|
|
- }
|
|
|
- return strings.Join(groups, ",")
|
|
|
-}
|
|
|
-
|
|
|
func NewListGenerator(config *config.ConfigT) *ListGenerator {
|
|
|
return &ListGenerator{Config: config}
|
|
|
}
|
|
@@ -236,7 +177,7 @@ func (generator *ListGenerator) Run() {
|
|
|
log.Println(err)
|
|
|
}
|
|
|
|
|
|
- generator.generate(outputPath, cloudPath, teachers, funcMap)
|
|
|
+ generator.generate(outputPath, cloudPath, teachers, funcmap.FuncMap)
|
|
|
|
|
|
if generator.JobID > 0 {
|
|
|
job.End = time.Now()
|