示例#1
0
文件: views.py 项目: 4416/hazel-cms
def list(request):
    nodes = dict([(n.get_key(), n) for n in Layout.all()])
    root = None
    for node in nodes:
        node = nodes[node]
        if node.path == '0':
            root = node
            break
    if root is not None:
        root = rec(root, nodes)
    return render_template('app:layouts/list.html', root=root)
示例#2
0
文件: views.py 项目: 4416/hazel-cms
def edit(request, key):
    layout = Layout.get(db.Key(key))
    form = LayoutForm(request.form, obj=layout)
    if request.method == "POST" and form.validate():
        form.auto_populate(layout)
        layout.put()
        # clear depending caches
        for node in layout.get_affected_nodes():
            node.invalidate_cache()
        if form.save.data is True:
            return redirect(url_for('nut:layouts/list'), 301)
    return render_template('app:layouts/form.html', form=form, layout=layout)
示例#3
0
文件: views.py 项目: 4416/hazel-cms
def add_folder(request):
    form = FolderForm(request.form)
    if request.method == 'POST' and form.validate():
        layout = Layout.add(name=form.name.data,
                            slug=slugify(form.name.data),
                            author=users.get_current_user(),
                            type=FOLDER)
        if form.save.data is True:
            return redirect(url_for('nut:layouts/list'), 301)
        if form.cont.data is True:
            return redirect(url_for('nut:layouts/edit', key=layout.get_key()), 301)
    return render_template('app:layouts/form.html', form=form)
示例#4
0
文件: views.py 项目: 4416/hazel-cms
def add(request, key):
    form = LayoutForm(request.form)
    if request.method == 'POST' and form.validate():
        layout = Layout.add(to=key, type=LAYOUT,
                            name=form.name.data,
                            slug=slugify(form.name.data),
                            body=form.body.data,
                            author=users.get_current_user())
        layout.update_extends()
        layout.put()
        if form.save.data is True:
            return redirect(url_for('nut:layouts/list'), 301)
        if form.cont.data is True:
            return redirect(url_for('nut:layouts/edit', key=layout.get_key()), 301)
    return render_template('app:layouts/form.html', form=form)
示例#5
0
文件: views.py 项目: 4416/hazel-cms
def move(request, A, mode, B):
    switch = { 'before': lambda x,y: Layout.move(x, before=y),
               'after': lambda x,y: Layout.move(x, after=y),
               'to': lambda x,y: Layout.move(x, to=y) }
    switch[mode](A,B)
    return redirect(url_for('nut:layouts/list'), 301)
示例#6
0
文件: views.py 项目: 4416/hazel-cms
def delete(request, key):
    layout = Layout.get(db.Key(key))
    if request.method == 'POST':
        Layout.drop(key)
        return redirect(url_for('nut:layouts/list'), 301)
    return render_template('app:layouts/confirm_delete.html', layout=layout, form=DeleteForm())