Exemplo n.º 1
0
//New returns a pointer to a TimeConfig with its fields set according to arguments.
func New(date, on, off time.Time) (tc *TimeConfig) {
	tc = new(TimeConfig)
	tc.Date = util.NormalizeDate(date)
	tc.Off = util.NormalizeTime(off)
	tc.On = util.NormalizeTime(on)
	return
}
Exemplo n.º 2
0
//TimeOverrideSubmit handles saving of time overrides into Datastore.
func TimeOverrideSubmit(c util.Context) (err error) {
	date, err := time.Parse(dateFormat, c.R.FormValue("date"))
	if err != nil {
		return
	}

	on, err := time.Parse(timeFormat, c.R.FormValue("on"))
	if err != nil {
		return
	}

	off, err := time.Parse(timeFormat, c.R.FormValue("off"))
	if err != nil {
		return
	}
	tc := timeConfig.New(util.NormalizeDate(date), util.NormalizeTime(on), util.NormalizeTime(off))
	var k *datastore.Key
	if _, ok := c.Vars["id"]; ok {
		k, err = datastore.DecodeKey(c.Vars["id"])
		if err != nil {
			return
		}
	} else {
		k = nil
	}
	tc.SetKey(k)
	err = tc.Save(c)
	if err != nil {
		return
	}
	http.Redirect(c.W, c.R, "/admin/config", 303)
	return
}
Exemplo n.º 3
0
//Save saves a TimeConfig to Datastore.
//If its Key field is set, it will replace an existing record
//that has that key. If not, it will use datastore.NewIncompleteKey()
//to create a new key and set the field.
func (tc *TimeConfig) Save(c appengine.Context) (err error) {
	tc.Date = util.NormalizeDate(tc.Date)
	tc.Off = util.NormalizeTime(tc.Off)
	tc.On = util.NormalizeTime(tc.On)
	err = gaemodel.Save(c, tc)
	if err != nil {
		return
	}

	err = config.UpdateTimestamp(c)
	return
}