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()
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()
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
def test_unique_constraint(self): session = DBSession() # Try to add two children with the same name to the root node: root = session.query(Node).get(1) session.add(Node(name=u'child1', parent=root)) session.add(Node(name=u'child1', parent=root)) self.assertRaises(IntegrityError, session.flush)
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()
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()
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()
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')
def populate(): nodecount = DBSession.query(Node).count() if nodecount == 0: p = _add_document_from_file( "home.html", u"", None, u"Welcome to Kotti!", acl=SITE_ACL) _add_document_from_file( "about.html", u"about", p, u"About") settingscount = DBSession.query(Settings).count() if settingscount == 0: settings = Settings(data={'kotti.db_version': get_version()}) DBSession.add(settings) populate_users() DBSession.flush() transaction.commit()
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()
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()
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()
def test_container_methods(self): session = DBSession() # Test some of Node's container methods: root = session.query(Node).get(1) self.assertEquals(root.keys(), []) child1 = Node(name=u'child1', parent=root) session.add(child1) self.assertEquals(root.keys(), [u'child1']) self.assertEquals(root[u'child1'], child1) del root[u'child1'] self.assertEquals(root.keys(), []) # When we delete a parent node, all its child nodes will be # released as well: root[u'child2'] = Node() root[u'child2'][u'subchild'] = Node() self.assertEquals( session.query(Node).filter(Node.name == u'subchild').count(), 1) del root[u'child2'] self.assertEquals( session.query(Node).filter(Node.name == u'subchild').count(), 0)
def link_translation(source, target): DBSession.add(Translation(source=source, target=target))