Skip to content

Commit

Permalink
move recaptcha only methods inline
Browse files Browse the repository at this point in the history
  • Loading branch information
hornc committed Apr 8, 2016
1 parent 213ff1e commit 2d7a034
Showing 1 changed file with 15 additions and 17 deletions.
32 changes: 15 additions & 17 deletions openlibrary/plugins/upstream/addbook.py
Expand Up @@ -51,6 +51,21 @@ def get_authors_solr():


def get_recaptcha():
def is_old_user():
"""Check to see if account is more than two years old."""
user = web.ctx.site.get_user()
account = user and user.get_account()
if not account:
return False
create_dt = account.creation_time()
now_dt = datetime.datetime.utcnow()
delta = now_dt - create_dt
return delta.days > 365*2

def is_plugin_enabled(name):
plugin_names = delegate.get_plugins()
return name in plugin_names or "openlibrary.plugins." + name in plugin_names

if is_plugin_enabled('recaptcha') and not is_old_user():
public_key = config.plugin_recaptcha.public_key
private_key = config.plugin_recaptcha.private_key
Expand All @@ -60,23 +75,6 @@ def get_recaptcha():
return recap


def is_old_user():
"""Check to see if account is more than two years old."""
user = web.ctx.site.get_user()
account = user and user.get_account()
if not account:
return False
create_dt = account.creation_time()
now_dt = datetime.datetime.utcnow()
delta = now_dt - create_dt
return delta.days > 365*2


def is_plugin_enabled(name):
plugin_names = delegate.get_plugins()
return name in plugin_names or "openlibrary.plugins." + name in plugin_names


def make_work(doc):
w = web.storage(doc)
w.key = "/works/" + w.key
Expand Down

0 comments on commit 2d7a034

Please sign in to comment.