Пример #1
0
def add_site_menu_node(menu_key):
    parent_key = request.args.get('parent_key', '')

    name = request.form.get('name', '')
    link = request.form.get('link', '')
    target = request.form.get('target', '')
    fixed = request.form.get('fixed', '')
    path_scope = request.form.get('path_scope', '')
    css = request.form.get('css', '')
    pos = request.form.get('pos', 0)

    _index = parse_int(pos)

    new_node = {
        'key': process_slug(name),
        'name': name,
        'link': link,
        'target': target,
        'path_scope': path_scope,
        'fixed': bool(fixed),
        'class': css
    }

    site = current_app.db.Site()
    nodes = site['menus'].get(menu_key, [])
    if parent_key:
        parent = _find_parent_node(nodes, parent_key)
        parent['nodes'].insert(_index, new_node)
    else:
        nodes.insert(_index, new_node)

    site.save()
    flash('SAVED')
    return_url = act.url_as('.site')
    return redirect(return_url)
Пример #2
0
def query_segments(app, type_slug, parent_slug):
    _config = app['theme_meta']
    _opts = _config.get('options', {})
    sortby = parse_sortby(_opts.get('sortby', 'updated'))
    tmpls = [process_slug(tmpl) for tmpl in _config.get('templates', [])
             if tmpl.startswith('^')]

    if tmpls:
        files = current_app.db.Document.find(type_slug)
        segments = [f for f in files if f['template'] in tmpls and
                    f['parent'] == parent_slug and f['status']]
        segments = sortedby(segments, [('priority', 1), sortby])[:60]
    else:
        segments = []
    return segments
Пример #3
0
def create_term():
    term_name = request.form.get('name')
    term_key = request.form.get('key')
    site = current_app.db.Site()
    term = site.add_category_term({
        'key': process_slug(term_key or term_name),
        'meta': {
            'name': term_name,
            'caption': '',
            'figure': '',
        },
        'parent': '',
        'priority': 1,
        'status': 0,
    })
    site.save()
    return_url = act.url_as('.term', term_key=term['key'])
    return redirect(return_url)
Пример #4
0
def create_content(content_type):
    title = request.form.get('title')
    slug = request.form.get('slug')
    template = request.form.get('template', '')

    content = current_app.db.Document()
    slug = process_slug(slug or title)
    content.add({
        'slug': slug,
        'content_type': content_type,
        'template': template,
        'meta': {
            'title': title,
        }
    })
    content.save()
    return_url = act.url_as('.content_detail',
                            content_type=content_type,
                            slug=content.slug)
    return redirect(return_url)