def get(self, special_day_id=None): user = users.get_current_user() if user and is_trusted_user(user): day = SpecialDay.get(special_day_id) if day: self.response.headers['Content-Type'] = 'application/json; charset=utf-8' special_things = [{"thing": cgi.escape(t.thing), "added": t.added()} for t in get_special_things(day=day)] self.response.out.write(simplejson.dumps(special_things)) else: self.redirect('/') else: self.redirect("/")
def get(self, special_day_id=None): user = users.get_current_user() if user and is_trusted_user(user): day = SpecialDay.get(special_day_id) if day: special_things = [{"thing": cgi.escape(t.thing), "added": t.added()} for t in get_special_things(day=day)] path = os.path.join(os.path.dirname(__file__), 'specialday.html') self.response.out.write(template.render(path, { 'version': MEDIA_VERSION, 'day': day, 'special_things': simplejson.dumps(special_things) })) else: self.redirect('/') else: path = os.path.join(os.path.dirname(__file__), 'notallowed.html') self.response.out.write(template.render(path, {}))
def post(self, special_day_id=None): user = users.get_current_user() if user and is_trusted_user(user): self.response.headers['Content-Type'] = 'application/json; charset=utf-8' try: day = SpecialDay.get(self.request.get("specialdayid")) if day: new_thing = self.request.get("newthing") thing = SpecialThing(day=day, thing=new_thing, user=user) thing.put() self.response.out.write(simplejson.dumps({ "status": True, "message": "Sweet! Your special thing was added." })) else: raise except: self.response.out.write(simplejson.dumps({ "status": False, "message": "Damn! There was a problem adding your special thing. \ Please try again." })) else: self.redirect("/")