def _submit_page_form(pcapp, source): metadata = {} for f in source.getInteractiveFields(): metadata[f.name] = f.default_value for fk, fv in request.form.items(): if fk.startswith('meta-'): metadata[fk[5:]] = fv logger.debug("Creating item with metadata: %s" % metadata) content_item = source.createContent(metadata) if content_item is None: logger.error("Can't create item for: %s" % metadata) abort(500) logger.debug("Creating content: %s" % content_item.spec) with source.openItem(content_item, 'w') as fp: fp.write('---\n') fp.write('draft: true\n') fp.write('---\n') fp.write('\n') fp.write("Start writing!\n") flash("'%s' was created." % content_item.spec) page = Page(source, content_item) uri = page.getUri() logger.debug("Redirecting to: %s" % uri) _, rel_url = split_uri(page.app, uri) return redirect(url_for('.edit_page', url=rel_url))
def _doBuildPage(self): logger.debug("Building page: %s" % self.path) page = Page(self.source, copy.deepcopy(self.metadata), self.rel_path) # Load it right away, especially when using the page repository, # because we'll be inside a critical scope. page._load() return page
def _get_location_response(source_name, content_item): from piecrust.app import PieCrust pcapp = PieCrust(g.site.root_dir) source = pcapp.getSource(source_name) page = Page(source, content_item) uri = page.getUri() logger.debug("Redirecting to: %s" % uri) r = Response() r.status_code = 201 r.headers.add('Location', uri) return r
def run(self, job, ctx, result): year = job['year'] content_item = ContentItem('_index[%04d]' % year, { 'year': year, 'route_params': { 'year': year } }) page = Page(self.source, content_item) prev_entry = ctx.previous_entry rdr_subs = self._pagebaker.bake(page, prev_entry) result['subs'] = rdr_subs result['year'] = page.source_metadata['year']
def run(self, job, ctx, result): term = job['term'] content_item = ContentItem('_index[%s]' % term, { 'term': term, 'route_params': { self.taxonomy.term_name: term } }) page = Page(self.source, content_item) logger.debug("Rendering '%s' page: %s" % (self.taxonomy.name, page.source_metadata['term'])) prev_entry = ctx.previous_entry rdr_subs = self._pagebaker.bake(page, prev_entry) result['subs'] = rdr_subs result['term'] = page.source_metadata['term']
def get_simple_page(app, rel_path): source = app.getSource('pages') metadata = {'slug': os.path.splitext(rel_path)[0]} return Page(source, metadata, rel_path)
def _doBuildPage(self): logger.debug("Building page: %s" % self.path) page = Page(self.source, copy.deepcopy(self.metadata), self.rel_path) return page
def getPage(self, source, content_item): cache_key = '%s@%s' % (source.name, content_item.spec) return self.env.page_repository.get( cache_key, lambda: Page(source, content_item))