def add(title, father, text): assert not isinstance(current_user, AnonymousUserMixin), 'user has not logged in' assert isinstance(title, basestring), 'name is not string' assert len(title) >= 5, 'route name too short!' assert father is None or isinstance(father, ObjectId), 'father is not not valid category id' new_route = Route() new_route.title = title new_route.author = current_user.id new_route.create_ts = dt_to_ts(datetime.utcnow()) if father: new_route.father = father new_route.content.new_file() new_route.content.write(text.encode('utf-8')) new_route.content.close() new_route.save() # add id of new route to father's routes list from app.helpers.category import CategoryHelper CategoryHelper.add_route(father, new_route.id) return new_route