def post(self, category_id=None): if category_id: abort(400) else: args = category_post_parser.parse_args(strict=True) user = User.verify_auth_token(args['token']) if not user: abort(401) new_post = Category(args['title']) new_post.user = user new_post.date = datetime.datetime.now() new_post.text = args['text'] if args['items']: for item in args['items']: tag = Item.query.filter_by(title=item).first() # Add the tag if it exists. If not, make a new tag if tag: new_post.tags.append(tag) else: new_tag = Item(item) new_post.tags.append(new_tag) db.session.add(new_post) db.session.commit() return new_post.id, 201
def new_post(): form = CategoryForm() if form.validate_on_submit(): new_post_model = Category(form.title.data) new_post_model.text = form.text.data new_post_model.publish_date = datetime.datetime.now() new_post_model.user = User.query.filter_by( username=current_user.username).one() db.session.add(new_post_model) db.session.commit() return render_template('new.html', form=form)
def category(category_id): form = ItemForm() if form.validate_on_submit(): new_category = Category(form.name.title) new_category.name = form.name.data new_category.text = form.text.data new_category.post_id = category_id new_category.date = datetime.datetime.now() db.session.add(new_category) db.session.commit() category = Category.query.get_or_404(category_id) items = Item.query.filter_by(category_id=category.id).all() recent, top_items = sidebar_data() return render_template('category.html', category=category, recent=recent, top_items=top_items, form=form)