コード例 #1
0
ファイル: view.py プロジェクト: paraboul/FlaskPress
def page_id(id):
    try:
        page = Page.query.filter_by(id=id).first()
        pageForm = PageForm(obj=page)
    except:
        return redirect('/admin/pages/')

    if pageForm.validate_on_submit():
        page.link = slugify_unique(pageForm.data['link'], Page, page)
        page.title = pageForm.data['title']
        page.body = pageForm.data['body']

        if pageForm.data['id_parent']:
            page.id_parent = pageForm.data['id_parent'].id
        else:
            page.id_parent = None

        db.session.commit()
        return redirect('/admin/pages/' + str(id) + '/')
    else:
        pageForm.id_parent.data = page.parent

    fp['breadcrumb'] = [{
        'a': '/admin/pages/',
        'v': 'Pages'
    }, {
        'v': page.title
    }]

    return render_template('admin_page.html',
                           fp=fp,
                           page=page,
                           pageForm=pageForm)
コード例 #2
0
ファイル: view.py プロジェクト: paraboul/FlaskPress
def page_id(id):
  try:
    page = Page.query.filter_by(id=id).first()
    pageForm  = PageForm(obj=page)
  except:
    return redirect('/admin/pages/')

  if pageForm.validate_on_submit():
    page.link = slugify_unique(pageForm.data['link'], Page, page)
    page.title       = pageForm.data['title']
    page.body        = pageForm.data['body']

    if pageForm.data['id_parent']:
      page.id_parent = pageForm.data['id_parent'].id
    else:
      page.id_parent = None

    db.session.commit()
    return redirect('/admin/pages/'+str(id)+'/')
  else:
    pageForm.id_parent.data = page.parent

  fp['breadcrumb'] = [
    {'a' : '/admin/pages/', 'v' : 'Pages'},
    {'v' : page.title}
  ]

  return render_template(
    'admin_page.html',
    fp=fp,
    page=page,
    pageForm=pageForm
  )
コード例 #3
0
ファイル: view.py プロジェクト: paraboul/FlaskPress
def pages():
    fp['breadcrumb'] = [{'v': 'Pages'}]
    pages = Page.query.filter_by(id_parent=None).all()
    pageForm = PageForm()
    pageMultiForm = PageMultiForm(prefix="multi_")

    if request.args.get('q') == 'add' and pageForm.validate_on_submit():
        page = Page()
        pageForm.populate_obj(page)

        if pageForm.data['id_parent']:
            page.id_parent = pageForm.data['id_parent'].id

        page.link = slugify_unique(page.link, Page)
        db.session.add(page)
        db.session.commit()

        return redirect('/admin/pages/')

    if request.args.get('q') == 'multi':
        if request.form['multi_actions'] == 'D':
            ids = request.form.getlist('selected')
            for id in ids:
                to_del = Page.query.filter_by(id=id).first()
                db.session.delete(to_del)

            db.session.commit()

        return redirect('/admin/pages/')

    return render_template('admin_pages.html',
                           fp=fp,
                           pages=pages,
                           pageForm=pageForm,
                           pageMultiForm=pageMultiForm)
コード例 #4
0
ファイル: view.py プロジェクト: paraboul/FlaskPress
def pages():
  fp['breadcrumb'] = [{'v' : 'Pages'}]
  pages = Page.query.filter_by(id_parent=None).all()
  pageForm  = PageForm()
  pageMultiForm = PageMultiForm(prefix="multi_")

  if request.args.get('q') == 'add' and pageForm.validate_on_submit():
    page = Page()
    pageForm.populate_obj(page)

    if pageForm.data['id_parent']:
      page.id_parent = pageForm.data['id_parent'].id

    page.link = slugify_unique(page.link, Page)
    db.session.add(page)
    db.session.commit()
      
    return redirect('/admin/pages/')

  if request.args.get('q') == 'multi':
    if request.form['multi_actions'] == 'D':
      ids = request.form.getlist('selected')
      for id in ids:
        to_del = Page.query.filter_by(id=id).first()
        db.session.delete(to_del)

      db.session.commit()

    return redirect('/admin/pages/')

  return render_template(
    'admin_pages.html',
    fp=fp,
    pages=pages,
    pageForm=pageForm,
    pageMultiForm=pageMultiForm
  )