func CreateTeacher(w http.ResponseWriter, r *http.Request, _ httprouter.Params) {
	redirected, _ := ensureLoggedIn(w, r)
	if redirected {
		return
	}

	// Parse and validate.
	r.ParseForm()
	short := html.EscapeString(r.Form.Get("short"))
	name := html.EscapeString(r.Form.Get("name"))
	sex := html.EscapeString(r.Form.Get("sex"))

	valid, message := validateTeacherData(short, name, sex)
	if valid {
		teacher := model.Teacher{Short: short}
		if teacher.Exists() {
			message = fmt.Sprintf("Es gibt bereits einen Lehrer mit dem Kürzel %s.", short)
			valid = false
		}
	}

	// Render message if the data is not valid.
	if !valid {
		template, err := template.ParseFiles("templates/base.html", "templates/teacher/new.html")
		if err != nil {
			log.Printf("error: %v\n", err)
		}

		err = template.Execute(w, simpleMessage(message, false))
		if err != nil {
			log.Printf("error: %v\n", err)
		}
		return
	}

	// Create the teacher.
	teacher := model.Teacher{Short: short, Name: name, Sex: sex}
	teacher.Create()

	unknown := model.UnknownTeacher{Short: short}
	unknown.Delete()

	// Render all teachers
	message = fmt.Sprintf("%s wurde gespeichert.", short)
	showTeachers(w, r, message)
}
// CreateTeacher creates a new teacher and serves the list of all teachers.
CreateTeacher creates a new teacher and serves the list of all teachers.
// CreateTeacher creates a new teacher and serves the list of all teachers .
func CreateTeacher(w http.ResponseWriter, r *http.Request, _ httprouter.Params) {
	redirected, _ := ensureLoggedIn(w, r)
	if redirected {
		return
	}
	r.ParseForm()
	short := html.EscapeString(r.Form.Get("short"))
	name := html.EscapeString(r.Form.Get("name"))
	sex := html.EscapeString(r.Form.Get("sex"))
	valid, message := validateTeacherData(short, name, sex)
	if valid {
		teacher := model.Teacher{Short: short}
		if teacher.Exists() {
			message = fmt.Sprintf("Es gibt bereits einen Lehrer mit dem Kürzel %s.", short)
			valid = false
		}
	}
	if !valid {
		template, err := template.ParseFiles("templates/base.html", "templates/teacher/new.html")
		if err != nil {
			log.Printf("error: %v\n", err)
		}
		err = template.Execute(w, simpleMessage(message, false))
		if err != nil {
			log.Printf("error: %v\n", err)
		}
		return
	}
	teacher := model.Teacher{Short: short, Name: name, Sex: sex}
	teacher.Create()
	unknown := model.UnknownTeacher{Short: short}
	unknown.Delete()
	message = fmt.Sprintf("%s wurde gespeichert.", short)
	showTeachers(w, r, message)
}
func CreateTeacher ( w http . ResponseWriter , r * http . Request , _ httprouter . Params ) { redirected , _ := ensureLoggedIn ( w , r ) if redirected { return } r . ParseForm ( ) short := html . EscapeString ( r . Form . Get ( " " ) ) name := html . EscapeString ( r . Form . Get ( " " ) ) sex := html . EscapeString ( r . Form . Get ( " " ) ) valid , message := validateTeacherData ( short , name , sex ) if valid { teacher := model . Teacher { Short : short } if teacher . Exists ( ) { message = fmt . Sprintf ( " , hort) valid = false } } if ! valid { template , err := template . ParseFiles ( " " , " " ) if err != nil { log . Printf ( " \n " , err ) } err = template . Execute ( w , simpleMessage ( message , false ) ) if err != nil { log . Printf ( " \n " , err ) } return } teacher := model . Teacher { Short : short , Name : name , Sex : sex } teacher . Create ( ) unknown := model . UnknownTeacher { Short : short } unknown . Delete ( ) message = fmt . Sprintf ( " " , short ) showTeachers ( w , r , message ) }
CreateTeacher creates a new teacher and serves the list of all teachers.
CreateTeacher creates a new teacher and serves the list of all teachers .
// Parse and validate. // Render message if the data is not valid. // Create the teacher. // Render all teachers