diff --git a/compose/db.env b/compose/db.env index 762f78bb..3a48f6ea 100644 --- a/compose/db.env +++ b/compose/db.env @@ -1,6 +1,6 @@ MYSQL_ROOT_PASSWORD=oef MYSQL_PASSWORD=oef -MYSQL_DATABASE=oef_test +MYSQL_DATABASE=oef_dev MYSQL_USER=oef diff --git a/orm/answer.go b/orm/answer.go index 43b9a55c..9c586370 100644 --- a/orm/answer.go +++ b/orm/answer.go @@ -29,11 +29,11 @@ func (a *Answer) Read(args map[string]string, r *http.Request) (interface{}, err } func (a *Answer) ReadAll(args map[string]string, r *http.Request) (interface{}, error) { - var questions []*Question - if err := DB().Order("created_at").Find(&questions).Error; err != nil { + var answers []*Answer + if err := DB().Order("created_at").Find(&answers).Error; err != nil { return nil, err } - return questions, nil + return answers, nil } func (a *Answer) Update(args map[string]string, r *http.Request) (interface{}, error) { diff --git a/orm/question.go b/orm/question.go index b0f45c76..2715dd59 100644 --- a/orm/question.go +++ b/orm/question.go @@ -21,7 +21,7 @@ func (q *Question) String() string { func (q *Question) Create(args map[string]string, r *http.Request) (interface{}, error) { if r.Method == "GET" { - return make([]*Question, 0), nil + return nil, nil } else { question := new(Question) err := renderer.Decode(question, r) diff --git a/renderer/funcmap.go b/renderer/funcmap.go index 9afa9570..3e05c271 100644 --- a/renderer/funcmap.go +++ b/renderer/funcmap.go @@ -62,8 +62,9 @@ func pluralize(text string) string { return inflection.Plural(text) } -func active(value string, model interface{}) string { - if value == pluralize(lower(modelName(model))) { +func active(value string, options url.Values) string { + model := strings.Title(inflection.Singular(strings.Split(options["tpl_content"][0], "_")[0])) + if value == model { return "active" } return "" diff --git a/renderer/renderer.go b/renderer/renderer.go index 8a38856d..ee0cbcb6 100644 --- a/renderer/renderer.go +++ b/renderer/renderer.go @@ -6,6 +6,7 @@ import ( "fmt" "html/template" "io" + "log" "mime" "net/http" @@ -219,14 +220,16 @@ func Use(r Renderer) { currRenderer = r } -func (rend *HTMLRenderer) writeError(w http.ResponseWriter, r *http.Request, err error) { +func (rend *HTMLRenderer) writeError(w http.ResponseWriter, r *http.Request, data interface{}) { t, ok := rend.templates["error"] if !ok { panic(fmt.Errorf("Error template not found! Can't proceed, sorry.")) } + log.Println(data.(*htmlTemplateData).Data.(error)) + w.Header().Set("Content-Type", "text/html; charset=utf-8") - e := t.ExecuteTemplate(w, "base", err) + e := t.ExecuteTemplate(w, "base", data) if e != nil { panic(e) } @@ -234,16 +237,17 @@ func (rend *HTMLRenderer) writeError(w http.ResponseWriter, r *http.Request, err func (rend *HTMLRenderer) Render(w http.ResponseWriter, r *http.Request, data interface{}, options ...url.Values) { if data != nil && isErrorType(data) { - rend.writeError(w, r, data.(error)) + rend.writeError(w, r, &htmlTemplateData{data.(error), options[0]}) } else { t, ok := rend.templates[options[0]["tpl_content"][0]] if !ok { - rend.writeError(w, r, fmt.Errorf("Template %s not found", options[0]["tpl_content"][0])) + err := fmt.Errorf("Template %s not found", options[0]["tpl_content"][0]) + rend.writeError(w, r, &htmlTemplateData{err, options[0]}) } w.Header().Set("Content-Type", "text/html; charset=utf-8") err := t.ExecuteTemplate(w, options[0]["tpl_layout"][0], &htmlTemplateData{data, options[0]}) if err != nil { - rend.writeError(w, r, err) + rend.writeError(w, r, &htmlTemplateData{err, options[0]}) } } } diff --git a/template_generator/.gitignore b/template_generator/.gitignore index 8f3f22a2..2bd49811 100644 --- a/template_generator/.gitignore +++ b/template_generator/.gitignore @@ -1,2 +1,2 @@ -generator +template_generator test/ diff --git a/template_generator/template_generator b/template_generator/template_generator deleted file mode 100755 index 300a73c1..00000000 Binary files a/template_generator/template_generator and /dev/null differ diff --git a/templates/answers.html.tpl b/templates/answers.html.tpl new file mode 100644 index 00000000..7ef350b4 --- /dev/null +++ b/templates/answers.html.tpl @@ -0,0 +1,33 @@ +{{ define "content" }} + + +
All'attività non è associata alcuna materia + didattica. Clicca qui per + modificare questa attività didattica.
+ {{end}} +