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 populate_users(): principals = get_principals() if u'admin' not in principals: principals[u'admin'] = { 'name': u'admin', 'password': get_settings()['kotti.secret'], 'title': u"Administrator", 'groups': [u'role:admin'], } DBSession.flush() transaction.commit()
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 save_success(self, appstruct): appstruct.pop('csrf_token', None) context = self.request.context mapper = lambda snippet: ("snippet-%d" % snippet.id, snippet) view_name = self.context.default_view or "view" slots_names = [name for name, title in get_registered_slots(view_name)] for slot in context.slots: if slot.name in slots_names: snippets = self._available_snippets(context, slot.name) snippets = dict(map(mapper, snippets)) while slot.snippets: slot.snippets.pop() for snippet in appstruct[slot.name]: snippet_id = snippet['snippet'] if snippet_id in snippets: s = snippets[snippet_id] if s not in slot.snippets: slot.snippets.append(snippets[snippet_id]) del appstruct[slot.name] for slot_name in appstruct: snippets = self._available_snippets(context, slot_name) snippets = dict(map(mapper, snippets)) slot = DocumentSlot() slot.document = context slot.name = slot_name for snippet in appstruct[slot_name]: snippet_id = snippet['snippet'] if snippet_id in snippets: s = snippets[snippet_id] if s not in slot.snippets: slot.snippets.append(snippets[snippet_id]) for slot in context.slots: if slot.name not in slots_names: context.slots.remove(slot) DBSession.delete(slot) DBSession.flush() return HTTPFound(self.request.resource_url(context))