def validate_title(self, field): """ If the title is already in use, refuse to add this one. """ existing = set([simplify_text(c.title) for c in Category.query.filter_by(workspace=g.workspace).all() if c != self.edit_obj]) if simplify_text(field.data) in existing: raise wtforms.ValidationError("You have an existing category with the same name")
def get_word_bag(text): """ Return a string containing all unique words in the given text, in alphabetical order. >>> get_word_bag("This is a piece\tof text with this extra bit!") 'a bit extra is of piece text this with' """ words = list(set(simplify_text(striptags(text)).split(' '))) words.sort() return " ".join(words)