Exemplo n.º 1
0
def create_fixtures():
    loader = Loader('opennews', project_label='Open News',
                    project_settings={},
                    source_url=DEFAULT_SOURCE_URL)
    
    import_schema(loader.project, StringIO(SCHEMATA))

    reader = unicodecsv.reader(StringIO(DATA))
    reader.next()
     
    for record in reader:
        fellow = loader.make_entity(['fellow'])
        fellow.set('name', record[0])
        fellow.set('twitter_handle', record[1])
        fellow.save()
     
        news_org = loader.make_entity(['news_organization'])
        news_org.set('name', record[4])
        news_org.set('url', record[5])
        news_org.save()
     
        fellowship = loader.make_relation('fellowship', fellow, news_org)
        fellowship.set('start_date', record[2])
        fellowship.set('end_date', record[3])
        fellowship.save()

    loader.persist()
Exemplo n.º 2
0
def save(data, project=None):
    """ Create or update a project with a given slug. """

    data = validate(data, project)

    operation = 'create' if project is None else 'update'
    if project is None:
        project = Project()
        project.slug = data.get('slug')
        project.author = data.get('author')

        from grano.logic import permissions as permissions_logic
        permissions_logic.save({
            'account': data.get('author'),
            'project': project,
            'admin': True
        })

    project.settings = data.get('settings')
    project.label = data.get('label')
    project.private = data.get('private')
    project.updated_at = datetime.utcnow()

    db.session.add(project)

    # TODO: make this nicer - separate files?
    from grano.logic.schemata import import_schema
    with app.open_resource('fixtures/base.yaml') as fh:
        import_schema(project, fh)

    db.session.flush()
    _project_changed(project.slug, operation)
    return project
Exemplo n.º 3
0
def save(data, project=None):
    """ Create or update a project with a given slug. """

    data = validate(data, project)

    operation = 'create' if project is None else 'update'
    if project is None:
        project = Project()
        project.slug = data.get('slug')
        project.author = data.get('author')

        from grano.logic import permissions as permissions_logic
        permissions_logic.save({
            'account': data.get('author'),
            'project': project,
            'admin': True
            })

    project.settings = data.get('settings')
    project.label = data.get('label')
    project.private = data.get('private')
    project.updated_at = datetime.utcnow()
    
    db.session.add(project)
    
    # TODO: make this nicer - separate files? 
    from grano.logic.schemata import import_schema
    with app.open_resource('fixtures/base.yaml') as fh:
        import_schema(project, fh)

    db.session.flush()
    _project_changed(project.slug, operation)
    return project
Exemplo n.º 4
0
def create_fixtures():
    loader = Loader('opennews',
                    project_label='Open News',
                    project_settings={},
                    source_url=DEFAULT_SOURCE_URL)

    import_schema(loader.project, StringIO(SCHEMATA))

    reader = unicodecsv.reader(StringIO(DATA))
    reader.next()

    for record in reader:
        fellow = loader.make_entity(['fellow'])
        fellow.set('name', record[0])
        fellow.set('twitter_handle', record[1])
        fellow.save()

        news_org = loader.make_entity(['news_organization'])
        news_org.set('name', record[4])
        news_org.set('url', record[5])
        news_org.save()

        fellowship = loader.make_relation('fellowship', fellow, news_org)
        fellowship.set('start_date', record[2])
        fellowship.set('end_date', record[3])
        fellowship.save()

    loader.persist()
Exemplo n.º 5
0
def save(data, project=None):
    """ Create or update a project with a given slug. """

    data = validate(data, project)

    if project is None:
        project = Project()
        project.slug = data.get('slug')
        project.author = data.get('author')

    project.settings = data.get('settings')
    project.label = data.get('label')
    project.updated_at = datetime.utcnow()

    db.session.add(project)

    # TODO: make this nicer - separate files?
    from grano.logic.schemata import import_schema
    with app.open_resource('fixtures/base.yaml') as fh:
        import_schema(project, fh)

    db.session.flush()
    return project
Exemplo n.º 6
0
def save(data, project=None):
    """ Create or update a project with a given slug. """

    data = validate(data, project)

    if project is None:
        project = Project()
        project.slug = data.get('slug')
        project.author = data.get('author')

    project.settings = data.get('settings')
    project.label = data.get('label')
    project.updated_at = datetime.utcnow()
    
    db.session.add(project)
    
    # TODO: make this nicer - separate files? 
    from grano.logic.schemata import import_schema
    with app.open_resource('fixtures/base.yaml') as fh:
        import_schema(project, fh)

    db.session.flush()
    return project