def profile_or_home(): try: if web.input().profile: return web.seeother("/profile/%s" % web.input().profile) except: pass return web.seeother('/home')
def POST(self): user = db.GqlQuery("SELECT * FROM User WHERE goog = :1", users.get_current_user()).get() if not user: valid_name_regexp = re.compile(r"[a-z]+[a-z_0-9]+") if valid_name_regexp.match(web.input().name): user = User(key_name=web.input().name) user.goog = users.get_current_user() user.name = web.input().name if user.put(): return profile_or_home() return render.welcome() return profile_or_home()
def POST(self): user = db.GqlQuery("SELECT * FROM User WHERE goog = :1", users.get_current_user()).get() if not user: valid_name_regexp = re.compile(r"[a-z]+[a-z_0-9]+") if not valid_name_regexp.match(web.input().name): return web.seeother('/welcome') user = User(key_name=web.input().name) user.goog = users.get_current_user() user.name = web.input().name if user.put(): return web.seeother("/users/%s" % user.name) else: return web.seeother('/welcome') return web.seeother("/users/%s" % user.name)
def POST(self): user = db.GqlQuery("SELECT * FROM User WHERE goog = :1", users.get_current_user()).get() if not user: user = User() user.goog = users.get_current_user() user.name = web.input().name user.put() # FIXME: uniq on name return web.seeother("/")
def POST(self, key): i = web.input() comment = Comment.get(key) comment.name = i.name comment.body = i.body comment.body_html = sanitize.html(i.body) comment.url = i.url comment.put() return web.seeother("/articles/" + comment.article.slug)
def POST(self, name): page = db.GqlQuery("SELECT * FROM Page WHERE name = :1", name).get() if not page: page = Page(name=name) page.body = web.input().body page.updated = datetime.datetime.now() page.put() PageVersion(page=page, body=page.body).put() return web.seeother('/wiki/'+page.name)
def POST(self): i = web.input() article = Article() article.title = i.title article.slug = i.slug article.body = i.body # article.created = datetime.datetime.strptime(i.created.split('.')[0], '%Y-%m-%d %H:%M:%S') article.tags = [x.strip() for x in i.tags.split(",")] article.put() return web.seeother("/articles/" + article.slug)
def POST(self, slug): key = db.Key.from_path("Redirect", slug) item = Redirect.get(key) if not item: item = Redirect(key_name=slug) i = web.input() item.url = i.url item.slug = slug item.put() return web.seeother("/admin")
def POST(self, key): i = web.input() topic = Topic.get(key) post = Post() post.topic = topic post.body = i.body post.body_html = sanitize.html(i.body) post.user = users.get_current_user() post.put() return web.seeother("/forum/%s" % topic.key())
def POST(self, slug): if not users.is_current_user_admin(): return web.seeother("/") forum = Forum(key_name=slug) i = web.input() forum.slug = slug forum.name = i.name forum.description = i.description forum.put() return web.seeother("%s/forum" % slug)
def POST(self, slug): i = web.input() articles = db.GqlQuery("SELECT * FROM Article WHERE slug = :1", slug) article = articles.get() article.title = i.title article.slug = i.slug article.body = i.body article.created = datetime.datetime.strptime(i.created.split(".")[0], "%Y-%m-%d %H:%M:%S") article.tags = [x.strip() for x in i.tags.split(",")] article.put() return web.seeother("/articles/" + article.slug)
def GET(self): offset = int(web.input().offset) comments = Comment.all().fetch(limit=40, offset=offset) for comment in comments: comment.body_html = sanitize.html(comment.body) comment.put() cnt = Comment.all().count() if offset + 40 < cnt: return "<a href='/admin/fix?offset=%s'>next</a>" % (offset + 40) else: return "done"
def GET(self, key): try: if web.input().login: return web.seeother(users.create_login_url("/welcome?profile=%s" % key)) except: pass profile = Profile.get(key) nonce = uuid.uuid4().hex goog = users.get_current_user() if profile: return render.profile(profile, nonce, goog) else: return web.seeother('/')
def POST(self, slug, key): i = web.input() topic = Topic.get(key) post = Post() post.topic = topic post.body = i.body post.body_html = sanitize.html(i.body) post.user = users.get_current_user() post.put() if post.is_saved(): topic.last_post = post.created topic.put() return web.seeother("%s/forum/%s" % (slug, topic.key()))
def POST(self, slug): if not users.is_current_user_admin(): return web.seeother('/') key = db.Key.from_path('Page', slug) page = Page.get(key) if page == None: page = Page(key_name=slug) i = web.input() page.slug = slug page.title = i.title page.body = i.body page.put() return web.seeother(slug)
def POST(self, mid): extension = db.GqlQuery("SELECT * FROM Extension WHERE mid = :1", mid)[0] for rec in extension.extensionrecommendation_set.fetch(100): rec.delete() added = 0 for mid in web.input().recommended.split("/"): recommended = db.GqlQuery("SELECT * FROM Extension WHERE mid = :1", mid)[0] er = ExtensionRecommendation(recommended=recommended, extension=extension) er.put() added += 1 return "Extension: %s now has %s recommendations" % (extension.name, added)
def POST(self): if not users.get_current_user(): web.ctx.status = "401 Unauthorized" return user = db.GqlQuery("SELECT * FROM User WHERE goog = :1", users.get_current_user()).get() if not user: web.ctx.status = "401 Unauthorized" return # Build a dictionary of the user's current extensions user_extensions = db.GqlQuery("SELECT * FROM UserExtension WHERE user = :1", user) ux_dict = {} for e in user_extensions: ux_dict[e.extension.mid] = e web.debug(ux_dict) i = web.input() json = simplejson.loads(i.data) for mid in json: web.debug("processing " + mid) key = db.Key.from_path("Extension", mid) extension = Extension.get(key) if not extension: web.debug("new extension: " + mid) extension = Extension(key_name=mid) extension.mid = mid extension.name = json[mid]["name"] extension.icon_url = json[mid]["icon"] extension.put() if ux_dict.has_key(mid): web.debug("user had extension " + mid) ux_dict[mid].version = json[mid]["version"] ux_dict[mid].put() del ux_dict[mid] else: web.debug("user did not have extension " + mid) ux = UserExtension() ux.extension = extension ux.version = json[mid]["version"] ux.user = user ux.put() # Delete any user extensions from the database that weren't in the update for ux in ux_dict: web.debug("user no longer has extension " + mid) ux_dict[ux].delete() web.ctx.status = "200 OK" return
def POST(self, slug): if not users.is_current_user_admin(): return web.seeother("/") key = db.Key.from_path("Page", slug) page = Page.get(key) if not page: page = Page(key_name=slug) i = web.input() page.slug = slug page.title = i.title page.body = i.body page.metaDescription = i.metaDescription page.put() return web.seeother(slug)
def POST(self, key): goog = users.get_current_user() if not goog: return web.seeother('/') profile = Profile.get(key) if not profile: web.debug("no such profile") return web.seeother('/') challenge = web.input().challenge response = web.input().response secret = profile.secret expected_response = md5.new(challenge + secret).hexdigest() web.debug("response = " + response + ", expected = " + expected_response) user = db.GqlQuery("SELECT * FROM User WHERE goog = :1", goog).get() if (expected_response == response) and user: web.debug("own the profile") profile.user = user profile.put() return web.seeother("/users/%s" % user.name) else: web.debug("unauthorized") web.ctx.status = "401 unauthorized" return web.seeother('/')
def POST(self, tag): i = web.input() topic = Topic() topic.title = i.title topic.tags = [tag] topic.user = users.get_current_user() topic.put() post = Post() post.topic = topic post.body = i.body post.body_html = sanitize.html(i.body) post.user = users.get_current_user() post.put() return web.seeother("/forum/%s/%s" % (tag, topic.key()))
def POST(self): user = users.get_current_user() i = web.input() json = simplejson.loads(i.data) for mid in json: key = db.Key.from_path('Extension', mid) ux = UserExtension() extension = Extension.get(key) if not extension: extension = Extension(key_name=mid) extension.mid = mid extension.name = json[mid]['name'] # extension.icon_url = json[mid]['icon_url'] extension.put() ux.extension = extension ux.version = json[mid]['version'] ux.user = user ux.put() web.ctx.status = "200 OK" return
def POST(self, slug): key = db.Key.from_path('Forum', slug) forum = Forum.get(key) if not forum: return render.seeother('/') i = web.input() topic = Topic() topic.forum = forum topic.title = i.title topic.user = users.get_current_user() topic.put() post = Post() post.topic = topic post.body = i.body post.body_html = sanitize.html(i.body) post.user = users.get_current_user() post.put() return web.seeother("%s/forum/%s" % (slug, topic.key()))
def POST(self): i = web.input() slug = i.slug articles = db.GqlQuery("SELECT * FROM Article WHERE slug = :1", slug) article = articles.get() #result = captcha.submit(i.recaptcha_challenge_field, i.recaptcha_response_field, PRIV, web.ctx['ip']) #if not result.is_valid: # return render.captcha() comment = Comment() comment.article = article comment.name = i.name comment.email = i.email comment.body = i.body # comment.created = datetime.datetime.strptime(i.created.split('.')[0], '%Y-%m-%d %H:%M:%S') comment.body_html = sanitize.html(i.body) comment.url = sanitize.url(i.url) comment.raw = web.data() comment.put() return web.seeother('/articles/'+article.slug)
def POST(self, key=None): web.debug("hi: %s" % key) send_welcome = False json = simplejson.loads(web.input().data) if key and key != '': profile = Profile.get(key) if profile: sig = web.input().sig data = web.data() expected = md5.new(data + profile.secret).hexdigest() if sig != expected: web.ctx.status = "401 Unauthorized" return "Invalid Signature" else: send_welcome = 410 else: send_welcome = 200 if send_welcome: secret_uuid = uuid.uuid4() profile = Profile(secret=secret_uuid.hex) profile.version = json['system']['version'] profile.os = json['system']['OS'] profile.platform = json['system']['name'] profile.put() web.debug("profile: %s" % profile) # Build a dictionary of the current extensions profile_extensions = profile.profileextension_set.fetch(100) px_dict = {} for e in profile_extensions: px_dict[e.extension.mid] = e web.debug(px_dict) local_extensions = json['extensions'] for mid in local_extensions: local_extension = local_extensions[mid] web.debug("processing " + mid) key = db.Key.from_path('Extension', mid) extension = Extension.get(key) if not extension: web.debug("new extension: " + mid) extension = Extension(key_name=mid) extension.mid = mid extension.name = local_extension['name'] extension.updateRDF = local_extension['updateRDF'] extension.description = local_extension['description'] extension.creator = local_extension['creator'] extension.homepageURL = local_extension['homepageURL'] extension.developers = local_extension['developers'] extension.translators = local_extension['translators'] extension.contributors = local_extension['contributors'] extension.put() if px_dict.has_key(mid): web.debug("user had extension " + mid) px_dict[mid].version = local_extension['version'] px_dict[mid].put() del px_dict[mid] else: web.debug("user did not have extension " + mid) px = ProfileExtension() px.extension = extension px.version = local_extension['version'] px.profile = profile px.put() # Delete any user extensions from the database that weren't in the update for px in px_dict: web.debug("user no longer has extension " + mid) px_dict[px].delete() web.debug("profile key: %s" % profile.key()) if send_welcome: web.ctx.status = "%s New Profile" % send_welcome web.header('Content-Type', 'text/x-json') return simplejson.dumps({'profile': str(profile.key()), 'secret': profile.secret}) else: web.ctx.status = "200 OK" return "KTHXBAI"
def POST(self): i = web.input() person = Person() person.name = i.name person.put() return web.seeother('/list')