示例#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.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()
示例#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()
    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()
示例#3
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()
示例#4
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()
示例#5
0
def populate():
    populate_users()
    populate_root_document()
    print 'Sea Unicornis site is initialized'