def get(self, pk): user = request.user page, number = self.pageinfo collect = Collect.query.filter_by(id=pk, author_id=user.id).first_or_404() form = CollectForm() form.name.data = collect.name form.description.data = collect.description form.is_hidden.data = 0 if collect.is_hidden else 1 topics = collect.topics.paginate(page, number, True) data = {'collect': collect, 'topics': topics, 'form': form} return render_template('collect/collect.html', **data)
def post(self): user = request.user form = CollectForm() name = form.name.data description = form.description.data is_hidden = form.is_hidden.data is_hidden = True if is_hidden == 0 else False collect = Collect(name=name, description=description, is_hidden=is_hidden) collect.author = user collect.save() return redirect(url_for('collect.list'))
def get(self): query_dict = request.data user = request.user form = CollectForm() page, number = self.pageinfo keys = ['name'] order_by = gen_order_by(query_dict, keys) filter_dict = gen_filter_dict(query_dict, keys) filter_dict.update(author_id=user.id) collects = Collect.query.filter_by(**filter_dict).order_by( *order_by).paginate(page, number, True) data = {'title': 'Collect', 'collects': collects, 'form': form} return render_template('collect/collect_list.html', **data)