def edit_taxonomy(data): new = False if 'id' in data and data['id']: tax = Taxonomy.query.get(data['id']) else: new = True tax = Taxonomy() tax.type = data['type'] if not tax: return False tax.name = data['name'] tax.name_sort = data['name'] tax.slug = tax.generate_slug() if 'parent' in data and data['parent']: tax.parent_id = int(data['parent']) else: tax.parent_id = None if new: db.session.add(tax) db.session.commit() return True
def add_taxonomy(name, ttype, parent=None): tax = Taxonomy() tax.name = name tax.slug = tax.generate_slug() tax.type = ttype tax.parent_id = parent if parent else None db.session.add(tax) db.session.commit() return tax.id