Ejemplo n.º 1
0
def category_id(id):
    try:
        category = Category.query.filter_by(id=id).first()
        categoryForm = CategoryForm(obj=category)
    except:
        redirect('/admin/categories/')

    if categoryForm.validate_on_submit():
        prevCategory = category
        categoryForm.populate_obj(category)
        category.link = slugify_unique(category.link, Category, prevCategory)

        db.session.commit()
        return redirect('/admin/categories/')

    fp['breadcrumb'] = [{
        'a': '/admin/categories/',
        'v': 'Categories'
    }, {
        'v': category.title
    }]

    return render_template('admin_category.html',
                           fp=fp,
                           category=category,
                           categoryForm=categoryForm)
Ejemplo n.º 2
0
def category_id(id):
  try:
    category = Category.query.filter_by(id=id).first()
    categoryForm  = CategoryForm(obj=category)
  except:
    redirect('/admin/categories/')

  if categoryForm.validate_on_submit():
    prevCategory = category
    categoryForm.populate_obj(category)
    category.link = slugify_unique(category.link, Category, prevCategory)

    db.session.commit()
    return redirect('/admin/categories/')

  fp['breadcrumb'] = [
    {'a' : '/admin/categories/', 'v' : 'Categories'},
    {'v' : category.title}
  ]

  return render_template(
    'admin_category.html',
    fp=fp,
    category=category,
    categoryForm=categoryForm
  )
Ejemplo n.º 3
0
def categories():
    fp['breadcrumb'] = [{'v': 'Categories'}]
    categories = Category.query.all()
    categoryForm = CategoryForm()
    categoryMultiForm = CategoryMultiForm(prefix="multi_")

    if request.args.get('q') == 'add' and categoryForm.validate_on_submit():
        category = Category()
        categoryForm.populate_obj(category)
        category.link = slugify_unique(category.link, Category)
        db.session.add(category)
        db.session.commit()
        return redirect('/admin/categories/')

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

            db.session.commit()

        return redirect('/admin/categories/')

    return render_template('admin_categories.html',
                           fp=fp,
                           categories=categories,
                           categoryForm=categoryForm,
                           categoryMultiForm=categoryMultiForm)
Ejemplo n.º 4
0
def categories():
  fp['breadcrumb'] = [{'v' : 'Categories'}]
  categories = Category.query.all()
  categoryForm  = CategoryForm()
  categoryMultiForm = CategoryMultiForm(prefix="multi_")
  
  if request.args.get('q') == 'add' and categoryForm.validate_on_submit():
    category = Category()
    categoryForm.populate_obj(category)
    category.link = slugify_unique(category.link, Category)
    db.session.add(category)
    db.session.commit()
    return redirect('/admin/categories/')

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

      db.session.commit()

    return redirect('/admin/categories/')

  return render_template(
    'admin_categories.html',
    fp=fp,
    categories=categories,
    categoryForm=categoryForm,
    categoryMultiForm=categoryMultiForm
  )