Example #1
0
def show_one_document(idx: int):
    """View for one document page"""

    document = Document(root_uri=os.environ['ROOT_BACKEND_URI'])
    document_description, all_document_tasks = document.get_one_document(document_id=idx)

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

    return render_template('pages/settings/document.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 change_document(document_idx: int):
    """View for document changing"""

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

    document_to_change, all_document_tasks = document.get_one_document(document_id=document_idx)

    document_to_change['date_of_creation'] = datetime.strptime(document_to_change['date_of_creation'],
                                                               '%Y-%m-%d').date()
    document_to_change['date_of_creation'] = str(document_to_change['date_of_creation'])

    document_to_change['date_of_registration'] = datetime.strptime(document_to_change['date_of_registration'],
                                                                   '%Y-%m-%d').date()
    document_to_change['date_of_registration'] = str(document_to_change['date_of_registration'])

    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(root_uri=os.environ['ROOT_BACKEND_URI'])
    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(root_uri=os.environ['ROOT_BACKEND_URI'])

        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)