Пример #1
0
def signup():

    #  form = SignupForm2(email = current_user.email)

    u = User2.find_by_identity(current_user.email)

    if u is None:
        u = User2()
        form = SignupForm2(email=current_user.email)
    else:
        form = SignupForm2(email=current_user.email,
                           skills=u.skills,
                           train=u.train,
                           department=u.department,
                           protype=u.protype)

#    form = SignupForm2(obj=current_user)

    if form.validate_on_submit():
        #        u = User2()

        form.populate_obj(u)
        u.save()

        redurl = '/recommendprj/' + u.email
        return redirect(redurl)

#       if login_user(u):
#           flash('Awesome, thanks for signing up!', 'success')
#           return redirect(url_for('user2.welcome'))

    return render_template('user2/signup.html', form=form)
Пример #2
0
def recommendprj(email, disinterested):
    recommender = []

    user = User2.find_by_identity(email)

    user_skill = user.skills.split(',')

    projects = Projects.query \
        .order_by(Projects.created_on.desc())

    for project in projects:
        if project.resource_email == '':
            project_skills = project.skills.split(',')
            matching_skills = set(project_skills) & set(user_skill)
            if len(matching_skills) >= 0.6 * len(project_skills):
                project_employees = project.interesting_participants.split(',')
                if user.email in project_employees:
                    recommender.append([
                        project.projectid, user.email, 'X', disinterested,
                        project.description, project.email
                    ])
                else:
                    recommender.append([
                        project.projectid, user.email, '', disinterested,
                        project.description, project.email
                    ])
        if user.current_project != '':
            if user.current_project == project.projectid:
                recommender.append([
                    project.projectid, user.email, 'C', disinterested,
                    project.description, project.email
                ])

    return render_template('user2/projectrecommend.html', bets=recommender)
Пример #3
0
def login():
    form = LoginForm2(next=request.args.get('next'))

    if form.validate_on_submit():
        u = User2.find_by_identity(request.form.get('identity'))

        if u and u.authenticated(password=request.form.get('password')):
            # As you can see remember me is always enabled, this was a design
            # decision I made because more often than not users want this
            # enabled. This allows for a less complicated login form.
            #
            # If however you want them to be able to select whether or not they
            # should remain logged in then perform the following 3 steps:
            # 1) Replace 'True' below with: request.form.get('remember', False)
            # 2) Uncomment the 'remember' field in user/forms.py#LoginForm
            # 3) Add a checkbox to the login form with the id/name 'remember'
            if login_user(u, remember=True) and u.is_active():
                u.update_activity_tracking(request.remote_addr)

                # Handle optionally redirecting to the next URL safely.
                next_url = request.form.get('next')
                if next_url:
                    return redirect(safe_next_url(next_url))

                return redirect(url_for('user2.settings'))
            else:
                flash('This account has been disabled.', 'error')
        else:
            flash('Identity or password is incorrect.', 'error')

    return render_template('user2/login.html', form=form)
Пример #4
0
def seed2():
    """
    Seed the database with an initial user.

    :return: User instance
    """
    if User2.find_by_identity(app.config['SEED_ADMIN_EMAIL']) is not None:
        return None

    params = {
        'role': 'admin',
        'email': app.config['SEED_ADMIN_EMAIL'],
        'password': app.config['SEED_ADMIN_PASSWORD']
    }

    return User2(**params).save()
Пример #5
0
def signup():
    form = SignupForm2()

    if form.validate_on_submit():
        u = User2()

        form.populate_obj(u)
        u.password = User2.encrypt_password(request.form.get('password'))
        u.save()

        redurl = '/recommendprj/' + u.email
        return redirect(redurl)

#       if login_user(u):
#           flash('Awesome, thanks for signing up!', 'success')
#           return redirect(url_for('user2.welcome'))

    return render_template('user2/signup.html', form=form)
Пример #6
0
def begin_password_reset():
    form = BeginPasswordResetForm2()

    if form.validate_on_submit():
        u = User2.initialize_password_reset(request.form.get('identity'))

        flash('An email has been sent to {0}.'.format(u.email), 'success')
        return redirect(url_for('user.login'))

    return render_template('user2/begin_password_reset.html', form=form)
Пример #7
0
def recommendme(projectid, disinterested):
    recommender = []
    match = ''
    matching_skills = defaultdict(list)
    #    matching_skills = []
    stemmer = SS('english')

    project = Projects.find_by_identity(projectid)

    employees = User2.query \
        .order_by(User2.created_on.desc())

    if project.resource_email == '':
        project_skills = project.skills.split(',')
        for employee in employees:
            matching_skills = []
            employee_skills = employee.skills.split(',')
            for project_skill in project_skills:
                s1 = stemmer.stem(project_skill)
                for employee_skill in employee_skills:
                    s2 = stemmer.stem(employee_skill)
                    if s1 == s2:
                        matching_skills.append(employee_skill)


#            matching_skills = set(project_skills) & set(employee_skills)
            if len(matching_skills) >= 0.6 * len(project_skills):
                employee_projects = employee.interesting_projects.split(',')
                for matching_skill in matching_skills:
                    match = matching_skill + ',' + match
                if project.projectid in employee_projects:
                    recommender.append([
                        project.projectid, employee.email, 'X', disinterested,
                        employee.fullname, match, employee.department,
                        employee.protype
                    ])
                else:
                    recommender.append([
                        project.projectid, employee.email, '', disinterested,
                        employee.fullname, match, employee.department,
                        employee.protype
                    ])
    if project.project_status == 'Started':
        employee = User2.find_by_identity(project.resource_email)
        project_skills = project.skills.split(',')
        employee_skills = employee.skills.split(',')
        matching_skills = set(project_skills) & set(employee_skills)
        for matching_skill in matching_skills:
            match = matching_skill + ',' + match
        recommender.append([
            project.projectid, employee.email, '', 'E', employee.fullname,
            match, employee.department, employee.protype
        ])

    return render_template('contact2/userrecommend.html', bets=recommender)
Пример #8
0
def password_reset():
    form = PasswordResetForm2(reset_token=request.args.get('reset_token'))

    if form.validate_on_submit():
        u = User2.deserialize_token(request.form.get('reset_token'))

        if u is None:
            flash('Your reset token has expired or was tampered with.',
                  'error')
            return redirect(url_for('user2.begin_password_reset'))

        form.populate_obj(u)
        u.password = User2.encrypt_password(request.form.get('password'))
        u.save()

        if login_user(u):
            flash('Your password has been reset.', 'success')
            return redirect(url_for('user2.settings'))

    return render_template('user2/password_reset.html', form=form)
Пример #9
0
def ensure_identity_exists(form, field):
    """
    Ensure an identity exists.

    :param form: wtforms Instance
    :param field: Field being passed in
    :return: None
    """
    user = User2.find_by_identity(field.data)

    if not user:
        raise ValidationError('Unable to locate account.')
Пример #10
0
def update_credentials():
    form = UpdateCredentials2(current_user, uid=current_user.id)

    if form.validate_on_submit():
        new_password = request.form.get('password', '')
        current_user.email = request.form.get('email')

        if new_password:
            current_user.password = User2.encrypt_password(new_password)

        current_user.save()

        flash('Your sign in settings have been updated.', 'success')
        return redirect(url_for('user2.settings'))

    return render_template('user2/update_credentials.html', form=form)
Пример #11
0
def recommendme(email):
    recommender = []

    user = User2.find_by_identity(email)

    user_skill = user.skills.split(',')

    projects = Projects.query \
        .order_by(Projects.created_on.desc())

    for project in projects:
        if project.resource_email == '':
            project_skills = project.skills.split(',')
            matching_skills = set(project_skills) & set(user_skill)
            if len(matching_skills) >= 0.6 * len(project_skills):
                recommender.append([project.projectid, user.email])

    return render_template('contact2/userrecommend.html', bets=recommender)
Пример #12
0
def assign_project(projectid, email, action):

    u1 = Projects.find_by_identity(projectid)

    u2 = User2.find_by_identity(email)

    if action == 'I':

        u2.interesting_projects = projectid + ',' + u2.interesting_projects

        redurl = '/recommendprj/' + email + '/X'

        u2.save()

        return redirect(redurl)

    elif action == 'A':

        #        u1.whizcoin = 0

        u1.resource_email = email

#        u2.whizcoin = u2.whizcoin + 100

    elif action == 'R':

        u2_projects = u2.interesting_projects.split(',')

        u2_projects.remove(projectid)

        u2.interesting_projects = ''.join(u2_projects)

        u1_participants = u1.interesting_participants.split(',')

        u1_participants.remove(email)

        u1.interesting_participants = ''.join(u1_participants)

    elif action == 'S':

        u1.project_status = 'Started'

        u2.current_project = ''

    u1.save()

    u2.save()

    #    flash('Awesome, thanks for signing up!', 'success')

    #    u1 = Projects.find_by_identity(projectid)

    #    u1.interesting_participants = email + ',' + u1.interesting_participants

    #    u1.whizcoin = 0

    #    u2 = User2.find_by_identity(email)
    #    u2.interesting_projects = projectid + ',' + u2.interesting_projects
    #    u2.whizcoin = u2.whizcoin - 100

    #    u2.save()

    #    u1.save()

    #    recommender = []
    #    recommender.append([projectid, email])

    return render_template('contact2/thankyou.html')
Пример #13
0
def users2():
    """
    Generate fake users.
    """
    random_emails = []

    skills = [
        'c, c++, java, .net, db', '.net, abap, testing, c#, web development',
        'sso, architecture, machine learning, big data, web develop',
        'project management, budget, design thinking, marketing',
        'strategy, finance, investment, pricing',
        'executive presentation, finance modeling, human resources',
        'leadership, .net, java, abap, archiecture, web development',
        'project management, strategy, architecture, sso',
        'accounting, corporate finance, governance, leadership, management',
        'operations, supply chain, performance management, HR policies',
        'c, c++, java, .net, db', '.net, abap, testing, c#, web development',
        'sso, architecture, machine learning, big data, web develop',
        'project management, budget, design thinking, marketing',
        'strategy, finance, investment, pricing',
        'executive presentation, finance modeling, human resources',
        'leadership, .net, java, abap, archiecture, web development',
        'project management, strategy, architecture, sso',
        'accounting, corporate finance, governance, leadership, management',
        'operations, supply chain, performance management, HR policies',
        'c, c++, java, .net, db', '.net, abap, testing, c#, web development',
        'sso, architecture, machine learning, big data, web develop',
        'project management, budget, design thinking, marketing',
        'strategy, finance, investment, pricing',
        'executive presentation, finance modeling, human resources',
        'leadership, .net, java, abap, archiecture, web development',
        'project management, strategy, architecture, sso',
        'accounting, corporate finance, governance, leadership, management',
        'operations, supply chain, performance management, HR policies'
    ]
    data = []
    #    skills[0] = 'c, c++, java, .net, db'
    #    skills[1] = '.net, abap, testing, c#, web development'
    #    skills[2] = 'sso, architecture, machine learning, big data, web develop'
    #    skills[3] = 'project management, budget, design thinking, marketing'
    #    skills[4] = 'strategy, finance, investment, pricing'
    #    skills[5] = 'executive presentation, finance modeling, human resources'
    #    skills[6] = 'leadership, .net, java, abap, archiecture, web development'
    #    skills[7] = 'project management, strategy, architecture, sso'
    #    skills[8] = 'accounting, corporate finance, governance, leadership, management'
    #    skills[9] = 'operations, supply chain, performance management, HR policies'
    #    skills[10] = 'c, c++, java, .net, db'
    #    skills[11] = '.net, abap, testing, c#, web development'
    #    skills[12] = 'sso, architecture, machine learning, big data, web develop'
    #    skills[13] = 'project management, budget, design thinking, marketing'
    #    skills[14] = 'strategy, finance, investment, pricing'
    #    skills[15] = 'executive presentation, finance modeling, human resources'
    #    skills[16] = 'leadership, .net, java, abap, archiecture, web development'
    #    skills[17] = 'project management, strategy, architecture, sso'
    #    skills[18] = 'accounting, corporate finance, governance, leadership, management'
    #    skills[19] = 'operations, supply chain, performance management, HR policies'
    #    skills[20] = 'c, c++, java, .net, db'
    #    skills[21] = '.net, abap, testing, c#, web development'
    #    skills[22] = 'sso, architecture, machine learning, big data, web develop'
    #    skills[23] = 'project management, budget, design thinking, marketing'
    #    skills[24] = 'strategy, finance, investment, pricing'
    #    skills[25] = 'executive presentation, finance modeling, human resources'
    #    skills[26] = 'leadership, .net, java, abap, archiecture, web development'
    #    skills[27] = 'project management, strategy, architecture, sso'
    #    skills[28] = 'accounting, corporate finance, governance, leadership, management'
    #    skills[29] = 'operations, supply chain, performance management, HR policies'
    click.echo('Working...')

    # Ensure we get about 100 unique random emails.

    #    for j in range(0, 3):
    #        skill1 = skills[j]
    #        random_skills.append(skill1)
    #        click.echo('Skill read {0} {1}'.format(j, skill1))
    #        random_skills = list(set(random_skills))

    for i in range(0, 30):
        random_email = 'test' + str(int(i)) + '@abc.com'
        random_emails.append(random_email)

#        random_emails.append(app.config['SEED_ADMIN_EMAIL'])
#        random_emails = list(set(random_emails))

    while True:
        if len(random_emails) == 0:
            break

        click.echo('Skill list {0}'.format(skills))

        created_on = '2016-12-29 06:51:46.429746+00:00'
        current_sign_in_on = '2016-12-29 07:51:46.429746+00:00'
        #        fake_datetime = fake.date_time_between(
        #            start_date='-1y', end_date='now').strftime('%s')

        #       created_on = datetime.utcfromtimestamp(
        #           float(fake_datetime)).strftime('%Y-%m-%dT%H:%M:%S Z')

        random_percent = random.random()

        if random_percent >= 0.05:
            role = 'member'
        else:
            role = 'admin'

        email = random_emails.pop()
        skill = skills.pop()

        random_percent = random.random()

        if random_percent >= 0.5:
            random_trail = str(int(round((random.random() * 1000))))
            username = '******' + random_trail
        else:
            username = None


#        fake_datetime = fake.date_time_between(
#            start_date='-1y', end_date='now').strftime('%s')

#        current_sign_in_on = datetime.utcfromtimestamp(
#            float(fake_datetime)).strftime('%Y-%m-%dT%H:%M:%S Z')

        params = {
            'created_on': created_on,
            'updated_on': created_on,
            'role': role,
            'email': email,
            'username': username,
            'password': User2.encrypt_password('password'),
            'skills': skill,
            'train': 'machine learning, bigdata',
            'sign_in_count': random.random() * 100,
            'current_sign_in_on': current_sign_in_on,
            'current_sign_in_ip': '192.157.1.1',
            'last_sign_in_on': current_sign_in_on,
            'last_sign_in_ip': '192.157.1.1'
        }

        # Ensure the seeded admin is always an admin with the seeded password.
        if email == app.config['SEED_ADMIN_EMAIL']:
            password = User2.encrypt_password(
                app.config['SEED_ADMIN_PASSWORD'])

            params['role'] = 'admin'
            params['password'] = password

        data.append(params)

        click.echo('chosen skill {0}'.format(skill))

    return _bulk_insert(User2, data, 'users2')