def POST(self): form = web.input() patron_name = form.get("name", "") email = form.get("email", "") topic = form.get("topic", "") description = form.get("question", "") url = form.get("url", "") user = accounts.get_current_user() useragent = web.ctx.env.get("HTTP_USER_AGENT", "") if not all([email, topic, description]): return "" hashed_ip = hashlib.md5(web.ctx.ip.encode('utf-8')).hexdigest() has_emailed_recently = get_memcache().get('contact-POST-%s' % hashed_ip) if has_emailed_recently: recap = get_recaptcha() if recap and not recap.validate(): return render_template( "message.html", 'Recaptcha solution was incorrect', ('Please <a href="javascript:history.back()">go back</a> and try ' 'again.'), ) default_assignees = config.get("support_default_assignees", {}) topic_key = str(topic.replace(" ", "_").lower()) if topic_key in default_assignees: assignee = default_assignees.get(topic_key) else: assignee = default_assignees.get("default", "*****@*****.**") stats.increment("ol.support.all") subject = "Support case *%s*" % topic url = web.ctx.home + url displayname = user and user.get_name() or "" username = user and user.get_username() or "" message = SUPPORT_EMAIL_TEMPLATE % locals() sendmail(email, assignee, subject, message) get_memcache().set('contact-POST-%s' % hashed_ip, "true", time=15 * MINUTE_SECS) return render_template("email/case_created", assignee)
def GET(self): i = web.input(path=None) user = accounts.get_current_user() email = user and user.email hashed_ip = hashlib.md5(web.ctx.ip.encode('utf-8')).hexdigest() has_emailed_recently = get_memcache().get('contact-POST-%s' % hashed_ip) recaptcha = has_emailed_recently and get_recaptcha() return render_template("support", email=email, url=i.path, recaptcha=recaptcha)
def GET_memcache(self): i = web.input() i.setdefault("keys", "") from openlibrary.core import cache mc = cache.get_memcache() keys = [k.strip() for k in i["keys"].split() if k.strip()] mapping = keys and mc.get_multi(keys) return render_template("admin/inspect/memcache", keys, mapping)
def GET_memcache(self): i = web.input(action="read") i.setdefault("keys", "") mc = cache.get_memcache() keys = [k.strip() for k in i["keys"].split() if k.strip()] if i.action == "delete": mc.delete_multi(keys) add_flash_message("info", "Deleted %s keys from memcache" % len(keys)) return render_template("admin/inspect/memcache", [], {}) else: mapping = keys and mc.get_multi(keys) return render_template("admin/inspect/memcache", keys, mapping)