From a8e4ec69bf75a368437b6795b8c5fa573a4af9a5 Mon Sep 17 00:00:00 2001 From: Lars Immisch Date: Tue, 22 Sep 2015 13:33:26 +0200 Subject: [PATCH 1/2] Fix gravatar URL and one possible redirect loop --- realms/lib/util.py | 2 +- realms/modules/auth/views.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/realms/lib/util.py b/realms/lib/util.py index e121ada..0bd115d 100644 --- a/realms/lib/util.py +++ b/realms/lib/util.py @@ -119,7 +119,7 @@ def filename_to_cname(filename): def gravatar_url(email): - return "//www.gravatar.com/avatar/" + hashlib.md5(email).hexdigest() + return "https://www.gravatar.com/avatar/" + hashlib.md5(email).hexdigest() def in_virtualenv(): diff --git a/realms/modules/auth/views.py b/realms/modules/auth/views.py index 4237cdd..6afdc54 100644 --- a/realms/modules/auth/views.py +++ b/realms/modules/auth/views.py @@ -69,4 +69,4 @@ def settings(): @blueprint.route("/logout") def logout(): User.logout() - return redirect("/") + return redirect(url_for(current_app.config['ROOT_ENDPOINT'])) From 9d340e0da1a2cf7c46fb6dc8f51777bc79d5ff45 Mon Sep 17 00:00:00 2001 From: Lars Immisch Date: Tue, 22 Sep 2015 16:37:39 +0200 Subject: [PATCH 2/2] Work around a bug in click Closes https://github.com/scragg0x/realms-wiki/issues/76 --- realms/commands.py | 44 ++++++++++++++++++++++++++++++++++---------- 1 file changed, 34 insertions(+), 10 deletions(-) diff --git a/realms/commands.py b/realms/commands.py index 1a9b3fa..4766b31 100644 --- a/realms/commands.py +++ b/realms/commands.py @@ -51,6 +51,20 @@ def module_exists(module_name): return True +def prompt_and_invoke(ctx, fn): + # This is a workaround for a bug in click. + # See https://github.com/mitsuhiko/click/issues/429 + # This isn't perfect - we are ignoring some information (type mostly) + + kw = {} + + for p in fn.params: + v = click.prompt(p.prompt, p.default, p.hide_input, + p.confirmation_prompt, p.type) + kw[p.name.upper()] = v + + ctx.invoke(fn, **kw) + @cli.command() @click.option('--site-title', default=config.SITE_TITLE, @@ -81,8 +95,8 @@ def module_exists(module_name): type=click.Choice([None, 'simple', 'redis', 'memcached']), prompt='Cache type?') @click.option('--search-type', - default=config.CACHE_TYPE, - type=click.Choice(['simple', 'elasticsearch']), + default=config.SEARCH_TYPE, + type=click.Choice(['simple', 'whoosh', 'elasticsearch']), prompt='Search type?') @click.option('--db-uri', default=config.DB_URI, @@ -105,12 +119,14 @@ def setup(ctx, **kw): conf_path = config.update(conf) if conf['CACHE_TYPE'] == 'redis': - ctx.invoke(setup_redis) + prompt_and_invoke(ctx, setup_redis) elif conf['CACHE_TYPE'] == 'memcached': - ctx.invoke(setup_memcached) + prompt_and_invoke(ctx, setup_memcached) if conf['SEARCH_TYPE'] == 'elasticsearch': - ctx.invoke(setup_elasticsearch) + prompt_and_invoke(ctx, setup_elasticsearch) + elif conf['SEARCH_TYPE'] == 'whoosh': + install_whoosh() green('Config saved to %s' % conf_path) @@ -129,15 +145,17 @@ def setup(ctx, **kw): prompt='Redis host') @click.option('--cache-redis-port', default=getattr(config, 'CACHE_REDIS_POST', 6379), - prompt='Redis port') + prompt='Redis port', + type=int) @click.option('--cache-redis-password', default=getattr(config, 'CACHE_REDIS_PASSWORD', None), prompt='Redis password') @click.option('--cache-redis-db', default=getattr(config, 'CACHE_REDIS_DB', 0), prompt='Redis db') -def setup_redis(**kw): - conf = {} +@click.pass_context +def setup_redis(ctx, **kw): + conf = config.read() for k, v in kw.items(): conf[k.upper()] = v @@ -145,19 +163,21 @@ def setup_redis(**kw): config.update(conf) install_redis() - @click.command() @click.option('--elasticsearch-url', default=getattr(config, 'ELASTICSEARCH_URL', 'http://127.0.0.1:9200'), prompt='Elasticsearch URL') def setup_elasticsearch(**kw): - conf = {} + conf = config.read() for k, v in kw.items(): conf[k.upper()] = v config.update(conf) +cli.add_command(setup_redis) +cli.add_command(setup_elasticsearch) + def get_prefix(): return sys.prefix @@ -175,6 +195,10 @@ def install_redis(): pip.main(['install', 'redis']) +def install_whoosh(): + pip.main(['install', 'Whoosh']) + + def install_mysql(): pip.main(['install', 'MySQL-Python'])