def put(self, contact_id): if not is_authorized_write(contact_id): return unauthorized() json_data = request.get_json(force=True) contact = Contact.query.get(contact_id) if not contact: return {'message': 'Contact does not exist'}, 404 try: data = profile_schema.load(json_data) except ValidationError as e: return e.messages, 422 profile_data = data.pop('profile', None) contact.update(**data) contact.profile.update(**profile_data) email = data.get('email', None) if email: contact.email_primary.email = email db.session.commit() result = profile_schema.dump(contact) return {'status': 'success', 'data': result}, 200
def post(self): if not is_authorized_with_permission('write:all-users'): return unauthorized() json_data = request.get_json(force=True) try: data = contacts_short_schema.load(json_data) except ValidationError as e: return e.messages, 422 if not data: return {'message': 'No data provided to update'}, 400 # Check that all of the contacts are in the db contact_ids = [c['id'] for c in data] contacts = Contact.query.filter(Contact.id.in_(contact_ids)).all() if len(data) != len(contacts): return { 'message': ("Payload contained contacts " "that couldn't be found") }, 404 # Update the stage of each contact for contact in contacts: contact.stage = ContactStage.approved.value db.session.commit() # Format and return the contacts result = contacts_short_schema.dump(contacts) return {'status': 'success', 'data': result}, 201
def put(self, contact_id): contact = Contact.query.get(contact_id) if not contact: return {'message': 'Contact does not exist'}, 404 if not is_authorized_write(contact.id): return unauthorized() json_data = request.get_json(force=True) try: data = contact_schema.load(json_data, partial=True) except ValidationError as e: return e.messages, 422 if not data: return {'message': 'No input data provided'}, 400 email = data.pop('email_primary', None) email_list = data.pop('emails', None) skills = data.pop('skills', None) contact.update(**data) if email: del contact.emails[:] contact.email_primary = Email(**email) if skills: sync_skills(skills, contact) db.session.commit() result = contact_schema.dump(contact) return {"status": 'success', 'data': result}, 200
def get(self, contact_id): if not is_authorized_view(contact_id): return unauthorized() res = Resume.query.filter_by(contact_id=contact_id) res_list = resumes_schema.dump(res) return {'status': 'success', 'data': res_list}, 200
def post(self, contact_id): if not is_authorized_write(contact_id): return unauthorized() json_data = request.get_json(force=True) try: data = skill_schema.load(json_data) except ValidationError as e: return e.messages, 422 if not data: return {'message': 'No input data provided'}, 400 contact = Contact.query.get(contact_id) if not contact: return {'message': 'Contact not found'}, 404 name = data['name'] skill = get_or_make_skill(name) contact_skill_names = {s.name for s in contact.skills} status_code = 200 if name not in contact_skill_names: status_code = 201 contact.add_skill(skill) db.session.commit() result = dump_skill_with_capabilities(skill, contact_id) return {'status': 'success', 'data': result}, status_code
def put(self, resume_id, section_id): res = Resume.query.get(resume_id) if not res: return {'message': 'Resume does not exist'}, 404 if not is_authorized_write(res.contact.id): return unauthorized() section = ResumeSection.query.get(section_id) if not section: return {'message': 'Resume section does not exist'}, 404 json_data = request.get_json(force=True) try: data = resume_section_schema.load(json_data, partial=True) except ValidationError as e: return e.messages, 422 if not data: return {'message': 'No input data provided'}, 400 items = data.pop('items', None) for k,v in data.items(): setattr(section, k, v) del section.items[:] if items: for item in items: i = ResumeItem(**item) i.resume_id = section.resume_id section.items.append(i) db.session.commit() result = resume_section_schema.dump(section) return {'status': 'success', 'data': result}, 200
def post(self, contact_id, capability_id): if not is_authorized_write(contact_id): return unauthorized() json_data = request.get_json(force=True) try: data = skill_schema.load(json_data) except ValidationError as e: return e.messages, 422 contact = Contact.query.get(contact_id) if not contact: return {'message': 'Contact does not exist'}, 404 capability = Capability.query.get(capability_id) if not capability: return {'message': 'Capability does not exist'}, 404 skill = get_or_make_skill(data['name']) if skill not in contact.skills: contact.add_skill(skill) suggestion = CapabilitySkillSuggestion( skill_id=skill.id, contact_id=contact_id, capability_id=capability_id) db.session.add(suggestion) db.session.commit() result = dump_skill_with_capabilities(skill, contact_id) return {'status': 'success', 'data': result}, 201
def put(self, contact_id, opportunity_id): if not is_authorized_write(contact_id): return unauthorized() json_data = request.get_json(force=True) try: data = opportunity_app_schema.load(json_data, partial=True) except ValidationError as e: return e.messages, 422 if not data: return {'message': 'No data provided to update'}, 400 opportunity_app = (OpportunityApp.query .filter_by(contact_id=contact_id, opportunity_id=opportunity_id) .first()) if not opportunity_app: return {'message': 'Application does not exist'}, 404 if data.get('resume') is not None: if opportunity_app.resume is None: opportunity_app.resume = ResumeSnapshot( **data['resume'] ) else: opportunity_app.resume.resume = data['resume']['resume'] del data['resume'] opportunity_app.update(**data) db.session.commit() result = opportunity_app_schema.dump(opportunity_app) return {'status': 'success', 'data': result}, 200
def get(self): opportunities = Opportunity.query.all() if not is_authorized_with_permission('view:opportunity-internal'): return unauthorized() opp_list = opportunities_internal_schema.dump(opportunities) return {'status': 'success', 'data': opp_list}, 200 return {'status': 'success', 'data': 'Hello World'}, 200
def post(self, contact_id): if not is_authorized_write(contact_id): return unauthorized() #load the input data input_data = request.get_json(force=True) try: data = resume_generate_schema.load(input_data) except ValidationError as e: return e.messages, 422 if not data: return {'message': 'No input data provided'}, 400 #pop off the ids for the data in each of the sections relevant_exp = data.pop('relevant_exp', None) other_exp = data.pop('other_exp', None) relevant_edu = data.pop('relevant_edu', None) other_edu = data.pop('other_edu', None) relevant_achieve = data.pop('relevant_achieve', None) other_achieve = data.pop('other_achieve', None) relevant_skills = data.pop('relevant_skills', None) other_skills = data.pop('other_skills', None) #query and add contact info to input data data['contact'] = Contact.query.get(contact_id) #query subset of resume items using lists of ids then #add those items to the input data with their section name def query_by_ids(table, id_list, contact_id, section_name): result = table.query.filter(table.id.in_(id_list), table.contact_id==contact_id) data[section_name] = result query_by_ids(Experience, relevant_exp, contact_id, 'relevant_exp_dump') query_by_ids(Experience, other_exp, contact_id, 'other_exp_dump') query_by_ids(Experience, relevant_edu, contact_id, 'relevant_edu_dump') query_by_ids(Experience, other_edu, contact_id, 'other_edu_dump') query_by_ids(Experience, relevant_achieve, contact_id, 'relevant_achieve_dump') query_by_ids(Experience, other_achieve, contact_id, 'other_achieve_dump') query_by_ids(TagItem, relevant_skills, contact_id, 'relevant_skills_dump') query_by_ids(TagItem, other_skills, contact_id, 'other_skills_dump') #dumps the throughput data and pass to generate resume script throughput_data = resume_generate_schema.dump(data) pprint(throughput_data) gdoc_id = generate(throughput_data) #creates dictionary to insert new resume record output_data = { 'name': data['name'], 'date_created': dt.datetime.today(), 'contact_id': contact_id, 'gdoc_id': gdoc_id, } resume = Resume(**output_data) db.session.add(resume) db.session.commit() result = resume_output_schema.dump(resume) return {'status': 'success', 'data': result}, 201
def get(self, contact_id): if not is_authorized_view(contact_id): return unauthorized() program_contacts = ProgramContact.query.filter_by( contact_id=contact_id) result = program_contacts_schema.dump(program_contacts) return {'status': 'success', 'data': result}, 200
def get(self): if not is_authorized_with_permission('view:all-users'): return unauthorized() contacts = Contact.query.all() contacts = contacts_schema.dump(contacts) return {'status': 'success', 'data': contacts}, 200
def get(self, contact_id): if not is_authorized_view(contact_id): return unauthorized() contact = Contact.query.get(contact_id) if not contact: return {'message': 'Contact does not exist'}, 404 result = instructions_schema.dump(contact) return {'status': 'success', 'data': result}, 200
def get(self, contact_id): if not is_authorized_view(contact_id): return unauthorized() contact = Contact.query.get(contact_id) result = program_app_schema.dump(contact) return {'status': 'success', 'data': result}, 200
def get(self, contact_id): achievement = Achievement.query.filter_by(contact_id=contact_id) achievement_list = achievements_schema.dump(achievement) if not is_authorized_view(contact_id): return unauthorized() return {'status': 'success', 'data': achievement_list}, 200
def get(self, contact_id, program_id): if not is_authorized_view(contact_id): return unauthorized() program_contact = query_one_program_contact(contact_id, program_id) if not program_contact: return {'message': 'Record does not exist'}, 404 result = program_contact_schema.dump(program_contact) return {'status': 'success', 'data': result}, 200
def delete(self, contact_id): if not is_authorized_with_permission('delete:all-users'): return unauthorized() contact = Contact.query.get(contact_id) if not contact: return {'message': 'Contact does not exist'}, 404 db.session.delete(contact) db.session.commit() return {"status": 'success'}, 200
def get(self, contact_id): if not is_authorized_view(contact_id): return unauthorized() opportunity_apps = (OpportunityApp.query .filter(OpportunityApp.contact_id==contact_id, OpportunityApp.stage>=ApplicationStage.submitted.value) .all()) data = opportunity_app_schema_many.dump(opportunity_apps) return {'status': 'success', 'data': data}, 200
def delete(self, resume_id): res = Resume.query.get(resume_id) if not res: return {'message': 'Resume does not exist'}, 404 if not is_authorized_write(res.contact.id): return unauthorized() db.session.delete(res) db.session.commit() return {'status': 'success'}, 200
def get(self, contact_id): contact = Contact.query.get(contact_id) if not contact: return {'message': 'Contact does not exist'}, 404 if not is_authorized_view(contact.id): return unauthorized() contact = contact_full_schema.dump(contact) return {'status': 'success', 'data': contact}, 200
def delete(self, contact_id, program_id): if not is_authorized_write(contact_id): return unauthorized() program_contact = query_one_program_contact(contact_id, program_id) if not program_contact: return {'message': 'Program contact does not exist'}, 404 db.session.delete(program_contact) db.session.commit() return {"status": 'success'}, 200
def get(self, contact_id, tag_id): if not is_authorized_view(contact_id): return unauthorized() tag = (TagItem.query.filter_by(contact_id=contact_id, tag_id=tag_id).first()) if not tag: return {'message': 'TagItem does not exist'}, 404 tag_data = tag_item_schema.dump(tag) return {'status': 'success', 'data': tag_data}, 200
def get(self, resume_id): res = Resume.query.get(resume_id) if not res: return {'message': 'Resume does not exist'}, 404 if not is_authorized_view(res.contact.id): return unauthorized() sections = ResumeSection.query.filter_by(resume_id=resume_id) result = resume_sections_schema.dump(sections) return {'status': 'success', 'data': result}, 200
def get(self, contact_id): if not is_authorized_view(contact_id): return unauthorized() contact = Contact.query.get(contact_id) if not contact: return {'message': 'Contact not found'}, 404 skills = skills_schema.dump(contact.skills) skills.sort(key=lambda s: s['name']) return {'status': 'success', 'data': skills}, 200
def delete(self, contact_id, tag_id): if not is_authorized_write(contact_id): return unauthorized() tag = TagItem.query.filter_by(contact_id=contact_id, tag_id=tag_id).first() if not tag: return {'message': 'TagItem does not exist'}, 404 db.session.delete(tag) db.session.commit() return {'status': 'success'}, 201
def delete(self, opportunity_id): opportunity = Opportunity.query.get(opportunity_id) if not opportunity: return {'message': 'Opportunity does not exist'}, 404 if not is_authorized_with_permission('write:opportunity'): return unauthorized() db.session.delete(opportunity) db.session.commit() result = opportunity_schema.dump(opportunity) return {"status": 'success'}, 200
def post(self, opportunity_id): opportunity = Opportunity.query.get(opportunity_id) if not opportunity: return {'message': 'Opportunity does not exist'}, 404 if not is_authorized_with_permission('write:opportunity'): return unauthorized() opportunity.is_active = True db.session.commit() result = opportunity_schema.dump(opportunity) return {'status': 'success', 'data': result}, 200
def get(self): if not is_authorized_with_permission('view:all-users'): return unauthorized() approved_arg = request.args.get('is_approved') if not approved_arg: contacts = Contact.query.all() else: if approved_arg == 'true': contacts = Contact.query.filter(Contact.stage >= 3) elif approved_arg == 'false': contacts = Contact.query.filter(Contact.stage < 3) contacts = program_app_many_schema.dump(contacts) return {'status': 'success', 'data': contacts}, 200
def get(self): if not is_authorized_with_permission('view:app-internal'): return unauthorized() program_id = request.args.get('program_id') if program_id: program = Program.query.get(program_id) if not program: return {'message': 'Program does not exist'}, 404 program_contacts = [c for c in program.contacts if c.is_approved] else: program_contacts = ProgramContact.query.filter_by(is_approved=True) result = program_contacts_short_schema.dump(program_contacts) return {'status': 'success', 'data': result}, 200
def delete(self, contact_id, capability_id, skill_id): if not is_authorized_write(contact_id): return unauthorized() (result, status_code) = delete_skill(contact_id, skill_id) if status_code != 200: return result, status_code suggestion = CapabilitySkillSuggestion.query.get( (contact_id, capability_id, skill_id)) if suggestion is not None: db.session.delete(suggestion) db.session.commit() return {'status': 'success'}, 200