diff options
author | Evgeny Fadeev <evgeny.fadeev@gmail.com> | 2012-11-19 00:20:58 -0300 |
---|---|---|
committer | Evgeny Fadeev <evgeny.fadeev@gmail.com> | 2012-11-19 00:20:58 -0300 |
commit | 1e597a8ee8cd2db3c37c8715410e81cc1972ddc3 (patch) | |
tree | ec9bd804faefe93a4e83bf06057e311ff3a7b3fe /askbot/utils | |
parent | e0dcb50e48b25f7fe641d54b5338e09486b7157e (diff) | |
download | askbot-1e597a8ee8cd2db3c37c8715410e81cc1972ddc3.tar.gz askbot-1e597a8ee8cd2db3c37c8715410e81cc1972ddc3.tar.bz2 askbot-1e597a8ee8cd2db3c37c8715410e81cc1972ddc3.zip |
added mandatory generation of secret key to askbot-setup
Diffstat (limited to 'askbot/utils')
-rw-r--r-- | askbot/utils/console.py | 8 | ||||
-rw-r--r-- | askbot/utils/functions.py | 12 |
2 files changed, 18 insertions, 2 deletions
diff --git a/askbot/utils/console.py b/askbot/utils/console.py index 644a7f21..23cff6f9 100644 --- a/askbot/utils/console.py +++ b/askbot/utils/console.py @@ -34,6 +34,7 @@ def choice_dialog(prompt_phrase, choices = None, invalid_phrase = None): print invalid_phrase % {'opt_string': opt_string} time.sleep(1) + def simple_dialog(prompt_phrase, required=False): """asks user to enter a string, if `required` is True, will repeat question until non-empty input is given @@ -49,6 +50,13 @@ def simple_dialog(prompt_phrase, required=False): return response time.sleep(1) + + +def get_yes_or_no(prompt_phrase): + while True: + response = raw_input(prompt_phrase + ' (yes/no)\n> ').strip() + if response in ('yes', 'no'): + return response def open_new_file(prompt_phrase, extension = '', hint = None): diff --git a/askbot/utils/functions.py b/askbot/utils/functions.py index f9d36534..2579728b 100644 --- a/askbot/utils/functions.py +++ b/askbot/utils/functions.py @@ -1,8 +1,8 @@ import re +import random import datetime from django.utils.translation import ugettext as _ from django.utils.translation import ungettext -from django.contrib.auth.models import User def get_from_dict_or_object(source, key): try: @@ -162,8 +162,16 @@ def setup_paginator(context): } def get_admin(): - '''Returns an admin users, usefull for raising flags''' + """Returns an admin users, usefull for raising flags""" try: + from django.contrib.auth.models import User return User.objects.filter(is_superuser=True)[0] except: raise Exception('there is no admin users') + +def generate_random_key(length=16): + """return random string, length is number of characters""" + random.seed() + assert(isinstance(length, int)) + format_string = '%0' + str(2*length) + 'x' + return format_string % random.getrandbits(length*8) |