// Set Value From HTMLForm Values func (t *Tasks) SetValue(Id string, r *http.Request) os.Error { var err os.Error t.UserId = Id t.KeyID, err = strconv.Atoi64(r.FormValue(FORM_KEY)) if err != nil { t.KeyID = 0 } t.Status, err = strconv.Atoi(r.FormValue(FORM_STATUS)) if err != nil { log.Println(err) return err } log.Println("Status") t.Context = html.EscapeString(r.FormValue(FORM_CONTEXT)) t.IsUseLimit, err = strconv.Atob(r.FormValue(FORM_LIMIT)) if err != nil { log.Println(err) return err } log.Println("IsUseLimit") t.IsComplete = (t.Status == 2) t.IsCanceld = (t.Status == 9) log.Println("Set Bool Value") if t.IsUseLimit { log.Println(r.FormValue(FORM_DATE)) log.Println(time.RFC3339) var limit *time.Time limit, err = time.Parse("2006-01-02 15:04:05", r.FormValue(FORM_DATE)) if err == nil { t.PlanDate = datastore.SecondsToTime(limit.Seconds()) } else { log.Println(err) return err } } log.Println("PostDate") t.PostDate = datastore.SecondsToTime(time.Seconds()) if t.IsComplete { t.CompleteDate = datastore.SecondsToTime(time.Seconds()) } return nil }
func registration(w http.ResponseWriter, r *http.Request) { c := appengine.NewContext(r) u := User{ Name: "TestHendrik", StartDate: datastore.SecondsToTime(time.Seconds()), } if g := user.Current(c); g != nil { var u2 User u.Account = g.String() if err := datastore.Get(c, datastore.NewKey("user", g.String(), 0, nil), &u2); err == datastore.ErrNoSuchEntity { key, err := datastore.Put(c, datastore.NewKey("user", u.Account, 0, nil), &u) if err != nil { http.Error(w, err.String(), http.StatusInternalServerError) return } fmt.Fprintf(w, "User %q stored %q", u.Account, key) return } else { fmt.Fprintf(w, "User %q is already logged in", g.String()) return } } else { url, err := user.LoginURL(c, r.URL.String()) if err != nil { http.Error(w, err.String(), http.StatusInternalServerError) return } w.Header().Set("Location", url) w.WriteHeader(http.StatusFound) return } }
func accept_event(w http.ResponseWriter, r *http.Request) { c := appengine.NewContext(r) event, key, err_string := find_single_event(c, r.FormValue("sender"), r.FormValue("date")) if len(err_string) > 0 { fmt.Fprintf(w, err_string) return } if event.OwnerDate > 0 { fmt.Fprintf(w, "This message is already owned by %s.", event.Owner) return } event.OwnerDate = datastore.SecondsToTime(time.Seconds()) event.Owner = "Someone" _, err := datastore.Put(c, key, &event) if err != nil { fmt.Fprintf(w, err.String()) return } else { target_url := fmt.Sprintf("/show?sender=%s&date=%d", event.Sender, event.RecieptDate) http.Redirect(w, r, target_url, http.StatusFound) } }
// articlePost handles saving new/edited pages in the admin manager. It // generates the Article struct based on data submitted by the client, and // then puts it into the datastore. // TODO: Don't need to manually delete old instance, can simply replace it, // so skip that step! func articlePost(w http.ResponseWriter, r *http.Request) { c := appengine.NewContext(r) // Create the article struct based on form data a := Article{ ID: r.FormValue("OldID"), // This may or may not be blank Title: r.FormValue("Title"), Author: user.Current(c).String(), Date: datastore.SecondsToTime(time.Seconds()), Public: true, // TODO: Implement public/private ShortBody: []byte(r.FormValue("ShortBody")), Body: []byte(r.FormValue("Body")), } a.DisplayDate = a.Date.Time().Format("Jan 2") // Set exposed date // If a.ID isn't blank, that means we're updating an article if a.ID != "" { // TODO: Need to remove the delete, and verify things still work err := datastore.Delete(c, datastore.NewKey(c, "Article", a.ID, 0, nil)) check(err) } else { a.ID = newArticleID() } // Add the Article struct to the datastore _, err := datastore.Put(c, datastore.NewKey(c, "Article", a.ID, 0, nil), &a) check(err) // Prints the article back to the client upon access (should come up with // a better way to express success!) fmt.Fprintf(w, "Article: %v\n", a) }
func close_event(w http.ResponseWriter, r *http.Request) { c := appengine.NewContext(r) event, key, err_string := find_single_event(c, r.FormValue("sender"), r.FormValue("date")) if len(err_string) > 0 { fmt.Fprintf(w, err_string) return } // TODO: Check to make sure the closer matches the owner if event.ClosedDate > 0 { fmt.Fprintf(w, "This message is already closed.") return } event.ClosedDate = datastore.SecondsToTime(time.Seconds()) _, err := datastore.Put(c, key, &event) if err != nil { fmt.Fprintf(w, err.String()) return } else { target_url := fmt.Sprintf("/show?sender=%s&date=%d", event.Sender, event.RecieptDate) http.Redirect(w, r, target_url, http.StatusFound) } }
func gamesPost(w http.ResponseWriter, r *http.Request, u *user.User, c appengine.Context) { game := Game{ P1: r.FormValue("player1"), P2: r.FormValue("player2"), Played: datastore.SecondsToTime(time.Seconds()), } scorefields := map[string]int{ "Player1score": 0, "Player2score": 0, } for k, _ := range scorefields { score, err := strconv.Atoi(r.FormValue(k)) if err != nil { http.Error(w, err.String(), http.StatusInternalServerError) return } scorefields[k] = score } game.P1score = scorefields["Player1score"] game.P2score = scorefields["Player2score"] _, err := datastore.Put(c, datastore.NewIncompleteKey("Game"), &game) if err != nil { http.Error(w, err.String(), http.StatusInternalServerError) return } rurl := fmt.Sprintf("http://%v/", r.Host) w.Header().Set("Location", rurl) w.WriteHeader(http.StatusFound) }
func postPosition(w http.ResponseWriter, r *http.Request) { c := appengine.NewContext(r) gid, _ := strconv.Atoi(r.FormValue("gid")) pid, _ := strconv.Atoi(r.FormValue("pid")) lat, _ := strconv.Atoi(r.FormValue("lat")) lng, _ := strconv.Atoi(r.FormValue("lng")) now := datastore.SecondsToTime(time.Seconds()) go savePlayer(c, &Player{pid, gid, lat, lng, now}) q := datastore.NewQuery("Player"). Filter("GameId =", gid) players := make([]Player, 0, 10) for t := q.Run(c); ; { var p Player _, err := t.Next(&p) if err == datastore.Done { break } if err != nil { serveError(c, w, err) return } if p.PlayerId != pid { players = append(players, p) } } m := map[string]interface{}{"players": players, "dead": false} enc := json.NewEncoder(w) enc.Encode(m) }
// 勉強会の追加 func (group *Group) Add(c appengine.Context) os.Error { count := new(Counter) countKey := datastore.NewKey(c, "Counter", "mycounter", 0, nil) countErr := datastore.RunInTransaction(c, func(c appengine.Context) os.Error { err := datastore.Get(c, countKey, count) if err != nil && err != datastore.ErrNoSuchEntity { return err } count.GroupCount++ _, err = datastore.Put(c, countKey, count) return err }, nil) if countErr != nil { return countErr } group.Id = count.GroupCount group.CreateDate = datastore.SecondsToTime(time.Seconds()) key := datastore.NewKey(c, "Group", "", int64(group.Id), nil) _, err := datastore.Put(c, key, group) return err }
func NewCharge(userKey *datastore.Key) *Charge { return &Charge{ datastore.SecondsToTime(time.Seconds()), userKey, 0, 0, } }
func (member *Member) Add(c appengine.Context) os.Error { parent := datastore.NewKey(c, "Group", "", int64(member.Id), nil) key := datastore.NewIncompleteKey(c, "Member", parent) member.CreateDate = datastore.SecondsToTime(time.Seconds()) _, err := datastore.Put(c, key, member) return err }
func (a *ActDetail) toDS() (res *DSActDetail) { res = &DSActDetail{ ActId: a.ActId, Type: a.Type, Name: a.Name, Desc: a.Desc, Location: a.Location, NCadets: a.NCadets, NStaff: a.NStaff, } if a.Start != nil { res.Start = datastore.SecondsToTime(a.Start.Seconds()) } if a.End != nil { res.End = datastore.SecondsToTime(a.End.Seconds()) } return }
// 勉強会の更新 func (group *Group) Put(c appengine.Context) os.Error { group.CreateDate = datastore.SecondsToTime(time.Seconds()) key := datastore.NewKey(c, "Group", "", int64(group.Id), nil) _, err := datastore.Put(c, key, group) return err }
func addLinkHandler(w http.ResponseWriter, r *http.Request) { r.ParseForm() name := r.FormValue("name") url := r.FormValue("url") if !strings.HasPrefix(url, "http://") { url = "http://" + url } location := r.Header.Get("X-AppEngine-country") getStorage(r).Save(Linky{Name: name, URL: url, Location: location, Created: datastore.SecondsToTime(time.Seconds())}) writeTemplate(w, MainPage, &PageModel{FooterMessage: "Link added", LinkyURL: r.Host + "/" + name, StatsURL: r.Host + "/stats/" + name, LinkyName: name}) }
func (score *Score) Set(no int, name string, japanese, math, english int) { score.No = no score.Name = name score.Japanese = japanese score.Math = math score.English = english score.CreateDate = datastore.SecondsToTime(time.Seconds()) // 格納されない値も計算 score.Average = float32(japanese+math+english) / 3 }
func (huser *HowlUser) Create(context appengine.Context) (*datastore.Key, os.Error) { log.Println("Creating user profile for " + huser.Name + " with id " + huser.Uid) huser.Email = user.Current(context).Email huser.LastLogin = datastore.SecondsToTime(time.Seconds()) huser.Streams = make([]*datastore.Key, 0, max_streams) huser.Providers = make([]*datastore.Key, 0, max_providers) huser.SharedStreams = make([]*datastore.Key, 0, max_shared_streams) huser.SharedProviders = make([]*datastore.Key, 0, max_shared_providers) key := datastore.NewKey("HowlUser", huser.Uid, 0, nil) err_s := "Error storing new user profile for " + huser.Uid return put(context, key, err_s, huser) }
func LogAccess(r *http.Request, User string) (accessLog Access, err os.Error) { accessLog = Access{ Date: datastore.SecondsToTime(time.Seconds()), RemoteAddress: r.RemoteAddr, Method: r.Method, URL: r.RawURL, User: User, } c := appengine.NewContext(r) _, err = datastore.Put(c, datastore.NewIncompleteKey("Access"), &accessLog) return // Access, err }
func input(w http.ResponseWriter, r *http.Request) { c := appengine.NewContext(r) var g Guest g.Name = r.FormValue("name") g.Date = datastore.SecondsToTime(time.Seconds()) if _, err := datastore.Put(c, datastore.NewIncompleteKey(c, "Guest", nil), &g); err != nil { http.Error(w, err.String(), http.StatusInternalServerError) return } http.Redirect(w, r, "/", http.StatusFound) }
func handle_test_form(w http.ResponseWriter, r *http.Request) { c := appengine.NewContext(r) event := MailEvent{ Body: r.FormValue("Body"), Sender: r.FormValue("Sender"), RecieptDate: datastore.SecondsToTime(time.Seconds()), } _, err := datastore.Put(c, datastore.NewIncompleteKey("Events"), &event) if err != nil { http.Error(w, err.String(), http.StatusInternalServerError) return } http.Redirect(w, r, "/", http.StatusFound) }
/** * Insert in datastore log * * @author A. Glansbeek en P. Kompier * @version 1.0 * @date 2011-12-22 * @param string de url * @param string de naam van wie url heeft aangeroepen * @param *http.Request * @return os.Error errors */ func SaveLog(url string, viewedby string, r *http.Request) os.Error { c := appengine.NewContext(r) pv := PageView{ Page: url, ViewedBy: viewedby, Date: datastore.SecondsToTime(time.Seconds()), } // Record toevoegen aan de datastore _, err := datastore.Put(c, datastore.NewIncompleteKey(c, "PageView", nil), &pv) // Wanneer er een error optreedt deze terug geven return err }
func handleSign(r *web.Request) { c := gae.Context(r) g := &Greeting{ Content: r.Param.Get("content"), Date: datastore.SecondsToTime(time.Seconds()), } if u := user.Current(c); u != nil { g.Author = u.String() } if _, err := datastore.Put(c, datastore.NewIncompleteKey("Greeting"), g); err != nil { r.Error(web.StatusInternalServerError, err) return } r.Redirect("/", false) }
func sign(w http.ResponseWriter, r *http.Request) { c := appengine.NewContext(r) g := Greeting{ Content: r.FormValue("content"), Date: datastore.SecondsToTime(time.Seconds()), } if u := user.Current(c); u != nil { g.Author = u.String() } _, err := datastore.Put(c, datastore.NewIncompleteKey(c, "Greeting", nil), &g) if err != nil { http.Error(w, err.String(), http.StatusInternalServerError) return } http.Redirect(w, r, "/", http.StatusFound) }
func post(w http.ResponseWriter, r *http.Request) { c := appengine.NewContext(r) g := Picture{ Image: appengine.BlobKey(r.FormValue("picture")), Date: datastore.SecondsToTime(time.Seconds()), } _, err := datastore.Put(c, datastore.NewIncompleteKey("Picture"), &g) if err != nil { http.Error(w, err.String(), http.StatusInternalServerError) } http.Redirect(w, r, "/", http.StatusFound) }
func sign(w http.ResponseWriter, r *http.Request) { c := appengine.NewContext(r) g := Log{ Content: r.FormValue("content"), Date: datastore.SecondsToTime(time.Seconds()), RemoteAddress: r.RemoteAddr, } g.User = requireAnyUser(w, r) _, err := datastore.Put(c, datastore.NewIncompleteKey("Log"), &g) if err != nil { http.Error(w, err.String(), http.StatusInternalServerError) return } http.Redirect(w, r, "/", http.StatusFound) }
// GetQuote retrieves the "ticker" data. func GetQuote(c appengine.Context) (x xgen.Quote, err os.Error) { defer func() { if e, ok := recover().(os.Error); ok { err = e } }() var q Quote err = restapi.GetJson(c, JsonTicker, &q) check(err) x.Date = datastore.SecondsToTime(time.Seconds()) x.HighestBuy = q.Ticker.Buy x.LowestSell = q.Ticker.Sell x.Last = q.Ticker.Last if !x.Validate() { panic("Invalid Ticker") } return }
func save(w http.ResponseWriter, r *http.Request) { c := appengine.NewContext(r) report := Report{ Code: []byte(r.FormValue("code")), Opts: []byte(r.FormValue("data")), Date: datastore.SecondsToTime(time.Seconds()), // Now } key, err := datastore.Put(c, datastore.NewIncompleteKey(c, "report", nil), &report) if err != nil { c.Criticalf(err.String()) renderTemplate(w, "500", nil) return } w.Header().Set("Location", "/reports/"+strconv.Itoa64(key.IntID())) w.WriteHeader(http.StatusFound) }
// Save saves the session in the response. func (s *DatastoreSessionStore) Save(r *http.Request, w http.ResponseWriter, key string, info *sessions.SessionInfo) (flag bool, err error) { sid, serialized, error := getIdAndData(info) if error != nil { err = error return } // Save the session. c := appengine.NewContext(r) entityKey := datastore.NewKey(c, "Session", sessionKey(sid), 0, nil) _, err = datastore.Put(appengine.NewContext(r), entityKey, &Session{ Date: datastore.SecondsToTime(time.Seconds()), Value: serialized, }) if err != nil { return } return sessions.SetCookie(s, w, key, cloneInfo(info, sid)) }
func write(w http.ResponseWriter, r *http.Request) { if r.Method != "POST" { w.WriteHeader(http.StatusNotFound) w.Header().Set("Context-Type", "text/plain; charset=utf-8") fmt.Fprintf(w, "Not Found") return } c := appengine.NewContext(r) // DataStoreへの書き込み var g Guest g.Name = r.FormValue("name") g.Date = datastore.SecondsToTime(time.Seconds()) if _, err := datastore.Put(c, datastore.NewIncompleteKey(c, "Guest", nil), &g); err != nil { http.Error(w, "Internal Server Error : "+err.String(), http.StatusInternalServerError) return } http.Redirect(w, r, "/", http.StatusFound) }
func add(w http.ResponseWriter, r *http.Request) { c := appengine.NewContext(r) u := user.Current(c) if u == nil { url, err := user.LoginURL(c, r.URL.String()) if err != nil { http.Error(w, err.String(), http.StatusInternalServerError) return } w.Header().Set("Location", url) w.WriteHeader(http.StatusFound) return } f := Fact{ Title: r.FormValue("title"), Details: r.FormValue("details"), SourceUrl: r.FormValue("source_url"), SourceName: r.FormValue("source_name"), AddDate: datastore.SecondsToTime(time.Seconds()), User: u.String(), } key, err := datastore.Put(c, datastore.NewIncompleteKey(c, "Fact", nil), &f) if err != nil { http.Error(w, err.String(), http.StatusInternalServerError) return } tags := strings.Split(r.FormValue("tags"), ",") for _, t := range tags { t = strings.TrimSpace(t) t = strings.ToLower(t) fmt.Printf("<%q>\n", t) addTagToFact(c, key, t) } http.Redirect(w, r, "/", http.StatusFound) }
func upload(w http.ResponseWriter, r *http.Request, c appengine.Context, u *user.User) { templateContext := make(map[string]interface{}) if r.Method != "POST" { templateContext["username"] = u.Email renderTemplate(w, "index", templateContext) return } comparison := new(Comparison) comparison.Title = r.FormValue("title") comparison.Left = extractImageFromPost("left_picture", r) comparison.Right = extractImageFromPost("right_picture", r) comparison.Submitter = u.Email comparison.Date = datastore.SecondsToTime(time.Seconds()) // now // Save the comparison under a unique key, a hash of the struct's data key := datastore.NewKey("Comparison", comparison.key(), 0, nil) _, err := datastore.Put(c, key, comparison) check(err) // Redirect to /edit using the key. http.Redirect(w, r, "/show/"+key.StringID(), http.StatusFound) }
func register(w http.ResponseWriter, r *http.Request) { c := appengine.NewContext(r) g := Member{ Usern: r.FormValue("usern"), Name: r.FormValue("name"), Passwd: r.FormValue("passwd"), Repasswd: r.FormValue("repasswd"), Phone: r.FormValue("phone"), Email: r.FormValue("email"), Study: r.FormValue("study"), Address: r.FormValue("address"), Date: datastore.SecondsToTime(time.Seconds()), } if g.Passwd == g.Repasswd && g.Usern != "" && g.Name != "" && g.Phone != "" && g.Email != "" { _, err := datastore.Put(c, datastore.NewIncompleteKey("Member"), &g) if err != nil { http.Error(w, err.String(), http.StatusInternalServerError) return } } else { http.Redirect(w, r, "/signin", http.StatusFound) } http.Redirect(w, r, "/view", http.StatusFound) }