func developerHandler(w io.Writer, r *http.Request) error { ctx := appengine.NewContext(r) if r.Method == "GET" { p, err := NewPage(ctx, "developer", nil) if err != nil { return fmt.Errorf("create developer page: %v", err) } return p.Render(w) } if r.Method != "POST" { return fmt.Errorf("unsupported method %v", r.Method) } switch { case r.FormValue("deleteall") == "yes": kind := r.FormValue("kind") keys, err := datastore.NewQuery(kind).KeysOnly().GetAll(ctx, nil) if err != nil { return fmt.Errorf("get keys to delete: %v", err) } if err := datastore.DeleteMulti(ctx, keys); err != nil { return fmt.Errorf("delete keys: %v", err) } case len(r.FormValue("announcement")) > 0: a := conf.NewAnnouncement(r.FormValue("announcement")) if err := a.Save(ctx); err != nil { return err } } return RedirectTo("/developer") }
func saveConfHandler(w io.Writer, r *http.Request, ctx appengine.Context, u *user.User) error { c, err := confFromRequest(r) if err != nil { return fmt.Errorf("conf from request: %v", err) } err = datastore.RunInTransaction(ctx, func(ctx appengine.Context) error { // Save the conference and generate the tickets if err := c.Save(ctx); err != nil { return fmt.Errorf("save conference: %v", err) } if err := c.CreateAndSaveTickets(ctx); err != nil { return fmt.Errorf("generate tickets: %v", err) } // Announce the conference a := conf.NewAnnouncement(fmt.Sprintf( "A new conference has just been scheduled! %s in %s. Don't wait; book now!", c.Name, c.City)) if err := a.Save(ctx); err != nil { return fmt.Errorf("announce conference: %v", err) } // Queue a task to email interested users. task := taskqueue.NewPOSTTask( "/notifyinterestedusers", url.Values{"conf_id": []string{c.ID()}}, ) if _, err = taskqueue.Add(ctx, task, ""); err != nil { return fmt.Errorf("add task to default queue: %v", err) } // Queue a task to review the conference. task = &taskqueue.Task{ Method: "PULL", Payload: []byte(c.ID()), } task, err := taskqueue.Add(ctx, task, "review-conference-queue") if err != nil { return fmt.Errorf("add task to review queue: %v", err) } return nil }, &datastore.TransactionOptions{XG: true}) if err != nil { return err } return RedirectTo("/showtickets?conf_id=" + url.QueryEscape(c.ID())) }