Esempio n. 1
0
def update_table():
    """View for table updating (using JQuery and ajax)"""

    update_table_schema = UpdateTableSchema()

    errors = update_table_schema.validate(request.args)

    # if user inputs not number or nothing, than show him all entries
    if errors:
        last_n_days = 0
    else:
        args = update_table_schema.dump(request.args)
        last_n_days = args['last_n_days']

    document = Document(connection=connection, cursor=cursor)

    if last_n_days == 0:
        documents_by_date = document.get_all_documents()
    else:
        documents_by_date = document.get_document_by_date(
            document_n_days=last_n_days)

    context = {'all_documents': documents_by_date}

    return render_template('pages/tables/documents_table.html', **context)
Esempio n. 2
0
def show_documents():
    """View with documents table"""

    document = Document(connection=connection, cursor=cursor)

    all_documents = document.get_all_documents()

    context = {'all_documents': all_documents}

    return render_template('pages/tables/documents.html', **context)
def delete_document(document_idx: int):
    """View for deleting document"""

    document = Document(connection=connection, cursor=cursor)

    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)
def delete_user(user_idx: int):
    """View for deleting users"""

    user = User(connection=connection, cursor=cursor)
    document = Document(connection=connection, cursor=cursor)

    user.delete_user(user_id=user_idx)
    document.delete_documents_with_no_users_assigned()

    all_users = user.get_all_users()

    context = {'all_users': all_users}

    return render_template('pages/tables/users.html', **context)
Esempio n. 5
0
def show_one_document(idx: int):
    """View for one document page"""

    document = Document(connection=connection, cursor=cursor)
    document_description = document.get_document_by_id(document_id=idx)

    task = Task(connection=connection, cursor=cursor)
    all_document_tasks = task.get_task_by_document_id(document_id=idx)

    context = {
        'document_description': document_description,
        'all_document_tasks': all_document_tasks
    }

    return render_template('pages/settings/document.html', **context)
Esempio n. 6
0
def change_document(document_idx: int):
    """View for document changing"""

    document = Document(connection=connection, cursor=cursor)

    document_to_change = document.get_document_by_id(document_id=document_idx)

    document_to_change['date_of_creation'] = datetime.strftime(
        document_to_change['date_of_creation'], '%Y-%m-%d')
    document_to_change['date_of_registration'] = datetime.strftime(
        document_to_change['date_of_registration'], '%Y-%m-%d')

    document_controllers = [
        curr_controller['id']
        for curr_controller in document_to_change['controllers']
    ]
    document_creators = [
        curr_controller['id']
        for curr_controller in document_to_change['creators']
    ]

    user = User(connection=connection, cursor=cursor)
    all_users = user.get_all_users()

    for curr_user in all_users:
        if curr_user['id'] in document_controllers:
            curr_user['is_in_controllers'] = True
        else:
            curr_user['is_in_controllers'] = False

        if curr_user['id'] in document_creators:
            curr_user['is_in_creators'] = True
        else:
            curr_user['is_in_creators'] = False

    context = {'all_users': all_users, 'document': document_to_change}

    if request.method == 'POST':
        creators_ids = request.form.getlist(
            'choose_creators')  # if there is no such name, returns empty list
        controllers_ids = request.form.getlist('choose_controllers')

        request_form = dict(request.form)
        request_form.pop('choose_creators')  # there is no need in it now
        request_form.pop('choose_controllers')

        request_form['creators_ids'] = creators_ids
        request_form['controllers_ids'] = controllers_ids

        request_form['date_of_creation'] = datetime.strptime(
            request_form['date_of_creation'], '%Y-%m-%d')
        request_form['date_of_registration'] = datetime.strptime(
            request_form['date_of_registration'], '%Y-%m-%d')

        add_new_document_schema = AddNewDocument()
        errors = add_new_document_schema.validate(data=request_form)

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

        args = add_new_document_schema.dump(request_form)

        document = Document(connection=connection, cursor=cursor)

        document.change_document(
            document_id=document_idx,
            document_name=args['document_name'],
            document_type=args['document_type'],
            date_of_creation=args['date_of_creation'],
            date_of_registration=args['date_of_registration'],
            controllers_ids=args['controllers_ids'],
            creators_ids=args['creators_ids'],
        )

        return redirect(
            url_for('show_documentation.show_one_document',
                    idx=document_to_change['id']))

    return render_template('pages/changes/change_document.html', **context)
Esempio n. 7
0
def change_task(task_idx: int):
    """View for task changing"""

    task = Task(connection=connection, cursor=cursor)
    task_to_change = task.get_task_by_id(task_id=task_idx)

    document = Document(connection=connection, cursor=cursor)
    all_documents = document.get_all_documents()

    user = User(connection=connection, cursor=cursor)
    all_users = user.get_all_users()

    factory = Factory(connection=connection, cursor=cursor)
    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(connection=connection, cursor=cursor)

        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)