def setup(n_random_users=100): logger.info('Starting setup script.') init_db() logger.info('Making labels.') make_labels() from community_share.models.secret import Secret logger.info('Making Admin Users') make_admin_user('*****@*****.**', '*****@*****.**', 'admin') admin_emails = config.ADMIN_EMAIL_ADDRESSES.split(',') admin_emails = [x.strip() for x in admin_emails] logger.info('admin_emails is {0}'.format(admin_emails)) for email in admin_emails: make_admin_user(email, email, Secret.make_key(20)) logger.info('Making {0} random users'.format(n_random_users)) for i in range(n_random_users): make_random_user() creator = get_creator() logger.info('Creator of questions is {}'.format(creator.email)) questions = setup_data.get_questions(creator) update_questions(questions) store.session.commit() creator = get_creator() questions = setup_data.get_questions(creator) update_questions(questions) store.session.commit()
def setup(n_random_users=100): logger.info('Starting setup script.') init_db() first_admin = None logger.info('Making labels.') make_labels() import os from community_share.models.secret import Secret admin_emails = config.ADMIN_EMAIL_ADDRESSES.split(',') admin_emails = [x.strip() for x in admin_emails] logger.info('admin_emails is {0}'.format(admin_emails)) logger.info('Making Admin Users') for email in admin_emails: if email: user = make_admin_user(email, email, Secret.make_key(20)) if user is not None and first_admin is None: first_admin = user logger.info('Making {0} random users'.format(n_random_users)) for i in range(n_random_users): make_random_user() store.session.commit() creator = get_creator() questions = setup_data.get_questions(creator) update_questions(questions) store.session.commit()
def make_random_user(): # Make the user first_name, last_name = gen_new_name(user_names_used, first_names, last_names) if first_name is None: return user_names_used.add((first_name, last_name)) password = Secret.make_key(20) password_hash = User.pwd_context.encrypt(password) if random.randint(0, 1): searcher_role = 'educator' searching_for_role = 'partner' bio = generate_educator_bio() associations = [gen_random_institution(schools, educator_roles)] else: searcher_role = 'partner' searching_for_role = 'educator' bio = generate_expert_bio() associations = [ gen_random_institution(companies, partner_roles) for _ in range(random.randint(1, 2)) ] new_user = User( name='{0} {1}'.format(first_name, last_name), email=gen_email(first_name, last_name), password_hash=password_hash, picture_filename=random.choice(profile_picture_filenames), bio=bio, institution_associations=associations, is_administrator=False, email_confirmed=True ) store.session.add(new_user) store.session.commit() # Make the search latitude, longitude = make_random_location() search = Search( searcher_user_id=new_user.id, searcher_role=searcher_role, searching_for_role=searching_for_role, latitude=latitude, longitude=longitude, ) search.labels = Label.name_list_to_object_list(gen_labels()) store.session.add(search) store.session.commit() if search.searcher_role == 'educator': new_user.educator_profile_search = search else: new_user.community_partner_profile_search = search store.session.add(new_user) store.session.commit()
def setup(n_random_users=100): logger.info('Starting setup script.') wait_for_db() init_db() logger.info('Making labels.') make_labels() from community_share.models.secret import Secret logger.info('Making Admin Users') make_admin_user('*****@*****.**', '*****@*****.**', 'admin') admin_emails = config.ADMIN_EMAIL_ADDRESSES.split(',') admin_emails = [x.strip() for x in admin_emails] logger.info('admin_emails is {0}'.format(admin_emails)) for email in admin_emails: make_admin_user(email, email, Secret.make_key(20)) logger.info('Making {0} random users'.format(n_random_users)) password_hash = User.pwd_context.encrypt('password') for i in range(n_random_users): make_random_user(password_hash=password_hash) creator = get_creator() logger.info('Creator of questions is {}'.format(creator.email)) questions = setup_data.get_questions(creator) update_questions(questions) store.session.commit() creator = get_creator() questions = setup_data.get_questions(creator) update_questions(questions) store.session.commit()
def make_random_user(): # Make the user finished = False while not finished: first_name = random_item_from_list(first_names) last_name = random_item_from_list(last_names) combined = (first_name, last_name) if combined not in user_names_used: finished = True user_names_used.add(combined) password = Secret.make_key(20) email = make_email(first_name, last_name) password_hash = User.pwd_context.encrypt(password) name = '{0} {1}'.format(first_name, last_name) picture_filename = random_item_from_list(profile_picture_filenames) randombinary = random.randint(0, 1) if randombinary: searcher_role = 'educator' searching_for_role = 'partner' bio = generate_educator_bio() institution_associations = [ InstitutionAssociation( institution=random_item_from_list(schools), role=random_item_from_list(educator_roles) )] else: searcher_role = 'partner' searching_for_role = 'educator' bio = generate_expert_bio() n_institutions = random.randint(1, 2) institution_associations = [ InstitutionAssociation( institution=random_item_from_list(companies), role=random_item_from_list(partner_roles)) for x in range(n_institutions)] new_user = User(name=name, email=email, password_hash=password_hash, picture_filename=picture_filename, bio=bio, institution_associations=institution_associations, is_administrator=False, email_confirmed=True) store.session.add(new_user) store.session.commit() # Make the search location = make_random_location() search = Search( searcher_user_id=new_user.id, searcher_role=searcher_role, searching_for_role=searching_for_role, latitude=location[0], longitude=location[1], ) search.labels = Label.name_list_to_object_list(get_labels()) store.session.add(search) store.session.commit() if search.searcher_role == 'educator': new_user.educator_profile_search = search else: new_user.community_partner_profile_search = search store.session.add(new_user) store.session.commit()
def main(): logger.info('Loading settings from environment') config.load_from_environment() logger.info('Starting setup script produced on 2014 June 14th.') setup.init_db() first_admin = None logger.info('Making labels.') setup.make_labels() admin_emails = os.environ.get('COMMUNITYSHARE_ADMIN_EMAILS', '').split(',') admin_emails = [x.strip() for x in admin_emails] logger.info('admin_emails is {0}'.format(admin_emails)) logger.info('Making Admin Users') for email in admin_emails: if email: user = setup.make_admin_user(email, email, Secret.make_key(20)) if user is not None and first_admin is None: first_admin = user logger.info('Making questions') setup.make_questions(first_admin) store.session.commit()
def setup(n_random_users=100): logger.info('Starting setup script.') init_db() first_admin = None logger.info('Making labels.') make_labels() import os from community_share.models.secret import Secret admin_emails = os.environ.get('COMMUNITYSHARE_ADMIN_EMAILS', '').split(',') admin_emails = [x.strip() for x in admin_emails] logger.info('admin_emails is {0}'.format(admin_emails)) logger.info('Making Admin Users') for email in admin_emails: if email: user = make_admin_user(email, email, Secret.make_key(20)) if user is not None and first_admin is None: first_admin = user logger.info('Making {0} random users'.format(n_random_users)) for i in range(n_random_users): make_random_user() store.session.commit()