def agtech(): per_page = 50 page = int(request.args.get("page", -1)) if page < 0: page = 1 investors = Investor.query.order_by('name').paginate(page, 120, error_out=False) startups = Startup.query.order_by('name').paginate(page, per_page, error_out=False) if request.method == 'POST': if request.form.get('investor', None) is not None: form = InvestorForm(request.form) found_investor = Investor.query.filter_by( name=form.investor.data).first() if not found_investor in current_user.investors: current_user.investors.append(found_investor) db.session.add(found_investor) db.session.commit() else: current_user.investors.remove(found_investor) db.session.commit() return redirect(url_for('users.agtech', page=page)) return render_template('users/agtech.html', investors=investors, startups=startups)
def collection(id): user = User.query.get(id) if request.method == 'POST': form = InvestorForm(request.form) found_investor = Investor.query.filter_by( name=form.investor.data).first() current_user.investors.remove(found_investor) db.session.commit() return render_template('users/collection.html', form=form) return render_template('users/collection.html', user=user)
def root(): per_page = 20 page = int(request.args.get("page", -1)) if page < 0: page = 1 startups = Startup.query.order_by('name').paginate(page,per_page,error_out=False) investors = Investor.query.order_by('name').paginate(page,per_page,error_out=False) if request.method == 'POST': form = InvestorForm(request.form) found_investor = Investor.query.filter_by(name=form.investor.data).first() if not found_investor in current_user.investors: current_user.investors.append(found_investor) db.session.add(found_investor) db.session.commit() else: current_user.investors.remove(found_investor) db.session.commit() return redirect(url_for("root", page=page)) return render_template('home.html', investors=investors, startups=startups, page=page)
def fitnesstech(): per_page = 20 investors = Investor.query.order_by('name').paginate(1, per_page, error_out=False) startups = Startup.query.all() if request.method == 'POST': if request.form.get('investor', None) is not None: form = InvestorForm(request.form) found_investor = Investor.query.filter_by( name=form.investor.data).first() if not found_investor in current_user.investors: current_user.investors.append(found_investor) db.session.add(found_investor) db.session.commit() else: current_user.investors.remove(found_investor) db.session.commit() return render_template('users/fitnesstech.html', investors=investors, startups=startups, form=form) else: form2 = CollectionForm(request.form) if form2.validate(): collection = Collection(name=form2.name.data, user_id=current_user.id) db.session.add(collection) db.session.commit() flash('You have created a new collection') return render_template('users/fitnesstech.html', investors=investors, startups=startups, form=form2) flash('Collection name cannot be empty') return render_template('users/new.html', form=form2) return render_template('users/fitnesstech.html', investors=investors, startups=startups)