Example #1
0
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()
Example #2
0
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()
Example #3
0
def make_random_user(password_hash):
    # 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))

    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()
Example #4
0
 def deserialize_community_partner_profile_search(self, data):
     search = self.community_partner_profile_search
     if data is not None:
         if search and search.active:
             profile_search_id = search.id
         else:
             profile_search_id = None
         data['id'] = profile_search_id
         self.community_partner_profile_search = Search.admin_deserialize(data)
Example #5
0
 def deserialize_educator_profile_search(self, data):
     search = self.educator_profile_search
     if data is not None:
         if search and search.active:
             profile_search_id = search.id
         else:
             profile_search_id = None
         data['id'] = profile_search_id
         self.educator_profile_search = Search.admin_deserialize(data)
Example #6
0
 def deserialize_educator_profile_search(self, data):
     search = self.educator_profile_search
     if data is not None:
         if search and search.active:
             profile_search_id = search.id
         else:
             profile_search_id = None
         data['id'] = profile_search_id
         self.educator_profile_search = Search.admin_deserialize(data)
Example #7
0
 def deserialize_community_partner_profile_search(self, data):
     search = self.community_partner_profile_search
     if data is not None:
         if search and search.active:
             profile_search_id = search.id
         else:
             profile_search_id = None
         data['id'] = profile_search_id
         self.community_partner_profile_search = Search.admin_deserialize(
             data)