示例#1
0
def add_category(category_name):
    categories = get_all_categories()
    if category_name not in categories:
        category_obj = Category(category_name)
        db.session.add(category_obj)

    """
示例#2
0
def add_place_to_db(page):
    db.session.add(page)
    categories = get_all_categories()
    if page.category not in categories:
        category_obj = Category(page.category)
        db.session.add(category_obj)
    db.session.commit()
示例#3
0
def add_place_to_db_new_page(title, category = "Other"):
    page = Page(title, category)
    db.session.add(page)

    categories = get_all_categories()
    if category not in categories:
        category_obj = Category(category)
        db.session.add(category_obj)

    db.session.commit()
示例#4
0
    def add_new_category(self, cat_name):
        """Category add new.
        Will check if the cat_name is unique, otherwise will return an error.

        Args:
            cat_name: string category name.

        Return:
            None
        """
        cat_name = SiteHelpers().secure_filename(cat_name)

        try:
            category = Category(name=cat_name)
            return category.save()
        except NotUniqueError:
            return 'category name not unique'
示例#5
0
def create(name, category_id=None):
    """Creates a Category given the provided values

    :param name: The string name of the Category object
    :param category_id: The id to assign to the Category.  If not provided, a uuid will be generated
    :return The created Category object
    :rtype Category
    """

    if category_id is None:
        category_id = str(uuid4())

    new_category = Category(id=category_id, name=name)

    db.session.add(new_category)
    db.session.commit()

    return new_category
 def add_category(name, user_id, description=None):
     if name == '':
         raise ValueError('Category has to have name')
     return Category(name=name, user_id=user_id, description=description)
示例#7
0
 def save(self, name):
     category = Category(name)
     db.session.add(category)
     db.session.commit()