Ejemplo n.º 1
0
def add_quality_data(data):
    """
    Adds the data quality items to the Quality Table
    :param data: A list of dicts (quality_data below)
    """
    from odmf import db
    with db.session_scope() as session:

        for q in data:
            if not session.query(db.Quality).get(q['id']):
                session.add(db.Quality(**q))
                logger.debug(f'Added quality level {q["id"]}')
        session.commit()
Ejemplo n.º 2
0
    def submit_config(self, filename, siteid, **kwargs):
        path = Path(filename.strip('/'))
        siteid = web.conv(int, siteid)
        user = kwargs.pop('user', web.user())
        config = di.ImportDescription.from_file(path.absolute)
        try:
            with db.session_scope() as session:
                messages = pi.submit(session, config, path, user, siteid)
                di.savetoimports(path.absolute, web.user(),
                                 [m.split()[0] for m in messages])

        except pi.DataImportError as e:
            raise web.redirect('..', error=str(e))

        else:
            raise web.redirect(path.parent().href,
                               msg='\n'.join(f' - {msg}' for msg in messages))
Ejemplo n.º 3
0
def add_admin(password=None):
    """
    Add an odmf.admin role to the person table
    :param password: The password of the admin. If missing you will be prompted
    :return:
    """
    from odmf import db
    from odmf.tools import hashpw
    password = password or getpass("Enter admin password:")
    with db.session_scope() as session:
        if session.query(db.Person).get('odmf.admin'):
            logger.info('odmf.admin exists already')
        else:
            user = db.Person(username='******',
                             firstname='odmf',
                             surname='admin',
                             access_level=4)
            user.password = hashpw(password)
            session.add(user)
            logger.info('odmf.admin user created')
Ejemplo n.º 4
0
def session(db) -> sqlalchemy.orm.Session:
    with db.session_scope() as session:
        yield session
Ejemplo n.º 5
0
import odmf.webpage.auth as auth
import odmf.db as db
import random
import string

with db.session_scope() as session:
    users = session.query(db.Person)
    for user in users:
        new_password = ''.join(
            random.choices(string.ascii_letters + string.digits, k=8))
        user.password = auth.hashpw(new_password)
        print(user.username, new_password)

    session.rollback()
Ejemplo n.º 6
0
def session(db):
    with db.session_scope() as session:
        yield session