Example #1
0
def show_documents():
    """View with documents table"""

    document = Document(root_uri=os.environ['ROOT_BACKEND_URI'])

    all_documents = document.get_all_documents()

    context = {
        'all_documents': all_documents
    }

    return render_template('pages/tables/documents.html', **context)
Example #2
0
def add_task(document_idx: int):
    """View for adding new tasks (form)"""

    document = Document(root_uri=os.environ['ROOT_BACKEND_URI'])

    if document_idx:
        all_documents, all_document_tasks = document.get_one_document(
            document_id=document_idx)
        all_documents = [all_documents]
    else:
        all_documents = document.get_all_documents()

    from pprint import pprint
    pprint(all_documents)

    user = User(root_uri=os.environ['ROOT_BACKEND_URI'])
    all_users = user.get_all_users()

    factory = Factory(root_uri=os.environ['ROOT_BACKEND_URI'])
    all_factories = factory.get_all_factories()

    context = {
        'all_documents': all_documents,
        'all_users': all_users,
        'all_factories': all_factories
    }

    if request.method == 'POST':

        add_new_task_schema = AddNewTask()
        errors = add_new_task_schema.validate(data=request.form)

        if errors:
            abort(400, str(errors))

        args = add_new_task_schema.dump(request.form)

        task = Task(root_uri=os.environ['ROOT_BACKEND_URI'])

        task.add_task(task_name=args['task_name'],
                      executor_id=args['executor_id'],
                      document_id=args['document_id'],
                      factory_id=args['factory_id'])

        if document_idx:
            return redirect(
                url_for('show_documentation.show_one_document',
                        idx=document_idx))
        else:
            return redirect(url_for('show_documentation.show_tasks'))

    return render_template('pages/inputs/add_task.html', **context)
Example #3
0
def delete_document(document_idx: int):
    """View for deleting document"""

    document = Document(root_uri=os.environ['ROOT_BACKEND_URI'])

    document.delete_document(document_id=document_idx)

    all_documents = document.get_all_documents()

    context = {
        'all_documents': all_documents
    }

    return render_template('pages/tables/documents.html', **context)
Example #4
0
def change_task(task_idx: int):
    """View for task changing"""

    task = Task(root_uri=os.environ['ROOT_BACKEND_URI'])
    task_to_change = task.get_one_task(task_id=task_idx)

    document = Document(root_uri=os.environ['ROOT_BACKEND_URI'])
    all_documents = document.get_all_documents()

    user = User(root_uri=os.environ['ROOT_BACKEND_URI'])
    all_users = user.get_all_users()

    factory = Factory(root_uri=os.environ['ROOT_BACKEND_URI'])
    all_factories = factory.get_all_factories()

    for curr_user in all_users:
        if curr_user['id'] == task_to_change['executor_id']:
            curr_user['is_in_users'] = True
        else:
            curr_user['is_in_users'] = False

    for curr_document in all_documents:
        if curr_document['id'] == task_to_change['document_id']:
            curr_document['is_in_documents'] = True
        else:
            curr_document['is_in_documents'] = False

    for curr_factory in all_factories:
        if curr_factory['id'] == task_to_change['factory_id']:
            curr_factory['is_in_factories'] = True
        else:
            curr_factory['is_in_factories'] = False

    context = {
        'task': task_to_change,
        'all_documents': all_documents,
        'all_users': all_users,
        'all_factories': all_factories
    }

    if request.method == 'POST':

        add_new_task_schema = AddNewTask()
        errors = add_new_task_schema.validate(data=request.form)

        if errors:
            abort(400, str(errors))

        args = add_new_task_schema.dump(request.form)

        task = Task(root_uri=os.environ['ROOT_BACKEND_URI'])

        task.change_task(
            task_id=task_idx,
            task_name=args['task_name'],
            executor_id=args['executor_id'],
            document_id=args['document_id'],
            factory_id=args['factory_id']
        )

        return redirect(url_for('show_documentation.show_tasks'))

    return render_template('pages/changes/change_task.html', **context)