Exemplo n.º 1
0
def populate():
    """
    Create the root node (:class:`~kotti.resources.Document`) and the 'about'
    subnode in the nodes tree if there are no nodes yet.
    """
    lrm = LocalizerRequestMixin()
    lrm.registry = get_current_registry()
    lrm.locale_name = get_settings()['pyramid.default_locale_name']
    localizer = lrm.localizer

    if DBSession.query(Node).count() == 0:
        localized_root_attrs = dict(
            [(k, localizer.translate(v)) for k, v in _ROOT_ATTRS.iteritems()])
        root = Document(**localized_root_attrs)
        root.__acl__ = SITE_ACL
        DBSession.add(root)
        localized_about_attrs = dict(
            [(k, localizer.translate(v)) for k, v in _ABOUT_ATTRS.iteritems()])
        root['about'] = Document(**localized_about_attrs)

        wf = get_workflow(root)
        if wf is not None:
            DBSession.flush()  # Initializes workflow
            wf.transition_to_state(root, None, u'public')

    populate_users()
Exemplo n.º 2
0
def populate():
    """
    Create the root node (:class:`~kotti.resources.Document`) and the 'about'
    subnode in the nodes tree if there are no nodes yet.
    """
    lrm = LocalizerRequestMixin()
    lrm.registry = get_current_registry()
    # noinspection PyPropertyAccess
    lrm.locale_name = get_settings()["pyramid.default_locale_name"]
    localizer = lrm.localizer

    if DBSession.query(Node.id).count() == 0:
        localized_root_attrs = {
            k: localizer.translate(v)
            for k, v in _ROOT_ATTRS.items()
        }
        root = Document(**localized_root_attrs)
        root.__acl__ = SITE_ACL
        DBSession.add(root)
        localized_about_attrs = {
            k: localizer.translate(v)
            for k, v in _ABOUT_ATTRS.items()
        }
        root["about"] = Document(**localized_about_attrs)

        wf = get_workflow(root)
        if wf is not None:
            DBSession.flush()  # Initializes workflow
            wf.transition_to_state(root, None, "public")

    populate_users()
Exemplo n.º 3
0
def populate():
    if DBSession.query(Node).count() == 0:
        root = Document(**_ROOT_ATTRS)
        root.__acl__ = SITE_ACL
        DBSession.add(root)
        root['about'] = Document(**_ABOUT_ATTRS)

    populate_users()
Exemplo n.º 4
0
def _add_document_from_file(filename, name, parent, title, package='kotti', 
                            directory='populate-content', acl=None):
    body = unicode(resource_string(package, os.path.join(directory, filename)))
    node = Document(name=name, parent=parent, title=title, body=body)
    if acl is not None:
        node.__acl__ = acl
    DBSession.add(node)
    return node
Exemplo n.º 5
0
def populate():
    if DBSession.query(Node).count() == 0:
        root = Document(**_ROOT_ATTRS)
        root.__acl__ = SITE_ACL
        DBSession.add(root)
        root['about'] = Document(**_ABOUT_ATTRS)

    if DBSession.query(Settings).count() == 0:
        settings = Settings(data={'kotti.db_version': get_version()})
        DBSession.add(settings)

    populate_users()
Exemplo n.º 6
0
def populate():
    if DBSession.query(Node).count() == 0:
        root = Document(**_ROOT_ATTRS)
        root.__acl__ = SITE_ACL
        DBSession.add(root)
        root['about'] = Document(**_ABOUT_ATTRS)

    if DBSession.query(Settings).count() == 0:
        settings = Settings(data={'kotti.db_version': get_version()})
        DBSession.add(settings)

    populate_users()
Exemplo n.º 7
0
def populate():
    if DBSession.query(Node).count() == 0:
        root = Document(**_ROOT_ATTRS)
        root.__acl__ = SITE_ACL
        DBSession.add(root)
        root['about'] = Document(**_ABOUT_ATTRS)

        wf = get_workflow(root)
        if wf is not None:
            DBSession.flush()  # Initializes workflow
            wf.transition_to_state(root, None, u'public')

    populate_users()
Exemplo n.º 8
0
def populate():
    if DBSession.query(Node).count() == 0:
        root = Document(**_ROOT_ATTRS)
        root.__acl__ = SITE_ACL
        DBSession.add(root)
        root['about'] = Document(**_ABOUT_ATTRS)

        wf = get_workflow(root)
        if wf is not None:
            DBSession.flush()  # Initializes workflow
            wf.transition_to_state(root, None, u'public')

    populate_users()
Exemplo n.º 9
0
def populate_root_document():
    if DBSession.query(Node).count() == 0:
        root = Document(name=u'', title=u'Front Page')
        root.__acl__ = SITE_ACL
        root.default_view = 'front-page'
        DBSession.add(root)
        url = JOB_CONTAINERS['url']
        root[url] = Document(title=u'Job Containers', owner=u'admin')
        set_groups(u'admin', root[url], set([u'role:owner']))

        wf = get_workflow(root)
        if wf is not None:
            DBSession.flush()  # Initializes workflow
            wf.transition_to_state(root, None, u'public')
Exemplo n.º 10
0
def populate():
    """
    Create the root node (Document) and the 'about' subnode in the nodes tree
    if there are no nodes yet.
    """

    if DBSession.query(Node).count() == 0:
        root = Document(**_ROOT_ATTRS)
        root.__acl__ = SITE_ACL
        DBSession.add(root)
        root['about'] = Document(**_ABOUT_ATTRS)

        wf = get_workflow(root)
        if wf is not None:
            DBSession.flush()  # Initializes workflow
            wf.transition_to_state(root, None, u'public')

    populate_users()
Exemplo n.º 11
0
def populate():
    """
    Create the root node (:class:`~kotti.resources.Document`) and the 'about'
    subnode in the nodes tree if there are no nodes yet.
    """

    if DBSession.query(Node).count() == 0:
        root = Document(**_ROOT_ATTRS)
        root.__acl__ = SITE_ACL
        DBSession.add(root)
        root['about'] = Document(**_ABOUT_ATTRS)

        wf = get_workflow(root)
        if wf is not None:
            DBSession.flush()  # Initializes workflow
            wf.transition_to_state(root, None, u'public')

    populate_users()
Exemplo n.º 12
0
def populate():
    """
    Create the root node (:class:`~kotti.resources.Document`) and the 'about'
    subnode in the nodes tree if there are no nodes yet.
    """
    lrm = LocalizerRequestMixin()
    lrm.registry = get_current_registry()
    lrm.locale_name = get_settings()['pyramid.default_locale_name']
    localizer = lrm.localizer

    if DBSession.query(Node.id).count() == 0:
        pkgdir = os.path.dirname(__file__)
        pagesdir = os.path.join(pkgdir, 'static/pages')
        #import pdb ; pdb.set_trace()
        root_filename = os.path.join(pagesdir, 'index.md')
        root_atts = make_markdown_attrs('', root_filename,
                                        title='Welcome to XYZZY',
                                        description='Home Page')
        root_atts['body'] = markdown.markdown(root_atts['body'])
        root = Document(**root_atts)
        root.__acl__ = SITE_ACL
        DBSession.add(root)
        webatts = make_markdown_attrs('webdesign',
                                      os.path.join(
                                          pagesdir, 'webdesign/index.md'),
                                      title='Web Design',
                                      description='Pages on Web Design')
        root['webdesign'] = MarkDownDocument(**webatts)
        wpages = ['history', 'development', 'stylesheets',
                  'javascript-components']
        for wp in wpages:
            wpfn = os.path.join(pagesdir, 'webdesign/%s.md' % wp)
            wptitle = ' '.join([p.capitalize() for p in wp.split('-')])
            wpatts = make_markdown_attrs(wp, wpfn, title=wptitle)
            root['webdesign'][wp] = MarkDownDocument(**wpatts)
        
        wf = get_workflow(root)
        if wf is not None:
            DBSession.flush()  # Initializes workflow
            wf.transition_to_state(root, None, u'public')

    populate_users()
Exemplo n.º 13
0
def populate():
    """
    Create the root node (:class:`~kotti.resources.Document`) and the 'about'
    subnode in the nodes tree if there are no nodes yet.
    """
    lrm = LocalizerRequestMixin()
    lrm.registry = get_current_registry()
    lrm.locale_name = get_settings()['pyramid.default_locale_name']
    localizer = lrm.localizer

    if DBSession.query(Node.id).count() == 0:
        localized_root_attrs = dict([(k, localizer.translate(v))
                                     for k, v in _ROOT_ATTRS.iteritems()])
        root = Document(**localized_root_attrs)
        root.__acl__ = SITE_ACL
        DBSession.add(root)
        localized_about_attrs = dict([(k, localizer.translate(v))
                                      for k, v in _ABOUT_ATTRS.iteritems()])
        root['about'] = Document(**localized_about_attrs)
        DBSession.flush()

    populate_users()
Exemplo n.º 14
0
def populate():

    session = DBSession()

    if session.query(Node).count() == 0:

        root = Document(**_ROOT_ATTRS)
        root.__acl__ = SITE_ACL
        DBSession.add(root)

        root.default_view = u'app'

        wf = get_workflow(root)
        if wf is not None:
            DBSession.flush()  # Initializes workflow
            wf.transition_to_state(root, None, u'public')

        populate_users()

        root_document = \
                session.query(Content).filter(Content.parent_id==None).first()

        fruit_categories_folder = \
                FruitCategoriesFolder(name=u"fruit_categories_folder",
                                      title=u"Fruit Categories Folder",
                                      in_navigation=True,
                                      parent=root_document)

        fruit_categories_folder.__acl__ = SITE_ACL
        session.add(fruit_categories_folder)

        workflow = get_workflow(fruit_categories_folder)
        if workflow:
            DBSession.flush()
            workflow.transition_to_state(fruit_categories_folder, None, u'public')
        else:
            print '################ NO WORKFLOW for ', fruit_categories_folder.title

        folder = \
                session.query(Content).filter_by(
                        name=u"fruit_categories_folder").first()

        fruit_category_instances = {}
        for fruit_category in fruit_categories:
            fruit_category_instances[fruit_category] = \
                FruitCategory(name=fruit_categories[fruit_category]['name'],
                              title=fruit_categories[fruit_category]['name'],
                              parent=folder)

        for key in fruit_category_instances:
            fruit_category_instances[key].__acl__ = SITE_ACL
            session.add(fruit_category_instances[key])

            workflow = get_workflow(fruit_category_instances[key])
            if workflow:
                DBSession.flush()
                workflow.transition_to_state(fruit_category_instances[key], None, u'public')
            else:
                print '################ NO WORKFLOW for ', fruit_category_instances[key].title

        fruit_instances = {}
        for fruit_category in fruit_categories:
            fruit_category_obj = \
                    DBSession.query(FruitCategory).filter_by(
                            title=fruit_category).first()
            for fruit_name in fruit_categories[fruit_category]['fruits']:
                fruit_instances[fruit_name] = \
                    Fruit(**fruit_data_args_dict(fruit_name,
                                                 fruit_category_obj))

        for key in fruit_instances:
            fruit_instances[key].__acl__ = SITE_ACL
            session.add(fruit_instances[key])

            workflow = get_workflow(fruit_instances[key])
            if workflow:
                DBSession.flush()
                workflow.transition_to_state(fruit_instances[key], None, u'public')
            else:
                print '################ NO WORKFLOW for ', fruit_instances[key].title

            # Images have filenames with format: apple.256.jpg. We will use
            # the largest, at 512 pixels, from choices of 32, 64, 128, 256,
            # and 512, and let Kotti handle sizing for thumbnails.
            size = 512
            image_filename = "{0}.{1}.jpg".format(key, size)
            image_path = os.path.join(os.path.dirname(images.__file__),
                                      image_filename)
            image = open(image_path, 'rb').read()
            fruit_instances[key][image_filename] = \
                    Image(image,
                          image_filename,
                          u"image/jpeg",
                          title=image_filename)
            fruit_instances[key][image_filename].__acl__ = SITE_ACL
            session.add(fruit_instances[key][image_filename])


    session.flush()
    transaction.commit()