Beispiel #1
0
def delete_fn():
    session = Session()
    data = request.get_json()
    x = data.get("x")
    delete_announcements=session.query(announcements).filter(announcements.id>=x).delete()
    #delete_announcements = announcements.delete().where(announcements.c.id > x)
    return jsonify({'info':'announcements are deleted '}),200
Beispiel #2
0
def employees():
    session = Session()
    emp_objects = session.query(employee).all()
    serialized_obj = serialize_all(emp_objects)
    #serialized_obj = [{"title":obj.title,"description":obj.description} for obj in emp_objects]
    session.close()
    return (jsonify(serialized_obj))
Beispiel #3
0
def login():
    print(request.get_json())
    emp_id = request.json.get("emp_id", None)
    password = request.json.get("password", None)
    login = False
    print(emp_id)
    print(password)
    if emp_id == None or password == None:
        return jsonify({"error:": "incorrect username or password"}), 200
    session = Session()
    print("pass here")

    auth_object = session.query(authUser).filter(
        authUser.emp_id == emp_id).first()
    if auth_object and auth_object.password == None:
        return jsonify({"warning":
                        "Password Not set Please set password"}), 200

    auth_object = session.query(authUser).filter(
        authUser.emp_id == emp_id, authUser.password == password).first()
    if auth_object == None:
        return jsonify({"error": "Username or password is incorrect"}), 200
    emp_obj = session.query(employee).filter(employee.emp_id == emp_id).first()
    employee_name = emp_obj.salutation + " " + emp_obj.first_name + " " + emp_obj.last_name
    roles = auth_object.roles
    login = True
    access_token = create_access_token(identity=emp_id)
    return jsonify(access_token=access_token,
                   username=emp_id,
                   roles=roles,
                   login=login,
                   employee_name=employee_name)
Beispiel #4
0
def timeData():
    manager_id = request.get_json()
    session = Session()
    emp_list = session.query(employee.emp_id).filter(employee.manager_id==manager_id).all()
    emp_final = [emp[0].lower() for emp in emp_list]
    time_final = []
    for emp in emp_final:
        project_time = 0
        sl = 0
        cl=0
        al=0
        bench=0
        user_id = emp
        unapproved=0

        user_name = session.query(employee.first_name).filter(employee.emp_id==emp).first()[0]
        submission_obj = session.query(timesubmissions).filter(timesubmissions.user_id==emp).all()
        serialized_obj = serialize_all(submission_obj)
        for time in serialized_obj:
            #print(time)
            if time['status']=='approved':
                if time['time_type']=='wfh' or time['time_type']=='REG':
                    project_time = project_time + time['hours']
                elif time['time_type']=='sl':
                    sl = sl + time['hours']
                elif time['time_type']=='cl':
                    cl = cl + time['hours']
                elif time['time_type']=='al':
                    al = al + time['hours']
                elif time['time_type']=='bench':
                    bench = bench + time['hours']
            else:
                unapproved = unapproved + time['hours']    
        
        total_hrs = project_time + sl + cl + al + bench
        time_final.append({'user_id':user_id, 'user_name': user_name, 'project_time':project_time,'sl':sl,'cl':cl,'al':al,'bench':bench,'unapproved':unapproved, 'total_hrs':total_hrs})
    print(">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>")
    print(time_final)  
    print(">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>")
    total_project = 0
    total_sl = 0
    total_cl = 0
    total_al = 0
    total_bench = 0
    total_unapproved = 0

    for emp_data in time_final:
        total_project = total_project  + emp_data['project_time']
        total_sl = total_sl  + emp_data['sl']
        total_cl = total_cl  + emp_data['cl']
        total_al = total_al  + emp_data['al']
        total_bench = total_bench  + emp_data['bench']
        total_unapproved = total_unapproved + emp_data['unapproved']
    total_time_list = {'total_project':total_project,'total_sl':total_sl,'total_cl':total_cl,'total_al':total_al,'total_bench':total_bench,'total_unapproved':total_unapproved, }
    print(total_time_list)
    #time_final.append({'total_project':total_project,'total_sl':total_sl,'total_cl':total_cl,'total_al':total_al,'total_bench':total_bench,'total_unapproved':total_unapproved, })
    return (jsonify({'result':time_final,'total':total_time_list}))
Beispiel #5
0
def projects():
    session = Session()
    project_objects = session.query(project).all()
    serialized_obj = serialize_all(project_objects)
    # serialized_obj = [{"project_id":obj.project_id,
    #                     "project_title":obj.project_title,
    #                     "project_start_date":obj.project_start_date,
    #                     "project_status":obj.project_status} for obj in project_objects]
    session.close()
    return (jsonify(serialized_obj))
Beispiel #6
0
def create_sample_employee(): 
    session = Session()
    emp_objects = session.query(employee).first()
    #serialized_obj = serialize_all(emp_objects)
    if not emp_objects:
        emp_data = employee(emp_id = "i3128",
                            first_name="ashok" , 
                            last_name = "kumar", 
                            sur_name= "", 
                            initial= "P", 
                            salutation= "Mr", 
                            project_code= "DIGI12345", 
                            dept= "DIGITAL", 

                            emp_start_date= datetime.datetime.now(),
                            emp_last_working_date=datetime.datetime.now(),
                            emp_project_assigned_date=datetime.datetime.now(),
                            emp_project_end_date=datetime.datetime.now(),

                            employment_status="INPROJECT", 
                            manager_name="NATARAJ", 
                            manager_dept="DIGITAL", 
                            resource_status = "BILLABLE",
                            delivery_type = "MANAGED SERVICES",
                            additional_allocation = "",
                            skills = "APP developement",
                            roles = "ADMIN"
                            )
        session.add(emp_data)
        session.commit()
        session.close()
def create_sample_employee(): 
    for emp in emp_list:
        session = Session()
        emp_object = session.query(employee).filter(employee.emp_id==emp['emp_id']).first()
        if emp_object==None:
            emp_data = employee(emp_id = emp['emp_id'].lower(),
                            manager_id = emp['manager_id'].lower(),
                            email = emp['email'].lower(),
                            first_name = emp['first_name'].lower(),
                            last_name = emp['last_name'].lower(),
                            sur_name = emp['sur_name'].lower(),
                            initial = emp['initial'].lower(),
                            salutation = emp['salutation'].lower(),
                            project_code = emp['project_code'].lower(),
                            dept = emp['dept'].lower(),
                            designation = emp['designation'].lower(),
                            emp_start_date = emp['emp_start_date'],
                            emp_last_working_date = emp['emp_last_working_date'],
                            emp_project_assigned_date = emp['emp_project_assigned_date'],
                            emp_project_end_date = emp['emp_project_end_date'],
                            employment_status = emp['employment_status'].lower(),
                            manager_name = emp['manager_name'].lower(),
                            manager_dept = emp['manager_dept'].lower(),
                            resource_status = emp['resource_status'].lower(),
                            delivery_type = emp['delivery_type'].lower(),
                            skills = emp['skills'].lower(),
                            roles = emp['roles'].lower()

                            )
            session.add(emp_data)
            session.commit()
        session.close()
Beispiel #8
0
def events():
    session = Session()
    time_objects = session.query(timesubmissions).all()
    serialized_obj = serialize_all(time_objects)
    events_data = []
    for event in serialized_obj:
        eve={}
        eve["title"]="*" + str(event["time_type"]) + " : "+ str(event["hours"]) + " Hours"
        eve["start"]=event["date_info"]
        events_data.append(eve)   
    return jsonify(events_data)
Beispiel #9
0
def get_announcements():
    session = Session()
    data = request.get_json()
    user_id = data.get("user_id")
    existing_announcements = session.query(announcements).filter(announcements.user_id==user_id).order_by(announcements.id.desc())[-30:]
    if existing_announcements:
    #ann = announcements.select([announcements]).order_by(-announcements.c.id.desc()).limit(2)
    #if ann:
        serialized_obj = serialize_all(existing_announcements)
        print(serialized_obj)
        return jsonify(serialized_obj),200  
    return jsonify({'info':'No announcements are available for you'}),200
Beispiel #10
0
def getResourceInfo():
    session =Session()
    data =request.get_json()
    print(">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>")
    project_ = session.query(project).filter(project.project_code==data).first()
  
    project_resources_list = project_.resource_info.split(",")
    for i in project_resources_list:
        if i=="":
            project_resources_list.remove(i)
    resource_info_data = session.query(employee).filter(employee.emp_id.in_(project_resources_list)).all()
    print(serialize_all(resource_info_data))
    return jsonify(serialize_all(resource_info_data))
Beispiel #11
0
def getTimeBy():
    session = Session()
    data = request.get_json()
    time_type = data['type']
    user = data['user']
    print(user)
    print(time_type)
    if user == 'total':
        if time_type =="project":
            time_type_list = ['wfh','REG']
        else:
            time_type_list = [time_type]
        sub_objects = session.query(timesubmissions).filter(timesubmissions.status=='approved',timesubmissions.time_type.in_(time_type_list)).all()
        serialized_obj = serialize_all(sub_objects)
        session.close()
        return (jsonify(serialized_obj)),200
        
    else:
        if time_type =="project":
            time_type_list = ['wfh','REG']
        else:
            time_type_list = [time_type]
        sub_objects = session.query(timesubmissions).filter(timesubmissions.status=='approved',timesubmissions.time_type.in_(time_type_list),timesubmissions.user_id==user).all()
        serialized_obj = serialize_all(sub_objects)
        session.close()
        return (jsonify(serialized_obj)),200
Beispiel #12
0
def reset_pass():
    session = Session()
    email = request.json.get('email')
    password = request.json.get('password')
    confirm_pass = request.json.get('password')
    token = request.json.get('reset_token')

    if email is None:
        return jsonify({"error:": "incorrect username or password"}), 400

    forget_pass_objects = session.query(forget_pass).filter(forget_pass.email_address == email)
    forget_pass_obj = serialize_all(forget_pass_objects)

    reset_token = forget_pass_obj[0]['reset_token']
    if reset_token == token:
        # update auth table password
        auth_object = session.query(authUser).filter(authUser.email == email).first()
        if auth_object is None:
            return jsonify({'error': 'User not found, This user is not added yet'}), 401
        auth_object.password = password
        session.add(auth_object)
        session.commit()

        return "Password Reset successfully", 200
    else:
        return "Please generate token for reset password  token expired"
Beispiel #13
0
def viewsubmissions():
    session = Session()
    data = request.get_json()
    manager_name = data  
    print(manager_name)
    emp_list = session.query(employee.emp_id).filter(employee.manager_id==manager_name).all()
    emp_final = [emp[0].lower() for emp in emp_list]
    print(emp_final)
    submission_obj = session.query(timesubmissions).filter(timesubmissions.manager_id.in_(emp_final),timesubmissions.status=='submitted-pending approval' ).all()
    print(submission_obj)
    if submission_obj:
        serialized_obj = serialize_all(submission_obj)
        print(serialized_obj)
        return jsonify(serialized_obj),200
    return jsonify({'info':'No submission available for you'}),200
def time_master():
    session = Session()
    time_objects = session.query(TimeMaster).first()
    if not time_objects:
        time_objects = TimeMaster(emp_id="i3128",
                                  month="01",
                                  year="2021",
                                  timedata=""
                                  )
        session.add(time_objects)
        session.commit()
        session.close()
Beispiel #15
0
def setpassword():
    session = Session()
    emp_id = request.json.get("emp_id", None)
    password = request.json.get("password", None)
    auth_object = session.query(authUser).filter(authUser.emp_id == emp_id).first()
    if auth_object is None:
        return jsonify({'error':'User not found, This user is not added yet'}), 200
    auth_object.password=password
    session.add(auth_object)
    session.commit()
    session.close()
    return jsonify({'success':'password set successfully ! Please login with your new password'}),200
def create_sample_authUser():    
    for authUsers in authUser_list:
        session = Session()
        auth_objects = session.query(authUser).filter(authUser.emp_id==authUsers["emp_id"]).first()
        if auth_objects==None: 
            auth_data = authUser( emp_id =authUsers["emp_id"].lower(), 
                                    email = authUsers["email"].lower(),
                                    password = authUsers["password"].lower(),
                                    roles = authUsers["roles"].lower()
                                    )
            print(auth_data)
            session.add(auth_data)
            session.commit()  
        session.close()    
Beispiel #17
0
def getSubmissionsBy():
    session = Session()
    user = request.get_json()
    if user == 'total':
        sub_objects = session.query(timesubmissions).filter(timesubmissions.status=='submitted-pending approval').all()
        serialized_obj = serialize_all(sub_objects)
        session.close()
        return (jsonify(serialized_obj)),200
        
    else:
        sub_objects = session.query(timesubmissions).filter(timesubmissions.status=='submitted-pending approval', timesubmissions.user_id==user).all()
        serialized_obj = serialize_all(sub_objects)
        session.close()
        return (jsonify(serialized_obj)),200
def create_sample_timesubmissions():    
    for timesubmission in timesubmission_list: 
        session = Session()
        sub_objects = session.query(timesubmissions).filter(timesubmissions.date_info==timesubmission["date"]).first()
        if sub_objects==None:
            sub_data = timesubmissions( date_info=timesubmission['date'],
                                            hours = timesubmission['hours'],
                                            user_id = timesubmission['user_id'].lower(),
                                            project_code = timesubmission['project_id'].lower(),
                                            manager_id = timesubmission['manager_id'].lower(),
                                            time_type = timesubmission['time_type'].lower(),
                                            status = timesubmission["status"].lower(),
                                            submission_id = timesubmission["submission_id"].lower()    
                                    )
            print(sub_data)
            session.add(sub_data)
            session.commit()    
        session.close()
Beispiel #19
0
def viewEmpInfo():
    emp_id = request.json.get("emp_id", None)
    print("????????????")
    print(emp_id)
    if emp_id is None:
        return jsonify({"error":"Employee ID is empty"}), 201
    session = Session()
    emp_objects = session.query(employee).filter(employee.emp_id==emp_id).all()
    print(">>>>>>>>>>>>")
    print(emp_objects)
    if emp_objects == []:
        return jsonify({"error":"Employee Not found !"}), 201
    emp_serialized = serialize_all(emp_objects)
    print(emp_serialized)
    emp_dict = emp_serialized[0]
    project_objects = session.query(project).filter(project.project_code==emp_serialized[0]['project_code']).all()
    if project_objects:
        project_serialized = serialize_all(project_objects)
        proj_dict = project_serialized[0]
        emp_dict.update(proj_dict)
    emp_dict['full_name'] = emp_dict['salutation'] + emp_dict['first_name'] + emp_dict['last_name']
    return jsonify(emp_dict), 201
Beispiel #20
0
def addtimesubmissions():    
    data = request.get_json() 
    user_id = data.get('user_id')
    session = Session()
    existing_emp = session.query(employee).filter(employee.emp_id == user_id ).first()
    if existing_emp == None:
        return jsonify({'error':'user not available in the employee table'}),200
    sub_data = timesubmissions( date_info = data.get('date'),
                                    hours = data.get('hours').lower(),
                                    user_id = data.get('user_name').lower(),
                                    project_code = data.get('project_id').lower(),
                                    manager_id = data.get('manager_name').lower(),
                                    time_type = data.get('time_type').lower(),
                                    status = 'submitted-pending approval',
                                    submission_id = data.get('user_id') + data.get('user_id') + data.get('time_type')     
                               )
    session = Session()
    session.add(sub_data)
    session.commit()
    return jsonify({'success':'Your Time has been  submitted for: {}'.format(data.get('date'))}),200
Beispiel #21
0
def create_sample_project(): 
    session = Session()
    project_objects = session.query(project).first()
    #serialized_obj = serialize_all(emp_objects)
    if not project_objects:
        project_objects = project(client_name = "Pi-Lit",
                            project_code="DIGI12345" , 
                            project_name = "Pi-lit", 
                            project_start_date=  datetime.datetime.now(),
                            project_status= "In Progress", 
                            billing_type= "F", 
                            segment= "Consulting Services", 
                            geography= "US", 
                            solution_category="Product Development", 
                            financial_year="2020", 
                            
                            )
        session.add(project_objects)
        session.commit()
        session.close()
Beispiel #22
0
def login():
    emp_id = request.json.get("emp_id", None)
    password = request.json.get("password", None)
    login=False
    if emp_id==None or password==None:
        return jsonify({"error:":"incorrect username or password"}), 200
    session = Session()
    # we can use both emp_id and email as a user id.
    if emp_id.find("@") != -1:
        auth_object = session.query(authUser).filter(authUser.email == emp_id, authUser.password == password).first()
    else:
        auth_object = session.query(authUser).filter(authUser.emp_id == emp_id, authUser.password == password).first()

    if auth_object and auth_object.password==None:
        return jsonify({"warning": "Password Not set Please set password"}), 200

    if auth_object is None:
        return jsonify({"error": "Username or password is incorrect"}), 200
    emp_obj = session.query(employee).filter(employee.emp_id == emp_id).first()
    employee_name = "Full Name"
    roles = auth_object.roles
    login=True
    access_token = create_access_token(identity=emp_id)
    return jsonify(access_token=access_token,username=emp_id,roles=roles,login=login,employee_name = employee_name)
def create_sample_project(): 
    for sample in project_list:
        session = Session()
        sample_objects = session.query(project).filter(project.project_code==sample["projectcode"]).first()
        #serialized_obj = serialize_all(emp_objects)
        if sample_objects==None:
            sample_data = project(client_name = sample["clientname"].lower(),
                                    project_code=sample["projectcode"].lower(),
                                    project_name=sample["projectname"].lower(),
                                    project_start_date=sample["project_start_date"].lower(),
                                    project_status=sample["projectstatus"].lower(),
                                    billing_type=sample["billingtype"].lower(),
                                    segment=sample["segment"].lower(),
                                    geography=sample["geography"].lower(),
                                    solution_category =sample["solution_category"].lower(),
                                    financial_year = sample["financialyear"].lower(),
                                    resource_info = sample["resource_info"].lower()
                                )         
            print(sample_data)  
            session.add(sample_data)
            session.commit()
        session.close()
Beispiel #24
0
def add_announcements():
    data = request.get_json()
    announcement_data = announcements (user_id =data.get('user_id').lower(),
                                       announcement_info = data.get('announcement_info').lower(),
                                       announcement_category=data.get('announcement_category').lower(),
                                       date_logged = datetime.datetime.now(),
                                        )
    session = Session()
    session.add(announcement_data)
    session.commit()    
    return ({'success':'Announcements are added sucessfully '})
Beispiel #25
0
def employees():
    session = Session()
    emp_objects = session.query(employee).all()
    serialized_obj = serialize_all(emp_objects)
    serialed_out = []
    for dictionary in serialized_obj:
        dictionary['full_name'] = dictionary['first_name'] + dictionary['last_name']
        serialed_out.append(dictionary)

    project_objects = session.query(project).all()
    serialized_project = serialize_all(project_objects)
    for dictionary in serialed_out:
        emp_id = dictionary["project_code"]
        for proj_item in serialized_project:
            if proj_item["project_code"]==emp_id:
                proj_item["project_code"] = [emp_id] #Project id should return list instead of string in employee
                dictionary.update(proj_item)
                break
    session.close()
    return (jsonify(serialed_out))
Beispiel #26
0
def forgot_pass_create_token():
    session = Session()
    email_id = request.json.get("email_id")
    emp_objects = session.query(employee).filter(employee.email == email_id).first()
    if emp_objects == None:
        return jsonify({"error":" Please enter Valid employee Email Id"})

    emp_id = emp_objects.emp_id
    forget_pass_data = session.query(forget_pass).filter(forget_pass.user_id == emp_id,
                                                         forget_pass.email_address == email_id,
                                                         ).first()
    access_token = create_access_token(identity=emp_id)
    current_date = datetime.datetime.now()

    if forget_pass_data == None:
        forget_pass_obj = forget_pass(user_id=emp_id, email_address=email_id, reset_token=access_token, create_date=current_date)
        session.add(forget_pass_obj)
        session.commit()
        session.close()

    else:
        forget_pass_data.reset_token = access_token
        forget_pass_data.create_data = current_date
        session.add(forget_pass_data)
        session.commit()
        session.close()

        html_body = render_template('frontend/frontend/src/app/reset-password/reset-password.component.html',
                                    user=email_id, token=access_token)
        text_body = "http://localhost:4200/" + 'resetpassword/?token='+access_token +'&'+'email='+email_id
        entities.mail.send_mail("Forgot password setup", Config.MAIL_USERNAME, email_id, html_body, text_body)

        return jsonify(text_body), 201
Beispiel #27
0
def addProject():
    data = request.get_json()

    session = Session()
    existing_project = session.query(project).filter(project.project_code==data.get("projectcode")).first()
    if existing_project:
        session.close()
        return jsonify({'warning':'Project with ID: {} already exist !'.format(data.get("projectcode"))})
    try:     
        project_data = project(client_name = data.get("clientname").lower(),
                                project_code=data.get("projectcode").lower(),
                                project_name=data.get("projectname").lower(),
                                project_start_date=data.get("project_start_date",None),                                
                                project_status=data.get("projectstatus").lower(),
                                billing_type=data.get("billingtype").lower(),
                                segment=data.get("segment").lower(),
                                geography=data.get("geography").lower(),
                                solution_category =data.get("solutioncategory").lower(),
                                financial_year = data.get("financialyear").lower()
        
        )
        session = Session()
        session.add(project_data)
        session.commit()
        session.close()
        return jsonify({"success":"added data to the table successfully"}), 201
    except:
        return jsonify({"error":"Something happened while adding the data to the table, please check the data and try again"}), 500
Beispiel #28
0
def addProjectmanager():
    session = Session()
    data = request.get_json()
    project_code = data.get("project_id")
    project_manager=data.get('manager_id')
    print(project_code)
    print(project_manager)
    existing_project = session.query(project).filter(project.project_code==project_code).first()
    if existing_project==None:
        return jsonify({'error':'Project with ID: {} Does not Exist !'.format(project_code)})
    
    existing_project_manager= session.query(employee).filter(employee.manager_id==project_manager).first()
    if existing_project_manager==None:
        return jsonify({"error":"Manager ID {} Does not Exists !".format(project_manager)})

    #existing_project_manager.project_code = project_code
    #session.add(existing_project_manager)
    #session.commit()
    if existing_project.project_manager_id == None:
        existing_project.project_manager_id = project_manager
        session.add(existing_project)
        session.commit()
    else:
        existing_PM = existing_project.project_manager_id
        print(existing_PM)
        existing_PM_list = stringToList(existing_PM)
        print(existing_PM_list)
        if project_manager in existing_PM_list:
            return  jsonify({'error':'Project Manager already Exists in the project'})
        existing_PM_list.append(project_manager)
        print(existing_PM_list)
        existing_project.project_manager_id=listToString(existing_PM_list)
        print(existing_PM_list)
        session.add(existing_project)
        session.commit()
    session.close()
    return jsonify({"success":"Manager {} and Project {} Linked".format(project_manager,project_code)})
Beispiel #29
0
def addProjectResource():
    session = Session()
    data = request.get_json()
    resource_id = data.get("emp_id")
    project_code = data.get("project_id")
    existing_emp = session.query(employee).filter(employee.emp_id==resource_id).first()
    if existing_emp==None:
        return jsonify({'success':'Employee with ID: {} Does not Exist !'.format(resource_id)})
    
    existing_project = session.query(project).filter(project.project_code==project_code).first()
    if existing_project==None:
        return jsonify({'error':'Project with ID: {} Does not Exist !'.format(project_code)})
    print(existing_emp)
    print("<<<<<<<<<<")
    resource_data=existing_emp.emp_id
    print(resource_data)
    if existing_emp.project_code == None:
        existing_emp.project_code=project_code
        session.add(existing_emp)
        session.commit()
    else:
        existing_proj_code= existing_emp.project_code
        existing_proj_list = stringToList(existing_proj_code)
        if project_code in existing_proj_list:
            return jsonify({'error':'resource exist already in the project'})
        existing_proj_list.append(project_code)
        
        existing_emp.project_code = listToString(existing_proj_list)# check if the string sanitation is required
        print(type(existing_emp.project_code))
        session.add(existing_emp)
        session.commit()

    # existing_emp.project_code=project_code
    # session.add(existing_emp)
    # session.commit()
    if existing_project.resource_info == None:
        existing_project.resource_info=resource_id
        session.add(existing_project)
        session.commit()
    
    else:
        existing_resource = existing_project.resource_info
        print(existing_resource)
        existing_resource_list=stringToList(existing_resource)#stringToList fn convert str to list 
        print(type(existing_resource_list))
        print(existing_resource_list)
        if resource_id in existing_resource_list:
            return jsonify({'error':'resource exist already in the project'})
        existing_resource_list.append(resource_id )
        existing_project.resource_info = listToString(existing_resource_list)#listToString convert list to str 
        print(existing_resource_list)
        session.add(existing_project)
        session.commit()

    session.close()
    return jsonify({"success":"Employee {} and Project {} Linked".format(resource_id,project_code)})
Beispiel #30
0
def removeresource():
    session=Session()
    data=request.get_json()
    emp_id=data.get("emp_id")
    project_code=data.get("project_id")
    print("<<<<<<<<<<<<")
    print(emp_id)
    print("<<<<<<<<<<<<")
    print(project_code)
    project_=session.query(project).filter(project.project_code==project_code).first()
    project_resources_list=project_.resource_info.split(",")
    print("<<<<<<<<<<<<")
    print(project_resources_list)
    try:
        project_resources_list.remove(emp_id)
    except:
        pass
    print(project_resources_list)
    out_PM =''
    for i in project_resources_list:
        out_PM = i + "," + out_PM

    project_.resource_info = out_PM
    session.add(project_)
    session.commit()
    session.close()

    emp_=session.query(employee).filter(employee.emp_id==emp_id).first()
    emp_project_list=emp_.project_code.split(",")
    print("<<<<<<<<<<<<<<")
    print(emp_project_list)
    try:
        emp_project_list.remove(project_code)
    except:
        pass
    print(emp_project_list)
    out_proj=""
    for i in emp_project_list:
        out_proj= i+","+out_proj
    
    emp_.project_code=out_proj
    session.add(emp_)
    session.commit()   
    session.close()

    return jsonify({"success":"Resource {} removed from project".format(emp_id)})