예제 #1
0
def populate(db):
    for name in capabilities_to_skills():
        db.session.add(get_or_make_skill(name))
    for id_, name in CAPABILITIES:
        db.session.add(Capability(id=id_, name=name))
    db.session.commit()

    for cap in CAPABILITIES:
        db_cap = get_capability(cap[0])
        for (i, name) in enumerate(CAPABILITIES[cap]):
            db.session.add(
                SkillRecommendation(capability_id=cap[0],
                                    skill_id=get_skill_id(name),
                                    order=i))
            db_cap.related_skills.append(get_skill(name))
    db.session.commit()
예제 #2
0
    def post(self):

        if not is_authorized_with_permission('view:all-users'):
            return unauthorized()

        json_data = request.get_json(force=True)
        query = input_schema.load(json_data)

        try:
            data = input_schema.load(json_data)
        except ValidationError as e:
            return e.messages, 422

        q = (db.session
                .query(Contact)
                .join(Contact.profile)
                .join(Contact.race)
                .join(Contact.address_primary)
                .with_entities(
                    Contact.id,
                    Contact.first_name,
                    Contact.last_name,
                    Contact.email,
                    Contact.phone_primary,
                    Contact.stage,
                    Profile.years_exp,
                    Profile.job_search_status,
                    Profile.gender,
                    ContactAddress.city,
                    ContactAddress.state,
                    Race.race_all,
                ))

        if not query:
            q = q.filter(Contact.stage > 1)
        else:
            # pops out stage and updates query with stage
            status_list = query.pop('status', None)
            if status_list == ['submitted']:
                q = q.filter(Contact.stage == 2)
            elif status_list == ['approved']:
                q = q.filter(Contact.stage == 3)
            else:
                q = q.filter(Contact.stage > 1)

            # pops out roles and adds them to the filter
            roles = query.pop('roles', None)
            if roles:
                q = q.join(Profile.roles)
                for r in roles:
                    q = q.filter(getattr(RoleChoice, r)==roles[r])

            # pops out programs_completed and adds them to the filter
            p_complete = query.pop('programs_completed', None)
            if p_complete:
                q = q.join(Profile.programs_completed)
                for p in p_complete:
                    q = q.filter(getattr(ProgramsCompleted, p)==p_complete[p])

            # pops out program_apps and adds them to the filter
            app_params = query.pop('program_apps', None)
            if app_params:
                programs = [app['program']['id'] for app in app_params]
                # uses subquery to prevent duplicate contacts
                # from being returned
                subq = (db.session
                          .query(ProgramApp.contact_id)
                          .filter(ProgramApp.program_id.in_(programs))
                          .filter(ProgramApp.is_interested==True)
                          .subquery())
                q = q.filter(Contact.id.in_(subq))

            # pops out skills and adds them to the filter
            skill_params = query.pop('skills', None)
            if skill_params:
                skills = [get_skill_id(skill) for skill in skill_params]
                # uses subquery to prevent duplicate contacts
                # from being returned
                subq = (db.session
                          .query(ContactSkill.contact_id)
                          .filter(ContactSkill.skill_id.in_(skills))
                          .filter(ContactSkill.deleted==False)
                          .subquery())
                q = q.filter(Contact.id.in_(subq))

            # iteratively adds query parameters to query for Profile
            for param in query:
                q = q.filter(getattr(Profile, param).in_(query[param]))

        result = [format_row(row) for row in q.all()]

        return {'status': 'success', 'data': result}, 201
예제 #3
0
def get_contact_skill(contact_id, skill_name):
    return ContactSkill.query.filter_by(
        contact_id=contact_id, skill_id=get_skill_id(skill_name)).first()
예제 #4
0
def get_skill(name):
    return Skill.query.get(get_skill_id(name))
예제 #5
0
    'Formalized organizational strategy for defining and analyzing KPIs.')
a_baltimore3 = Achievement(
    id=83,
    exp_id=513,
    contact_id=123,
    description=
    'Developed recruitment projection tools to model and track progress to goals.'
)
a_goucher1 = Achievement(id=84,
                         exp_id=512,
                         contact_id=123,
                         description='Did some stuff')

skills = [
    Skill(
        id=get_skill_id(name),
        name=name,
    ) for name in [
        'Python',
        'C++',
        'Web Development',
        'Public Health',
        'Advocacy and Public Policy',
        'Community Organizing',
        'Canvassing',
        'Advocacy',
        'Policy Writing',
        'Volunteer Mobilization',
        'Community Engagement and Outreach',
        'Community Engagement',
        'Client Recruitment',
예제 #6
0
billy_edu.achievements.append(billy_edu1)
billy.achievements.append(billy_edu1)


# creates billy's work experience
billy_work = create_exp(billy, EXPERIENCES_DATABASE['billy_work'])
billy_work1 = Achievement(**ACHIEVEMENTS_DATABASE['billy_work1'])
billy_work2 = Achievement(**ACHIEVEMENTS_DATABASE['billy_work2'])
billy_work3 = Achievement(**ACHIEVEMENTS_DATABASE['billy_work3'])

billy_work.achievements.extend([billy_work1, billy_work2, billy_work3])
billy.achievements.extend([billy_work1, billy_work2, billy_work3])


skills = [Skill(id=get_skill_id(name),name=name,)
          for name in SKILLS_NAMES]

advocacy_capability = Capability(
    id='cap:advocacy',
    name='Advocacy and Public Policy',
)
advocacy_recommendations = [
    SkillRecommendation(
        capability_id='cap:advocacy',
        skill_id=get_skill_id(name),
        order=i
    )
    for (i, name) in enumerate([
        'Community Organizing',
        'Canvassing',
예제 #7
0
from resources.skill_utils import get_skill_id

if __name__ == '__main__':
    import sys
    print(get_skill_id(sys.argv[1]))