def user_details(person_ID): """ Bring the overview of all the details to show :param job_number: :return: """ login_details = session["login_details"] user = User(login_details, person_ID) # jobs assigned to the user assigned_jobs = [] if user.assigned_jobs is not None: for job_number in user.assigned_jobs: job = Job(job_number, session["login_details"], user.id) assigned_jobs.append(job) # jobs that the user has worked on job_list = [] if user.jobs_list is not None: for list_entry in user.jobs_list: job_entry = Job(list_entry, login_details) job_list.append((job_entry.job_number, job_entry.title, job_entry.get_times(user.id))) # page function form = Form(request.form) if request.method == "POST" and assigned_jobs is not None: if sql_functions.verify_user_company_schema(session["login_details"]): for jobs in assigned_jobs: if jobs.job_number in request.form: if request.form[jobs.job_number] == "Start": start_time = jobs.start_time_entry(user.id) flash(start_time.strftime("%Y/%m/%d %H:%M")) elif request.form[jobs.job_number] == "Stop": finish_time = jobs.user_stop_log(user.id) flash(finish_time.strftime("%Y/%m/%d %H:%M")) return render_template( "private/users/main_details.html", user=user, assigned_jobs=assigned_jobs, job_list=job_list, form=form )
def job_main_details(job_number): """ Bring the overview of all the details to show :param job_number: :return: """ # TODO a lot of this code maybe able to be put in the Job Class login_details = session["login_details"] # Job details year, number = job_number.split("-") job_number_sql = (int(year), int(number)) job = Job(job_number_sql, login_details) client_company_list = [] client_company_id_list = [] # assigned users member_list = [] id_list = sql_functions.job_assigned_users(login_details, job_number_sql) if id_list is not None: for id_value in id_list: member_list.append(User(login_details, id_value)) else: member_list = None # User list user_list = [] number_list = sql_functions.get_all_user_ids(login_details) for number in number_list: if number in id_list: pass else: user_list.append(User(login_details, number)) # user that have put time to the job time_users = [] if job.timed_user_ids: for user_with_time in job.timed_user_ids: user_time = User(login_details, user_with_time) time_users.append((user_time.id, user_time.username, user_time.job_times(job.job_number_sql))) # get the list of companies so that one can be added to the job. if job.company_assigned: pass else: company_id_list = site_actions.ClientCompany.all_companies(login_details["company_schema"]) for company in company_id_list: client_company = site_actions.ClientCompany(company, login_details) client_company_list.append(client_company) client_company_id_list.append(company[0]) # page form details form = Form(request.form) if request.method == "POST": if sql_functions.verify_user_company_schema(login_details): user = session["login_details"]["person_ID"] if request.form["timer"] == "Start": start_time = job.start_time_entry(user) flash(start_time.strftime("%Y/%m/%d %H:%M")) elif request.form["timer"] == "Stop": finish_time = job.user_stop_log(user) flash(finish_time.strftime("%Y/%m/%d %H:%M")) elif request.form["timer"] == "Assign": user_assigned = [] for value in request.form: for user in user_list: if value == "user" + str(user.id): user_assigned.append(user.id) for user_id in user_assigned: values = (job_number_sql[0], job_number_sql[1], user_id) sql_functions.assign_users_to_job(values, login_details) elif request.form["timer"] == "Remove Members" and member_list is not None: remove_member = [] for value in request.form: for member in member_list: if value == "member" + str(member.id): remove_member.append(member.id) for member_id in remove_member: values = (job_number_sql[0], job_number_sql[1], member_id) sql_functions.remove_users_from_job(values, login_details) elif request.form["timer"] == "Assign company" and client_company_list is not None: for value in request.form: for client_id in client_company_id_list: try: if int(value) == client_id: job.add_client_company(int(value)) flash(value) except ValueError: pass return redirect(url_for("job_main_details", job_number=job.job_number)) current_user = User(session["login_details"]) return render_template( "private/jobs/main_details.html", job=job, user_list=user_list, member_list=member_list, time_users=time_users, current_user=current_user, client_company_list=client_company_list, form=form, )