Beispiel #1
0
def find_next_increment(column, string, max_length=None):
    """Get the next incremented string based on `column` and `string`.

    Example::

        find_next_increment(Category.slug, 'category name')
    """
    string = _strip_ending_nums(string)
    existing = session.query(column).filter(column.like('%s%%' % string)).all()
    return get_next_increment(flatten_iterator(existing), string, max_length)
Beispiel #2
0
def find_next_increment(column, string, max_length=None):
    """Get the next incremented string based on `column` and `string`.

    Example::

        find_next_increment(Category.slug, 'category name')
    """
    string = _strip_ending_nums(string)
    existing = session.query(column).filter(column.like('%s%%' % string)).all()
    return get_next_increment(flatten_iterator(existing), string, max_length)
Beispiel #3
0
#!/usr/bin/env python
# -*- coding: utf-8 -*-
from sqlalchemy_schemadisplay import create_uml_graph, create_schema_graph
from sqlalchemy.orm import class_mapper
from sqlalchemy.orm.exc import UnmappedClassError
from inyoka.core.api import db, ctx, IResource
from inyoka.utils import flatten_iterator

models = list(
    flatten_iterator(
        x.models for x in ctx.get_implementations(IResource, instances=True)))

# lets find all the mappers in our model
mappers = []
tables = []
for model in models:
    try:
        mappers.append(class_mapper(model))
        tables.extend(mappers[-1].tables)
    except UnmappedClassError:
        continue

# pass them to the function and set some formatting options
uml = create_uml_graph(
    mappers,
    show_operations=False,  # not necessary in this case
    show_multiplicity_one=False  # some people like to see the ones, some don't
)
uml.write_png('uml.png')  # write out the file

schema = create_schema_graph(list(set(tables)))
Beispiel #4
0
def test_flatten_iterator():
    eq_(list(flatten_iterator([1, [2, 3, [5, 6]], [1, 2]])),
                              [1, 2, 3, 5, 6, 1, 2])
    eq_(tuple(flatten_iterator((1, 2, 3, 4))), (1, 2, 3, 4))
Beispiel #5
0
def flatten_data(data):
    return {d.keys()[0]: list(flatten_iterator(d.values())) for d in data}
Beispiel #6
0
def test_flatten_iterator():
    eq_(list(flatten_iterator([1, [2, 3, [5, 6]], [1, 2]])),
        [1, 2, 3, 5, 6, 1, 2])
    eq_(tuple(flatten_iterator((1, 2, 3, 4))), (1, 2, 3, 4))
Beispiel #7
0
#!/usr/bin/env python
# -*- coding: utf-8 -*-
from sqlalchemy_schemadisplay import create_uml_graph, create_schema_graph
from sqlalchemy.orm import class_mapper
from sqlalchemy.orm.exc import UnmappedClassError
from inyoka.core.api import db, ctx, IResource
from inyoka.utils import flatten_iterator

models = list(flatten_iterator(x.models for x in ctx.get_implementations(IResource, instances=True)))

# lets find all the mappers in our model
mappers = []
tables = []
for model in models:
    try:
        mappers.append(class_mapper(model))
        tables.extend(mappers[-1].tables)
    except UnmappedClassError:
        continue

# pass them to the function and set some formatting options
uml = create_uml_graph(mappers,
    show_operations=False, # not necessary in this case
    show_multiplicity_one=False # some people like to see the ones, some don't
)
uml.write_png('uml.png') # write out the file

schema = create_schema_graph(list(set(tables)))
schema.write_png('schema.png')
Beispiel #8
0
def flatten_data(data):
    return {d.keys()[0]: list(flatten_iterator(d.values())) for d in data}