How to use the lektor.environment.PRIMARY_ALT function in Lektor

To help you get started, we’ve selected a few Lektor examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github ulope / pyformat.info / vendor / lektor / lektor / admin / modules / dash.py View on Github external
def edit_redirect():
    record = None

    # Find out where we wanted to go to.  We need to chop off the leading
    # /admin on this URL as this is where the admin thinks it's placed.
    path = extract_path_info(request.url_root.rstrip('/').rsplit('/', 1)[0],
                             request.args.get('path', '/'))

    if path is not None:
        record = g.admin_context.pad.resolve_url_path(path, alt_fallback=False)
    if record is None:
        abort(404)
    path = fs_path_to_url_path(record.path.split('@')[0])
    if record.alt != PRIMARY_ALT:
        path += '+' + record.alt
    return redirect(url_for('dash.edit', path=path))
github lektor / lektor / lektor / db.py View on Github external
    def _get_cache_key(self, record_or_path, alt=PRIMARY_ALT,
                       virtual_path=None):
        if isinstance(record_or_path, string_types):
            path = record_or_path.strip('/')
        else:
            path, virtual_path = split_virtual_path(record_or_path.path)
            path = path.strip('/')
            virtual_path = virtual_path or None
            alt = record_or_path.alt
        return (path, alt, virtual_path)
github lektor / lektor / lektor / db.py View on Github external
def _iter_filename_choices(fn_base, alts, config, fallback=True):
    """Returns an iterator over all possible filename choices to .lr files
    below a base filename that matches any of the given alts.
    """
    # the order here is important as attachments can exist without a .lr
    # file and as such need to come second or the loading of raw data will
    # implicitly say the record exists.
    for alt in alts:
        if alt != PRIMARY_ALT and config.is_valid_alternative(alt):
            yield os.path.join(fn_base, 'contents+%s.lr' % alt), alt, False

    if fallback or PRIMARY_ALT in alts:
        yield os.path.join(fn_base, 'contents.lr'), PRIMARY_ALT, False

    for alt in alts:
        if alt != PRIMARY_ALT and config.is_valid_alternative(alt):
            yield fn_base + '+%s.lr' % alt, alt, True

    if fallback or PRIMARY_ALT in alts:
        yield fn_base + '.lr', PRIMARY_ALT, True
github lektor / lektor / lektor / editor.py View on Github external
    def get_fs_path(self, alt=PRIMARY_ALT):
        """The path to the record file on the file system."""
        base = self.pad.db.to_fs_path(self.path)
        suffix = '.lr'
        if alt != PRIMARY_ALT:
            suffix = '+%s%s' % (alt, suffix)
        if self.is_attachment:
            return base + suffix
        return os.path.join(base, 'contents' + suffix)
github ulope / pyformat.info / vendor / lektor / lektor / builder.py View on Github external
    def find_files(self, query, alt=PRIMARY_ALT, lang=None, limit=50,
                   types=None):
        """Returns a list of files that match the query.  This requires that
        the source info is up to date and is primarily used by the admin to
        show files that exist.
        """
        return find_files(self, query, alt, lang, limit, types)
github lektor / lektor-archive / lektor / editor.py View on Github external
    def get_fs_path(self, alt=PRIMARY_ALT):
        """The path to the record file on the file system."""
        base = self.pad.db.to_fs_path(self.path)
        suffix = '.lr'
        if alt != PRIMARY_ALT:
            suffix = '+%s%s' % (alt, suffix)
        if self.is_attachment:
            return base + suffix
        return os.path.join(base, 'contents' + suffix)
github lektor / lektor-archive / lektor / builder.py View on Github external
    def find_files(self, query, alt=PRIMARY_ALT, lang=None, limit=50,
                   types=None):
        """Returns a list of files that match the query.  This requires that
        the source info is up to date and is primarily used by the admin to
        show files that exist.
        """
        return find_files(self, query, alt, lang, limit, types)
github lektor / lektor / lektor / sourcesearch.py View on Github external
def _find_best_info(infos, alt, lang):
    for _alt, _lang in [(alt, lang), (PRIMARY_ALT, lang),
                        (alt, 'en'), (PRIMARY_ALT, 'en')]:
        rv = _find_info(infos, _alt, _lang)
        if rv is not None:
            return rv
    return None
github ulope / pyformat.info / vendor / lektor / lektor / datamodel.py View on Github external
    def to_json(self, pad, record=None, alt=PRIMARY_ALT):
        return {
            'name': self.name,
            'label': self.label,
            'label_i18n': self.label_i18n,
            'hide_label': bool_from_string(self.options.get('hide_label'),
                                           default=False),
            'description_i18n': self.description_i18n,
            'type': self.type.to_json(pad, record, alt),
            'default': self.default,
        }