Exemple #1
0
def edit_category(category):
    categories = Category.query.filter_by(user_id=current_user.id).all()
    categoryList = [c.name for c in categories]
    if not categoryList or category not in categoryList:
        logger.error('No category for ' + current_user.username +
                     ' with category : ' + category)
        return redirect(url_for('index'))
    form = AddCategoryForm()
    newCategory = None
    if form.validate_on_submit():
        if category == form.category.data.lower():
            flash('No changes were made', 'info')
            return redirect(url_for('index'))
        for c in categories:
            if c.name == form.category.data.lower():
                flash('Category ' + form.category.data + ' already exists',
                      'danger')
                return redirect(url_for('edit_category', category=category))
            if c.name == category:
                newCategory = c
        c.name = form.category.data.lower()
        db.session.commit()
        return redirect(url_for('index'))
    return render_template('category.html',
                           title='Edit Category',
                           form=form,
                           category=categoryList)
Exemple #2
0
def editCategory(id=0):
    category = Category.query.filter_by(id=id).first()
    if category == None:
        flash(gettext('Category not found.'))
        return redirect(url_for('categories'))
    form = AddCategoryForm(obj=category)
    if form.validate_on_submit():

        #delete category
        if 'delete' in request.form:
            db.session.delete(category)
            db.session.commit()
            return redirect(url_for("categories"))

        #update category
        category.name_CS_ = form.name_CS.data
        category.name_JP = form.name_JP.data
        db.session.add(category)
        db.session.commit()
        flash(gettext("Category successfully changed."))
        return redirect(url_for("categories"))
    return render_template('settings/editCategory.html',
                           title=gettext("Edit Category"),
                           category=category,
                           form=form)
Exemple #3
0
def add_category():
    # fetch all categories of user and check if the current one already exists
    categories = Category.query.filter_by(user_id=current_user.id).all()
    categoryList = [c.name for c in categories]

    form = AddCategoryForm()
    if form.validate_on_submit():
        for name in categoryList:
            if name == form.category.data.lower():
                flash('Category ' + form.category.data + ' already exists',
                      'danger')
                return redirect(url_for('add_category'))
        # add category to database
        logger.info(current_user.username + ' : added category : ' +
                    form.category.data)
        category = Category(name=form.category.data.lower(),
                            user_id=current_user.id)
        db.session.add(category)
        db.session.commit()
        db.session.flush()
        categoryList.append(category.name)
        flash('Category ' + form.category.data + ' Added', 'success')
    return render_template('category.html',
                           title='Add Category',
                           form=form,
                           category=categoryList)
Exemple #4
0
def add_category():
    form = AddCategoryForm()
    if form.validate_on_submit():
        catalog_entry = Catalog(form.category.data)
        db.session.add(catalog_entry)
        db.session.commit()
        return redirect(url_for("index"))
    return render_template("add_category.html", form=form)
Exemple #5
0
def add_category():
    form = AddCategoryForm()
    if form.validate_on_submit():
        if Category.query.filter_by(name=form.name.data).first():
            flash(u"Category %s has existed!" % form.name.data, 'error')
            return render_template('admin/add_category.html', form=form)
        category = Category(name=form.name.data)
        db.session.add(category)
        db.session.commit()
        flash(u"Add category successfully!", 'success')
        return redirect(url_for('admin.index'))
    return render_template('admin/add_category.html', form=form)
def add_category():
    form = AddCategoryForm()
    if form.validate_on_submit():
        cat_exist = Category.query.filter_by(name=form.name.data).first()
        if not cat_exist:
            new_category = Category(name=form.name.data,description=form.description.data)
            db.session.add(new_category)
            db.session.commit()
            flash('You have successfully added a new category.')
         #   flash('This Category Exists, add a new category.')
        return redirect(url_for('admin.add_category'))

    return render_template('admin/add_category.html', form=form, title="Add Category")
Exemple #7
0
def add_category():
    form = AddCategoryForm()
    if request.method == 'POST':
        if form.validate_on_submit():
            category = request.form['category']
            if category:
                if create_category(category):
                    flash('Категория успешно добавлена')
                else:
                    flash('Категория уже существует')
            else:
                flash('Поле не должно быть пустым')

    return render_template('add_category.html', form=form, user=current_user)
Exemple #8
0
def addCategory():
    form = AddCategoryForm()
    if form.validate_on_submit():
        category = Category()
        category.name_CS = form.name_CS.data
        category.name_JP = form.name_JP.data
        ol = db.session.query(func.max(Category.order).label('order_max')).one()
        category.order = ol.order_max if ol else 1
        db.session.add(category)
        db.session.commit()
        flash(gettext("New product category successfully added."))
        return redirect(url_for("categories"))
    return render_template('settings/addCategory.html',
                           title=gettext("Add New Product Category"),
                           form=form)
Exemple #9
0
def categories_main():
    form = AddCategoryForm(request.form)
    if form.validate_on_submit():
        if g.user is None:
            flash(u'you must be logged in for that!', 'warning')
            return redirect(url_for('login', next=request.path))
        g.db.execute('''insert into categories (category_name, pub_date, 
                        last_modified, user_id) values (?, ?, ?, ?)''', [
                        form.category_name.data, datetime.utcnow(), 
                        datetime.utcnow(), session['user_id']])
        g.db.commit()
        flash('Your category has been submitted for review')
        return redirect(url_for('homepage'))
    categories = query_db('select category_id, category_name from categories')
    return render_template('categories.html', form=form, categories=categories)
Exemple #10
0
def add_category():
	if g.user.is_authenticated() and g.user.is_admin():
		form = AddCategoryForm()
		if request.method == 'POST' and form.validate_on_submit():
			name = form.name.data
			existing = Category.query.filter_by(name = name).first()
			if existing is not None:
				flash("Category name already exists")
				return redirect(url_for('add_category'))
			description = form.description.data
			image = request.files['image']
			image_filename = image.filename if image.filename == '' else category_img.save(image)
			category = Category(name, description, image_filename)
			db.session.add(category)
			db.session.commit()
			flash('Added Category with name : ' + name + ', description : ' + description + ', image : ' + image_filename)
			return redirect(url_for('index'))
		return render_template("addCategory.html",
			title = "Add Category",
			form = form)
	flash("You are not authorised to view the page")
	return redirect(url_for('index'))
Exemple #11
0
def add_category():
    if g.user.is_authenticated() and g.user.is_admin():
        form = AddCategoryForm()
        if request.method == 'POST' and form.validate_on_submit():
            name = form.name.data
            existing = Category.query.filter_by(name=name).first()
            if existing is not None:
                flash("Category name already exists")
                return redirect(url_for('add_category'))
            description = form.description.data
            image = request.files['image']
            image_filename = image.filename if image.filename == '' else category_img.save(
                image)
            category = Category(name, description, image_filename)
            db.session.add(category)
            db.session.commit()
            flash('Added Category with name : ' + name + ', description : ' +
                  description + ', image : ' + image_filename)
            return redirect(url_for('index'))
        return render_template("addCategory.html",
                               title="Add Category",
                               form=form)
    flash("You are not authorised to view the page")
    return redirect(url_for('index'))