def worker_start_docs(): """ Here user can check if worker delivered all documents needed for hire :return: index page if everything is OK """ required_role(current_user, "user") worker_name = request.args.get("worker_name") worker = Worker.query.filter_by(name=worker_name).first() title = "HR - dokumenty główne: {}".format(worker.name) form = NewStartDocForm() form.doc_type.choices = [(str(doc_type), str(doc_type)) for doc_type in StartDocType.query.all()] if form.validate_on_submit(): doc = form.doc_type.data workers_utils.create_worker_start_docs(worker_name, [doc]) return redirect( url_for("workers.worker_start_docs", worker_name=worker_name)) return render_template("workers/worker_list_start_docs.html", title=title, docs=worker.start_docs, worker=worker, form=form)
def index(): """ Renders main page :return: main page if workers is logged """ required_role(current_user, "user") title = "HR - strona główna" return render_template("main/main_page.html", title=title)
def edit_start_doc_type(): """ Changes name of start document type :return: "OK" if successful and "ERROR" if not """ required_role(current_user, "user") data = request.json if start_docs_utils.change_start_doc_type_name(data) is False: return "ERROR" return "OK"
def list_start_doc_type(): """ Allows to change name of start document type :return: renders template with list of all start document types """ required_role(current_user, "user") types = StartDocType.query.all() title = "HR - lista rodzajów dokumentóœ głównych" return render_template("start_docs/start_doc_types_list.html", title=title, types=types)
def create_start_docs(worker_name): """ Creates records in db for each document user choose is required :param worker_name: worker's name :return: url for worker_start_docs """ required_role(current_user, "user") data = request.json workers_utils.create_worker_start_docs(worker_name, data) return url_for("workers.worker_start_docs", worker_name=worker_name)
def delete_start_doc_type(doctype_id): """ Deletes given type of start document :param doctype_id: id of doctype to be deleted :return: redirect back to list of start doc types (list_start_doc_type() function) """ required_role(current_user, "user") if start_docs_utils.remove_start_doctype(doctype_id) is True: flash("Typ dokumentu usunięty") else: flash("Błąd. Upewnij się, że taki typ dokumentu istnieje. Ktoś mógł go usunąć w międzyczasie.") return redirect(url_for("start_docs.list_start_doc_type"))
def start_docs_status_upgrade(): """ Checks if data delivered by front is correct and updates start documents records :return: url to main page if data is correct. Else returns False """ required_role(current_user, "user") data = request.json response = workers_utils.upgrade_start_docs_status(data) if response: return {"response": url_for("main.index")} return {"response": False}
def delete_worker(worker_id): """ Deletes worker and all related documents and events :param worker_id: id of worker to be deleted :return: redirect back to main page """ required_role(current_user, "user") if workers_utils.del_worker(worker_id) is True: flash("Pracownik usunięty") else: flash( "Błąd. Upewnij się, że taki pracownik istnieje. Ktoś mógł go usunąć w międzyczasie." ) return redirect(url_for("main.index"))
def start_docs_required(worker_id): """ Allows to manage start documents of worker :param worker_id: worker's db id :return: renders template with list of all documents where user can choose which of them are needed to hire eworker """ required_role(current_user, "user") worker = Worker.query.filter_by(id=worker_id).first() documents = StartDocType.query.order_by(StartDocType.id).all() title = "HR - wybór dokumentów do zatrudnienia" return render_template("workers/worker_select_start_docs.html", title=title, docs=documents, worker=worker)
def new_start_doc_type(): """ Allows to create new type of main document (eg. job contract) :return: renders template with form for new start doc type """ required_role(current_user, "user") title = "HR - nowy rodzaj dokumentu głównego" form = NewStartDocTypeForm() if form.validate_on_submit(): if start_docs_utils.add_start_doc_type(form) is False: flash("Taki dokument już istnieje") else: flash("{} - nowy rodzaj dokumentu utworzony pomyślnie".format(form.name.data)) return render_template("start_docs/new_start_doc_type.html", title=title, form=form)
def edit_worker_basic(): """ Gets json with new workers data and updates records in database. Used by app/static/js/workers/edit_worker.js in app/templates/workers/show_worker.html :return: url for show_worker view """ required_role(current_user, "user") data = request.json if not data["OK"]: return {"response": False} workers_utils.edit_worker_basic_info(data) return { "response": url_for("workers.show_worker", worker_id=data["worker_id"]) }
def show_worker(worker_id): """ Shows important worker's info and allows to edit it :param worker_id: id of chosen worker :return: template with worker's info """ required_role(current_user, "user") worker = Worker.query.filter_by(id=int(worker_id)).first() workplaces = Workplace.query.all() functions = Function.query.all() title = "HR dane pracownika {}".format(worker.name) return render_template("workers/show_worker.html", title=title, worker=worker, workplaces=workplaces, functions=functions)
def add_worker(): """ Adds new worker to db :return: redirects to created worker's start documents or, if worker already exists, gives user info about that """ required_role(current_user, "user") title = "HR - nowy pracownik" form = NewWorkerForm() form.workplace.choices = [(str(worker), str(worker)) for worker in Workplace.query.all()] form.function.choices = [(str(function), str(function)) for function in Function.query.all()] if form.validate_on_submit(): worker = workers_utils.add_worker_submit_form(form) if worker[0]: return redirect( url_for("workers.start_docs_required", worker_id=worker[1])) flash("Użytkownik {} już istnieje".format(form.name.data)) return render_template("workers/add_worker.html", title=title, form=form)
def workers_query(): """ Allows to filter workers which user wants to find :return: list of workers meeting requirements """ required_role(current_user, "user") title = "HR wyszukaj pracownika" form = FilterWorkersForm() form.workplace.choices = [(str(workplace), str(workplace)) for workplace in Workplace.query.all()] form.workplace.choices.insert(0, ("all", "wszystkie")) form.function.choices = [(str(function), str(function)) for function in Function.query.all()] form.function.choices.insert(0, ("all", "wszystkie")) if form.validate_on_submit(): workers = workers_utils.query_workers(form) return render_template("workers/workers_list.html", workers=workers) return render_template("workers/workers_query.html", title=title, form=form)