Beispiel #1
0
def post_category():
    """
    Insert shopping_list
    """
    data = request.get_json(silent=True)
    print(data)

    if 'name' in data and 'description' in data and 'slug' in data:
        name = data['name']
        description = data['description']
        slug = data['slug']

        Category.create(name=name, description=description, slug=slug)
        return make_response(jsonify({'success': True, 'result': 'Category Created'}), 201)
    else:
        return make_response(jsonify({'success': False, 'result': 'Incomplete parameters'}), 400)
Beispiel #2
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)
Beispiel #3
0
    def run(self):
        """
        Run the database seeds.
        """
        categories = [
            "Soccer",
            "Basketball",
            "Baseball",
            "Frisbee",
            "Snowboarding",
            "Rock Climbing",
            "Football",
            "Skating",
            "Hockey"
        ]

        for category in categories:
            Category.create(title=category)
Beispiel #4
0
def create_category():
    """
    Creates a category given by the JSON in the request.
    :return:
    """
    try:
        name = request.json["name"]
    except KeyError:
        return make_json_response(status=400)
    else:
        try:
            category = Category.create(name=name)
        except Category.DuplicateCategory:
            return make_json_response(status=409)
        else:
            return jsonify(category.to_dict())
Beispiel #5
0
    def post(self):
        """
    Validates form and creates a new category if validation passed

    Returns:
      A template or a flask redirect.
    """
        form = CategoryForm()

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

            flash('Category {0} has been created.'.format(category.name),
                  'success')
            return redirect(url_for('blog.category', category_id=category.id))

        return render_template('blog/category/create.html', form=form)
Beispiel #6
0
def category_init():
    for c in category_list:
        Category.create(c)
Beispiel #7
0
def create_category():
    form = CreateCategoryForm().validate_for_api()
    Category.create(content=form.content.data, type=form.type.data, commit=True)
    return Success()