Exemple #1
0
 def handle(self, *args, **options):
     users = User.objects.all()
     
     n = 0
     for user in users:
         try:
             RegistrationKey.objects.get(user__email=user.email)
         except RegistrationKey.DoesNotExist:
             RegistrationKey.objects.create(key=generate_secret_key(12), user=user)
             n += 1
     
     self.stdout.write("Created %d new keys" % n)
Exemple #2
0
    def handle(self, *args, **options):
        users = User.objects.all()

        n = 0
        for user in users:
            try:
                RegistrationKey.objects.get(user__email=user.email)
            except RegistrationKey.DoesNotExist:
                RegistrationKey.objects.create(key=generate_secret_key(12),
                                               user=user)
                n += 1

        self.stdout.write("Created %d new keys" % n)
def add_event(short_name='', name='', secret_key='', url='', start_time=None, end_time=None):
    """
    Get event information and add it to Redis
    :param short_name: Id/short name
    :param name: Display name
    :param secret_key: Secret key for removing
    :param url: URL for redirection
    :param start_time: Python datetime object of event start time
    :param end_time: Python datetime object of event end time
    """

    # Generate new secret key if it's not provided
    if not secret_key:
        secret_key = generate_secret_key(allowed_characters=app.config['SECRET_KEY_CHARACTERS'])

    # Convert datetime objects to timestamp seconds
    start_seconds = datetime_to_seconds(start_time)
    end_seconds = datetime_to_seconds(end_time)

    # Setup dictionary of event information to save
    event_info = {
        'short_name': short_name,
        'name': name,
        'url': url,
        'secret_key': secret_key,
        'start_time': start_seconds,
        'end_time': end_seconds
    }

    redis_instance = app.extensions['redis']['REDIS']

    # Setup Redis transaction
    pipe = redis_instance.pipeline()

    # Add commands to transaction
    pipe.hmset(app.config['REDIS_KEY_EVENT_INFO'] % short_name, event_info)
    pipe.expireat(app.config['REDIS_KEY_EVENT_INFO'] % short_name, end_time)

    pipe.zadd(app.config['REDIS_KEY_EVENT_START'], short_name, start_seconds)
    pipe.zadd(app.config['REDIS_KEY_EVENT_END'], short_name, end_seconds)

    # Execute and return True if no Falses in Redis multi bulk reply
    return False not in pipe.execute()
Exemple #4
0
    def extract_settings_from_options(self, options):
        settings = {}

        settings['ENV'] = options.get('env') or utils.get_env_name()

        if not settings['ENV']:
            raise InstallError(
                'Could not extract env name from path and none specified.'
            )

        pyfile = settings['ENV'] + '.py'
        if not os.path.isfile(utils.get_settings_file(pyfile)):
            warnings.warn(
                'Could not find settings file for env named {}'
                .format(pyfile),
            )

        settings['DEBUG'] = (
            settings['ENV'] == 'development' or options.get('DEBUG')
        )

        settings['INSTANCE_NAME'] = utils.get_default(
            options,
            'instance_name',
            utils.get_instance_name(),
        )

        if not settings['INSTANCE_NAME']:
            raise InstallError(
                'Could not extract instance name from path and none specified.'
             )

        settings['SECRET_KEY'] = utils.get_default(
            options,
            'secret_key',
            utils.generate_secret_key(options.get('secret_key_length'))
        )

        settings['DATABASE_NAME'] = utils.get_default(
            options,
            'db_name',
            settings['INSTANCE_NAME'],
        )
        settings['DATABASE_USER'] = utils.get_default(
            options,
            'db_user',
            settings['DATABASE_NAME'],
        )
        settings['DATABASE_PASSWORD'] = utils.get_default(
            options,
            'db_password',
            get_password('Please enter the database user password: '******'DATABASE_HOST'] = utils.get_default(options, 'db_host', None)
        settings['DATABASE_PORT'] = utils.get_default(options, 'db_port', None)


        settings['SITE_DOMAIN_NAME'] = utils.get_default(
            options,
            'domain',
            input('Enter in the domain name for this project instance: '),
        )
        settings['SUBDOMAINS'] = []

        settings['ADDITIONAL_SETTINGS_FILES'] = utils.get_default(
            options,
            'additional_settings_file',
            [],
        )

        return settings
 def action(length=('l',32)):
     """creates a new secret key"""
     print utils.generate_secret_key(length)
Exemple #6
0
"""

# Build paths inside the project like this: os.path.join(BASE_DIR, ...)
import os
BASE_DIR = os.path.dirname(os.path.dirname(__file__))

# Quick-start development settings - unsuitable for production
# See https://docs.djangoproject.com/en/1.6/howto/deployment/checklist/

# SECURITY WARNING: keep the secret key used in production secret!
try:
    from secret_key import *
except ImportError:
    from utils import generate_secret_key
    SETTINGS_DIR=os.path.abspath(os.path.dirname(__file__))
    generate_secret_key(os.path.join(SETTINGS_DIR, 'secret_key.py'))
    from secret_key import *

# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = True

TEMPLATE_DEBUG = True

ALLOWED_HOSTS = []

# Application definition

INSTALLED_APPS = (
    'django.contrib.admin',
    'django.contrib.auth',
    'django.contrib.contenttypes',