コード例 #1
0
ファイル: create.py プロジェクト: ludovicchabant/PieCrust2
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))
コード例 #2
0
ファイル: dashboard.py プロジェクト: ludovicchabant/PieCrust2
def _getWipData(path, fs_endpoints, auto_formats, pcapp):
    pathname, pathext = os.path.splitext(path)
    if pathext.lstrip('.') not in auto_formats:
        return None

    source = None
    for endpoint, s in fs_endpoints.items():
        if path.startswith(endpoint):
            source = s
            break
    if source is None:
        return None

    # TODO: this assumes FS sources, but this comes from the disk anyway.
    full_path = os.path.join(pcapp.root_dir, path)
    content_item = source.findContentFromSpec(full_path)
    if content_item is None:
        return None

    page = pcapp.getPage(source, content_item)
    uri = page.getUri()
    _, slug = split_uri(pcapp, uri)

    seg = page.getSegment()
    if not seg:
        return None

    extract = text_preview(seg.content)
    return {
        'title': page.config.get('title'),
        'slug': slug,
        'url': url_for('.edit_page', url=slug),
        'text': extract
    }
コード例 #3
0
ファイル: dashboard.py プロジェクト: germanschnyder/PieCrust2
def _getWipData(path, site, fs_endpoints):
    auto_formats = site.piecrust_app.config.get('site/auto_formats', ['html'])
    pathname, pathext = os.path.splitext(path)
    if pathext not in auto_formats:
        return None

    source = None
    for endpoint, s in fs_endpoints.items():
        if path.startswith(endpoint):
            source = s
            break
    if source is None:
        return None

    fac = source.buildPageFactory(os.path.join(site.root_dir, path))
    route = site.piecrust_app.getSourceRoute(source.name, fac.metadata)
    if not route:
        return None

    qp = QualifiedPage(fac.buildPage(), route, fac.metadata)
    uri = qp.getUri()
    _, slug = split_uri(site.piecrust_app, uri)

    with open(fac.path, 'r', encoding='utf8') as fp:
        raw_text = fp.read()

    header, offset = parse_config_header(raw_text)
    extract = text_preview(raw_text, offset=offset)
    return {
            'title': qp.config.get('title'),
            'slug': slug,
            'url': url_for('.edit_page', slug=slug),
            'text': extract
            }
コード例 #4
0
def _getWipData(path, fs_endpoints, auto_formats, pcapp):
    pathname, pathext = os.path.splitext(path)
    if pathext.lstrip('.') not in auto_formats:
        return None

    source = None
    for endpoint, s in fs_endpoints.items():
        if path.startswith(endpoint):
            source = s
            break
    if source is None:
        return None

    # TODO: this assumes FS sources, but this comes from the disk anyway.
    full_path = os.path.join(pcapp.root_dir, path)
    content_item = source.findContentFromSpec(full_path)
    if content_item is None:
        return None

    page = pcapp.getPage(source, content_item)
    uri = page.getUri()
    _, slug = split_uri(pcapp, uri)

    seg = page.getSegment()
    if not seg:
        return None

    extract = text_preview(seg.content)
    return {
        'title': page.config.get('title'),
        'slug': slug,
        'url': url_for('.edit_page', url=slug),
        'text': extract
    }
コード例 #5
0
ファイル: single.py プロジェクト: qman1989/PieCrust2
    def getOutputPath(self, uri):
        uri_root, uri_path = split_uri(self.app, uri)

        bake_path = [self.out_dir]
        decoded_uri = urllib.parse.unquote(uri_path)
        if self.pretty_urls:
            bake_path.append(decoded_uri)
            bake_path.append('index.html')
        elif decoded_uri == '':
            bake_path.append('index.html')
        else:
            bake_path.append(decoded_uri)

        return os.path.normpath(os.path.join(*bake_path))
コード例 #6
0
def get_output_path(app, out_dir, uri, pretty_urls):
    uri_root, uri_path = split_uri(app, uri)

    bake_path = [out_dir]
    decoded_uri = urllib.parse.unquote(uri_path)
    if pretty_urls:
        bake_path.append(decoded_uri)
        bake_path.append('index.html')
    elif decoded_uri == '':
        bake_path.append('index.html')
    else:
        bake_path.append(decoded_uri)

    return os.path.normpath(os.path.join(*bake_path))
コード例 #7
0
ファイル: base.py プロジェクト: qman1989/PieCrust2
    def _loadCustom(self):
        page_url = self._get_uri()
        _, slug = split_uri(self.page.app, page_url)
        self._setValue('url', page_url)
        self._setValue('slug', slug)
        self._setValue(
                'timestamp',
                time.mktime(self.page.datetime.timetuple()))
        date_format = self.page.app.config.get('site/date_format')
        if date_format:
            self._setValue('date', self.page.datetime.strftime(date_format))

        assetor = Assetor(self.page, page_url)
        self._setValue('assets', assetor)

        segment_names = self.page.config.get('segments')
        for name in segment_names:
            self.mapLoader(name, self._load_rendered_segment)
コード例 #8
0
ファイル: pagedata.py プロジェクト: ludovicchabant/PieCrust2
    def _load(self):
        from piecrust.uriutil import split_uri

        page = self._page
        set_val = self._setValue

        page_url = page.getUri(self._ctx.sub_num)
        _, rel_url = split_uri(page.app, page_url)

        dt = page.datetime
        for k, v in page.source_metadata.items():
            set_val(k, v)
        set_val('url', page_url)
        set_val('rel_url', rel_url)
        set_val('route', copy.deepcopy(page.source_metadata['route_params']))

        set_val('timestamp', time.mktime(dt.timetuple()))
        set_val('datetime', {
            'year': dt.year, 'month': dt.month, 'day': dt.day,
            'hour': dt.hour, 'minute': dt.minute, 'second': dt.second})

        self._mapLoader('date', _load_date)
コード例 #9
0
    def _load(self):
        page = self._page
        dt = page.datetime
        page_url = self._get_uri()
        _, slug = split_uri(page.app, page_url)
        self._setValue('url', page_url)
        self._setValue('slug', slug)
        self._setValue(
                'timestamp',
                time.mktime(page.datetime.timetuple()))
        self._setValue('datetime', {
            'year': dt.year, 'month': dt.month, 'day': dt.day,
            'hour': dt.hour, 'minute': dt.minute, 'second': dt.second})
        date_format = page.app.config.get('site/date_format')
        if date_format:
            self._setValue('date', page.datetime.strftime(date_format))
        self._setValue('mtime', page.path_mtime)

        assetor = Assetor(page, page_url)
        self._setValue('assets', assetor)

        segment_names = page.config.get('segments')
        for name in segment_names:
            self._mapLoader(name, self._load_rendered_segment)