Ejemplo n.º 1
0
def new_category():
    form = CategoryForm()
    if form.validate_on_submit():
        category = Category(name=form.name.data)
        db.session.add(category)
        db.session.commit()
        flash(_('Your create a new category!'))
        return redirect(url_for('main.index'))
    return render_template('new_category.html', form=form)
Ejemplo n.º 2
0
def update_category(id):
    category = Category.query.get(id)
    form = CategoryForm(formdata=request.form, obj=category)
    if form.validate_on_submit():
        name = form.name.data
        # Updated review instance
        category.name = name
        # save review method
        category.save_category()
        return redirect(url_for('.categories'))

    title = f'Update Pitch'
    return render_template('pitch/new_category.html', title=title, form=form)
Ejemplo n.º 3
0
def new_category():
    form = CategoryForm()

    if form.validate_on_submit():
        name = form.name.data
        author = current_user.id
        category = Category(name=name,user_id=author)
        db.session.add(category)
        if current_user.has_categories is not True:
            current_user.has_categories = True
        db.session.commit()
        flash('Category created.', 'success')
        return redirect(url_for('main.manage_category'))
    return render_template('blog/new_category.html', form=form)
Ejemplo n.º 4
0
def edit_category(category_id):
    form = CategoryForm()
    category = Category.query.get_or_404(category_id)
    if category.id == 1:
        flash('You can not edit the default category.', 'warning')
        return redirect(url_for('blog.index'))
    if form.validate_on_submit():
        category.name = form.name.data
        db.session.commit()
        flash('Category updated.', 'success')
        return redirect(url_for('admin.manage_category'))

    form.name.data = category.name
    return render_template('admin/edit_category.html', form=form)
Ejemplo n.º 5
0
def new_category():
    form = CategoryForm()
    if form.validate_on_submit():
        name = form.name.data
        # Updated review instance
        category = Category(
            name=name
        )

        # save review method
        category.save_category()
        return redirect(url_for('.categories'))

    title = f'New Category'
    return render_template('pitch/new_category.html', title=title, form=form)
Ejemplo n.º 6
0
def newcategory():
    form = CategoryForm()
    category_name = None
    if form.validate_on_submit():
        try:
            category_name = form.category_name.data.lower()
            Category.create(category_name)
            flash("{} Category created".format(category_name))
            return redirect(url_for('main.homepage'))
        except IntegrityError as e:
            flash("Error: Duplicate category: {} already exists".format(
                category_name))
            return render_template('item_form.html',
                                   form=form,
                                   name=category_name)
    return render_template('item_form.html', form=form, name=category_name)
Ejemplo n.º 7
0
def index():
    categories = Category.query.all()

    form = CategoryForm()

    if form.validate_on_submit():
        category = Category(title=form.title.data,
                            description=form.description.data)

        db.session.add(category)
        db.session.commit()

        flash("The category {} was added".format(category.title))

        return redirect(url_for('main.index'))

    return render_template('index.html',
                           categories=categories,
                           add_category_form=form)