Exemple #1
0
 def test_nocreate_redundant(self):
     """ If a path already exists, an exception will be raised. """
     Path.objects.delete()
     wrds = fake.words(nb=5)
     pathstr = '/' + '/'.join(wrds)
     Path.create(self.admin, pathstr)
     try:
         Path.create(self.admin, pathstr)
         self.assertFalse(True)
     except OneBaseException as e:
         self.assertEqual(e.error_code, 'E-206')
Exemple #2
0
 def test_create_hierarchy(self):
     """ A complete path can be created. """
     Path.objects.delete()
     path = Path.create(self.admin, '/root2/a')
     path.save(self.admin)
     path = Path.create(self.admin, '/root2/b')
     path.save(self.admin)
     for p in Path.objects.all():
         logger.debug('Created path: {}'.format(p))
     self.assertEqual(Path.objects.count(), 3)
     self.assertEqual(len(Path.find('/root2').paths), 2)
Exemple #3
0
 def test_nocreate_parent_redundant(self):
     """ A parented path cannot be created. """
     Path.objects.delete()
     wrds = fake.words(nb=5)
     pathstr = '/' + '/'.join(wrds)
     Path.create(self.admin, pathstr)
     try:
         pathstr = '/' + '/'.join(wrds[:-1])
         Path.create(self.admin, pathstr)
         self.assertFalse(True)
     except OneBaseException as e:
         self.assertEqual(e.error_code, 'E-206')
Exemple #4
0
def add_slot_row():
    path = request.args['path']
    node = Path.find(path).node
    if node is None:
        return abort(500)

    class DynSlotInsertForm(SlotInsertForm):
        pass

    for key in node.get_keys():
        logger.debug('adding field {}'.format(key.name))
        setattr(DynSlotInsertForm, key.name, StringField())
        DynSlotInsertForm.ext_keys.update({
            key.name: key,
        })

    form = DynSlotInsertForm(request.form)

    if request.method == 'POST':
        if form.validate():
            form.submit(node=node, user=get_user())
            return redirect(url_for('node.view_node', path=path))
    return render_template('insert.html',
                           form=form,
                           title='Insert into {}'.format(node.title))
Exemple #5
0
def update_slow_row(row):
    path = request.args['path']
    node = Path.find(path).node
    if node is None:
        return abort(404)

    class DynSlotInsertForm(SlotInsertForm):
        pass

    for key in node.get_keys():
        slot = Slot.objects(row=int(row), key=key.id).first()
        logger.debug('adding field {}'.format(key.name))
        setattr(DynSlotInsertForm, key.name, StringField(default=slot.value))
        DynSlotInsertForm.ext_keys.update({
            key.name: key,
        })

    form = DynSlotInsertForm(request.form)

    if request.method == 'POST':
        if form.validate():
            form.submit(node=node, user=get_user(), update_row=row)
            return redirect(url_for('node.view_node', path=path))
    return render_template('update.html',
                           form=form,
                           title='Insert into {}'.format(node.title))
Exemple #6
0
def drop_slot():
    path = request.args['path']
    row_nums = [int(i) for i in request.args['rows'].split(",")]
    node = Path.find(path).node
    rows = []
    e = {
        'return_mimetype':
        'application/html',
        'static_url':
        common_settings.CONFIG['static'][common_settings.ONEBASE_MODE],
    }
    to_delete = []
    for row_num in row_nums:
        row = []
        for key in node.get_keys():
            slot = Slot.objects(key=key, row=row_num).first()
            to_delete.append(slot)
            row.append(slot.get_repr(environment=e))
        rows.append(row)
    if request.method == 'GET':
        return render_template('drop.html', rows=rows)
    elif request.method == 'POST' and 'YES' in request.form:
        for s in to_delete:
            Slot.objects(id=s.id).delete()
    return redirect(url_for('node.view_node', path=request.args['path']))
Exemple #7
0
def view_node():
    """ Find a node by a given path. """
    search = request.args.get('path')
    node = getattr(Path.find(search), 'node', None)
    title = 'No Node'
    offset = int(request.args.get('offset', 0))
    count = int(request.args.get('count', 100))
    query_set = []
    start = None
    end = None
    total = None
    node_keys = []
    if Path.find(search) is not None and node is None:
        return redirect(url_for('node.browse_nodes', path=search))
    if node is not None:
        if request.method == 'POST' and 'DELETE' in request.form:
            logger.debug("Delete nodes ?")
            if 'select_row' in request.form:
                rows = ','.join(request.form.getlist('select_row'))
                return redirect(
                    url_for('node.drop_slot', path=search, rows=rows))
        environment = {
            'return_mimetype':
            'application/html',
            'static_url':
            common_settings.CONFIG['static'][common_settings.ONEBASE_MODE],
        }
        total = node.row_count
        title = 'Node: {}'.format(node.title)
        total = node.row_count
        node_keys = node.get_keys()
        query_set = node.do_select(offset=offset,
                                   limit=count,
                                   expand_keys=True,
                                   expand_slots=True,
                                   environment=environment)
        import pprint
        logger.debug("Query set: {}".format(pprint.pformat(query_set)))
    return render_template("search.html",
                           node=node,
                           path=Path.find(search),
                           title=title,
                           node_keys=node_keys,
                           query_set=query_set,
                           start=offset,
                           end=offset + count,
                           total=total)
Exemple #8
0
def browse_nodes():
    """ Browse the nodes, one after another. """
    path = request.args.get('path', '')
    current = None
    node = None
    children = []
    if path is None or path == '':
        children = Path.objects(parent=None).all()
    else:
        current = Path.find(path)
        if current:
            node = current.node
            children = current.paths()
    if node is not None:
        return redirect(url_for('node.view_node', path=path))
    return render_template('browse.html',
                           title=(path or 'Browse Paths & Nodes'),
                           node=node,
                           current=current,
                           children=children)
Exemple #9
0
 def test_create(self):
     """ Root element can be created. """
     path = Path.create(self.admin, '/root')
     path.save(self.admin)
     self.assertEqual(Path.objects.count(), 1)
     self.assertIsNotNone(Path.objects(name='root').first())