def post(self): form = CategoryForm() if form.is_submitted(): try: if not form.validate(): raise Exception(_('ERROR_INVALID_SUBMISSION')) category = Category.create() if not form.slug.data: form.slug.data = form.name.data form.slug.data = Category.urlify(form.slug.data) form.populate_obj(category) category.save() return render_view(url_for('CategoriesView:put', id=category.id), message=_('CATEGORY_CREATE_SUCESS'), redirect=True) except Exception as e: flash(e.message, 'error') return render_view('admin/categories/add.html', form=form)
def put(self, id): category = Category.get_by_id(id) if category is None: flash(gettext('The category was not found'), 'error') return redirect(url_for('CategoriesView:index')) if not category.can_edit(): abort(401) if request.method in ['POST', 'PUT']: form = CategoryForm() if form.validate_on_submit(): try: form.populate_obj(category) category.save() flash(gettext('Category was succesfully saved')) return util.redirect_json_or_html(url_for('CategoriesView:index'), 'category') except: return util.redirect_json_or_html(url_for('CategoriesView:index'), 'category', gettext('Error while updating the category')) else: if request.is_xhr: return util.redirect_json_or_html(url_for('CategoriesView:index'), 'category', gettext('Invalid submission, please check the message below')) else: flash(gettext('Invalid submission, please check the message below'), 'error') else: form = NewCategoryForm(category) return render_template('admin/categories/edit.html', title=gettext('Edit Category: %(name)s', name=category.name), form=form, category=category)
def categoryEdit(id): category = SpendingCategory.query.filter(SpendingCategory.id == id).one() form = CategoryForm(request.form, obj=category) if request.method == 'POST': form.populate_obj(category) db.session.merge(category) db.session.commit() flash('Category '+category.name+' updated.') return render_template('edit_category.html', f=form, obj=category)
def edit_category(category_name): category = Category.get_by_key_name(category_name) form = CategoryForm(obj=category) if form.validate_on_submit(): form.populate_obj(category) try: category.put() flash(u"Example %s successfully saved." % category.name, "success") return redirect(url_for("list_categories")) except CapabilityDisabledError: flash(u"App Engine Datastore is currently in read-only mode.", "info") return redirect(url_for("list_categories")) return render_template("edit_category.html", form=form, category_name=category.id)
def post(self): form = CategoryForm() if request.method == "POST": if form.validate_on_submit(): try: category = Category.create() form.populate_obj(category) category.save() flash(gettext("Category succesfully created")) return util.redirect_json_or_html(url_for("CategoriesView:index"), "category") except: flash(gettext("Error while creating the category"), "error") else: flash(gettext("Invalid submission, please check the message below"), "error") return render_template("admin/categories/add.html", title=gettext("Create Category"), form=form)
def post(self): form = CategoryForm() if request.method == 'POST': if form.validate_on_submit(): try: category = Category.create() form.populate_obj(category) category.save() flash(gettext('Category succesfully created')) return util.redirect_json_or_html(url_for('CategoriesView:index'), 'category') except: flash(gettext('Error while creating the category'), 'error') else: flash(gettext('Invalid submission, please check the message below'), 'error') return render_template('admin/categories/add.html', title=gettext('Create Category'), form=form)
def category_edit(category_id): """ This creates a edits category only if the user is logged in """ if not logged_in(): flash('Please log in to edit categories') return redirect(url_for('category_list')) category = Category.query.get(category_id) if category.ctlg_user == get_current_user(): form = CategoryForm(obj=category) if form.validate_on_submit(): form.populate_obj(category) db.session.add(category) db.session.commit() flash(category.title + ' updated successfully') return redirect(url_for('category_list')) return render_template('category_edit.html', form=form) else: flash("All that we know that either this category" + "or its items are not created by you hence you cannot edit it!!") return redirect(url_for('category_list'))
def put(self, id): category = Category.get_by_id(id) if category is None: return render_view(url_for('CategoriesView:index'), status=False, redirect=True, message=_('CATEGORY_NOT_FOUND')) if not category.can_edit(): abort(401) form = CategoryForm(category=category) if form.is_submitted(): try: if not form.validate(): raise Exception(_('ERROR_INVALID_SUBMISSION')) if not form.slug.data: form.slug.data = form.name.data if category.slug != form.slug.data: form.slug.data = Category.urlify(form.slug.data) form.populate_obj(category) category.save() return render_view(url_for('CategoriesView:put', id=category.id), message=_('CATEGORY_SAVE_SUCCESS'), redirect=True) except Exception as e: flash(e.message, 'error') return render_view('admin/categories/edit.html', form=form, category=category)
def put(self, id): category = Category.get_by_id(id) if category is None: flash(gettext("The category was not found"), "error") return redirect(url_for("CategoriesView:index")) if not category.can_edit(): abort(401) if request.method in ["POST", "PUT"]: form = CategoryForm() if form.validate_on_submit(): try: form.populate_obj(category) category.save() flash(gettext("Category was succesfully saved")) return util.redirect_json_or_html(url_for("CategoriesView:index"), "category") except: return util.redirect_json_or_html( url_for("CategoriesView:index"), "category", gettext("Error while updating the category") ) else: if request.is_xhr: return util.redirect_json_or_html( url_for("CategoriesView:index"), "category", gettext("Invalid submission, please check the message below"), ) else: flash(gettext("Invalid submission, please check the message below"), "error") else: form = NewCategoryForm(category) return render_template( "admin/categories/edit.html", title=gettext("Edit Category: %(name)s", name=category.name), form=form, category=category, )