def new_empty_template(): manager_uuid = verify(request) if manager_uuid == None: return 'Unauthorized', 401 req = request.get_json(force=True) template_name = req['template_name'] template_id = db.generate_key() data = {"no_id": "no_name"} # make new empty template in Templates database db.child('Templates').child(template_id).set(data) # add template reference to manager # since we can't append to database, get the template info from the manager (will be a dict of template_id : template_name) templates = db.child('Managers').order_by_key().equal_to( manager_uuid).get().val()['templates'] # set plan's template data by combining the templates dict with a dict of the new template_id : template_name to be added templates.update({template_id: template_name}) db.child('Managers').child(manager_uuid).child('templates').update( templates) return {"response": "success"}
def add_info_to_task(): manager_uuid = verify(request) if manager_uuid == None: return 'Unauthorized', 401 req = request.get_json(force=True) training_id = req['training_id'] documentation_links = req[ 'documentation_links'] # should be a dict of {link : name} other_links = req['other_links'] # should be a dict of {link : name} # since we can't append to database, need to get current list of things, then add to it training = db.child('Trainings').order_by_key().equal_to( training_id).get().val()[training_id] if documentation_links: original_documentation_links = training[ 'documentation_links'] # will be a dict of {link : name} original_documentation_links.update( documentation_links) # combine the original dict with the new dict db.child('Trainings').child(training_id).child( 'documentation_links').update(original_documentation_links) if other_links: original_other_links = training[ 'other_links'] # will be a dict of {link : name} original_other_links.update( other_links) # combine the original dict with the new dict db.child('Trainings').child(training_id).child('other_links').update( original_other_links)
def signup(): #default using command line until HTML forms are built first_name = request.form["first_name"] last_name = request.form["last_name"] email = request.form["email"] age = request.form["age"] address = request.form["address"] password = request.form["password"] confirm_password = request.form["confirm_pass"] if password == confirm_password: try: user = auth.create_user_with_email_and_password(email, password) except: print("Email already in use. Try using another one") return else: print("Passwords do not match. Try again") return 0 #send verification email auth.send_email_verification(user['idToken']) #load information to database default to Users node data = { 'name': "{} {}".format(first_name, last_name), 'email': email, 'age': age, 'address': address } db.child('Users').push(data) return user['idToken']
def mark_task_complete(): trainee_uuid = verify(request) if trainee_uuid == None: return 'Unauthorized', 401 req = request.get_json(force=True) training_id = req['training_id'] db.child('Trainings').child(training_id).update({'complete': 'true'})
def update_task_info(): manager_uuid = verify(request) if manager_uuid == None: return 'Unauthorized', 401 req = request.get_json(force=True) training_id = req['training_id'] training_name = req['training_name'] note = req['note'] due_date = req['due_date'] duration = req['duration'] if training_name: db.child('Trainings').child(training_id).child('name').update( training_name) if note: db.child('Trainings').child(training_id).child('note').update(note) if due_date: db.child('Trainings').child(training_id).child('due_date').update( due_date) if duration: db.child('Trainings').child(training_id).child('duration').update( duration)
def add_new_trainee(): req = request.get_json(force=True) trainee_uuid = req["trainee_uuid"] name = req["name"] age = req["age"] try: meetings = req[ "meetings"] # will be of the form: 'meetings' : {"uuid 1" : "datetime 1", "uuid 2" : "datetime 2"} except: meetings = {None: None} # make a new plan for the trainee plan_key = db.generate_key() data = {'empty_id': 'empty_name'} db.child('Plans').child(plan_key).child("templates").set(data) db.child('Plans').child(plan_key).child("trainings").set(data) # set trainee data path = 'Trainees' data = {'name': name, 'age': age, 'plan': plan_key} db.child('Trainees').child(trainee_uuid).set(data) db.child(path).child(trainee_uuid).child("Meetings").set(meetings) return {"response": "success"}
def get_training_templates(): manager_uuid = verify(request) if manager_uuid == None: return 'Unauthorized', 401 return db.child('Managers').order_by_key().equal_to( manager_uuid).get().val()[manager_uuid]['templates']
def get_trainee_meetings(): trainee_uuid = verify(request) if trainee_uuid == None: return 'Unauthorized', 401 meetings = db.child('Trainees').order_by_key().equal_to( trainee_uuid).get().val()['meetings'] return meetings
def trainee_get_plan_id(): trainee_uuid = verify(request) if trainee_uuid == None: return 'Unauthorized', 401 plan_id = db.child('Trainees').order_by_key().equal_to( trainee_uuid).get().val()['plan'] return plan_id
def get_trainees(): manager_uuid = verify(request) if manager_uuid == None: return 'Unauthorized', 401 trainees = db.child('Managers').order_by_key().equal_to( manager_uuid).get().val()[manager_uuid]["trainees"] return trainees
def add_template_to_training_plan(): manager_uuid = verify(request) if manager_uuid == None: return 'Unauthorized', 401 req = request.get_json(force=True) template_id = req['template_id'] template_name = req['template_name'] plan_id = req['plan_id'] # since we can't append to database, get the template info currently in the plan (will be a dict of template_id : template_name) templates = db.child('Plans').order_by_key().equal_to( plan_id).get().val()['templates'] # set plan's template data by combining the templates dict with a dict of the new template_id : template_name to be added templates.update({template_id: template_name}) db.child('Plans').child(plan_id).child('templates').update(templates) return {"response": "success"}
def get_training(): trainee_uuid = verify(request) if trainee_uuid == None: return 'Unauthorized', 401 req = request.get_json(force=True) training_id = req['training_id'] return db.child('Trainings').order_by_key().equal_to( training_id).get().val()[training_id]
def remove_task_from_plan(): manager_uuid = verify(request) if manager_uuid == None: return 'Unauthorized', 401 req = request.get_json(force=True) plan_id = req['plan_id'] training_id = req['training_id'] # get the trainings currently in the plan (will be a dict of training_id : training_name) trainings = db.child('Plans').order_by_key().equal_to( plan_id).get().val()[training_id] # remove the training entry from the dict - using pop() so it won't crash if the key isn't present trainings.pop(training_id, None) # update the plan entry db.child('Plans').child(training_id).update(trainings) # remove the training entry in the Trainings table that corresponds to the training_id db.child('Trainings').child(training_id).remove()
def get_training_template(): manager_uuid = verify(request) if manager_uuid == None: return 'Unauthorized', 401 req = request.get_json(force=True) template_id = req['template_id'] return db.child('Templates').order_by_key().equal_to( template_id).get().val()[template_id]
def create_new_company(): req = request.get_json(force=True) identifier = req["identifier"] name = req["name"] num_employees = req["num_employees"] try: managers = req[ "managers"] # will be of the form: 'managers' : {"uuid 1" : "name 1", "uuid 2" : "name 2"} except: managers = {None: None} try: trainees = req[ "trainees"] # will be of the form: 'trainees' : {"uuid 1" : "name 1", "uuid 2" : "name 2"} except: trainees = {None: None} # set company data path = 'Companies' data = { 'name': name, 'num_employees': num_employees, } db.child(path).child(identifier).set(data) db.child(path).child(identifier).child("managers").set(managers) db.child(path).child(identifier).child("trainees").set(trainees) return {"response": "success"}
def trainee_get_plan_contents(): trainee_uuid = verify(request) if trainee_uuid == None: return 'Unauthorized', 401 req = request.get_json(force=True) plan_id = req['plan_id'] # get trainings added directly to the plan first trainings = db.child('Plans').order_by_key().equal_to( plan_id).get().val()[plan_id]['trainings'] # now get trainings from the templates template_ids = db.child('Plans').order_by_key().equal_to( plan_id).get().val()[plan_id]['templates'] for template_id in template_ids: trainings.append( db.child('Templates').order_by_key().equal_to( template_id).get().val()[template_id]['trainings']) return trainings
def manager_get_trainee_training_plan_contents(): manager_uuid = verify(request) if manager_uuid == None: return 'Unauthorized', 401 req = request.get_json(force=True) plan_id = req['plan_id'] # get trainings added directly to the plan first (trainings will be a dict of training_id : training_name) trainings = db.child('Plans').order_by_key().equal_to( plan_id).get().val()[plan_id]['trainings'] # now get trainings from the templates (templates will be a dict of template_id : template_name) template_ids = db.child('Plans').order_by_key().equal_to( plan_id).get().val()[plan_id]['templates'] for template_id in template_ids.keys(): # index into the templates table using the template_id and get the trainings (template_trainings will be a dict of training_id : training_name) template_trainings = db.child('Templates').order_by_key().equal_to( template_id).get().val()[template_id]['trainings'] # merge the trainings from this template into the trainings dict trainings.update(template_trainings) return trainings
def add_task_to_training_plan(): manager_uuid = verify(request) if manager_uuid == None: return 'Unauthorized', 401 req = request.get_json(force=True) plan_id = req['plan_id'] training_name = req['training_name'] documentation_links = req[ 'documentation_links'] # should be a dict of {link : name} other_links = req['other_links'] # should be a dict of {link : name} note = req['note'] due_date = req['due_date'] duration = req['duration'] # make a new training training_key = db.generate_key() data = { 'name': training_name, 'note': note, 'due_date': due_date, 'duration': duration, 'complete': 'false' } db.child('Trainings').child(training_key).set(data) db.child('Trainings').child(training_key).child('documentation_links').set( documentation_links) db.child('Trainings').child(training_key).child('other_links').set( other_links) # since we can't append to database, get the trainings currently in the plan (will be a dict of training_id : training_name) trainings = db.child('Plans').order_by_key().equal_to( plan_id).get().val()[plan_id]['trainings'] # set plan's training data by combining the trainings dict with a dict of the new training_id : training_name to be added trainings.update({training_key: training_name}) db.child('Plans').child(plan_id).child('trainings').update(trainings) return {"response": "success"}
def manager_get_trainee_training_plan_id(): manager_uuid = verify(request) if manager_uuid == None: return 'Unauthorized', 401 req = request.get_json(force=True) trainee_uuid = req['trainee_uuid'] plan_id = db.child('Trainees').order_by_key().equal_to( trainee_uuid).get().val()[trainee_uuid]['plan'] # here is where we could use the plan_id to query the plan table to get template_ids and individual trainings # then query the templates table with the template_ids to get all trainings for this user # if we don't do that here, we'll need another method to do that return plan_id
def add_new_manager(): req = request.get_json(force=True) manager_uuid = req["manager_uuid"] name = req["name"] age = req["age"] try: trainees = req[ "trainees"] # will be of the form: 'trainees' : {"uuid 1" : "name 1", "uuid 2" : "name 2"} except: trainees = {None: None} try: templates = req[ "templates"] # will be of the form: 'templates' : {"template id 1" : "template name 1", "template id 2" : "template name 2"} except: templates = {None: None} try: meetings = req[ "meetings"] # will be of the form: 'meetings' : {"uuid 1" : "datetime 1", "uuid 2" : "datetime 2"} except: meetings = {None: None} # set manager data path = 'Managers' data = { 'name': name, 'age': age, } db.child(path).child(manager_uuid).set(data) db.child(path).child(manager_uuid).child("trainees").set(trainees) db.child(path).child(manager_uuid).child("templates").set(templates) db.child(path).child(manager_uuid).child("meetings").set(meetings) return {"response": "success"}