def showfounder(startup_id): startup_1 = session.query(Startup).filter_by(id=startup_id).one() details = session.query(Founder).filter_by(startup_id=startup_id).all() creator = getUserInfo(startup_1.user_id) if 'username' not in login_session or creator.id != login_session[ 'user_id']: return render_template('publicfounders.html', startup_1=startup_1, details=details, creator=creator) else: if request.method == 'POST': newsfounder = Founder(name=request.form['name'], bio=request.form['bio'], startup_id=startup_id, user_id=login_session['user_id']) session.add(newsfounder) session.commit() flash("Founder Added successfully") return redirect(url_for('showfounder', startup_id=startup_id)) else: return render_template('founders.html', startup_1=startup_1, details=details, creator=creator)
def newFounder(startup_id): founder = Founder(name=request.form['name'], bio=request.form['bio'], startup_id=startup_id) session.add(founder) session.commit() flash('New Founder Created') return redirect(url_for('showStartup', startup_id=startup_id))
def create_founder(startup_id): if request.method == 'POST': new_founder = Founder(name=request.form['name'], startup_id=startup_id) db_session.add(new_founder) db_session.commit() return redirect(url_for('show_startup', startup_id=startup_id)) else: # startup = db_session.query(Startup).filter_by(startup_id=startup_id).one() return render_template('create_founder.html', startup=startup_id)
def newFounder(startup_id): if request.method == 'POST': newFounder = Founder(name=request.form['name'], bio=request.form['bio'], startup_id=startup_id) session.add(newFounder) session.commit() flash("Successfully Added a New Founder!") return redirect(url_for('showStartupDetails', startup_id=startup_id)) else: return render_template('newfounder.html', startup_id=startup_id)
def newFounder(startup_id): if request.method == 'POST': newfounder = Founder(name=request.form['name'], bio=request.form['bio'], startup_id=startup_id) session.add(newfounder) session.commit() flash("new founder created!") return redirect(url_for('startup', startup_id=startup_id)) else: return render_template('newfounder.html', startup_id=startup_id)
def newFounder(startup_id): startup = session.query(Startup).filter_by(id=startup_id).one() if request.method == 'POST': newfounder = Founder(name=request.form['name'], bio=request.form['bio'], startup_id=startup_id) session.add(newfounder) session.commit() flash('New Founder %s Successfully Created' % (newfounder.name)) return redirect(url_for('showDetail', startup_id=startup_id)) else: return render_template('newfounder.html', startup_id=startup_id)
def newFounder(startup_id): startup = session.query(Startup).filter_by(id=startup_id).one() if request.method == 'POST': newFounder = Founder(name=request.form['name'], bio=request.form['bio'], startup_id=startup.id) session.add(newFounder) session.commit() flash("new founder created!") return redirect(url_for('detailsStartup', startup_id=startup_id)) else: return render_template('newFounder.html', startup=startup)
def new_founder(startup_id): startup = session.query(Startup).filter_by(id=startup_id).one() founders = session.query(Founder).filter_by(startup_id=startup.id).all() if request.method == 'POST': new_founder = Founder(name=request.form['name'], bio=request.form['bio'], startup_id=startup_id) startup_id = startup_id session.add(new_founder) session.commit() flash("New founder added successfully !") return redirect( url_for('show_startup', startup_id=startup.id, founders=founders)) else: return render_template('new_founder.html', startup=startup)
# and represents a "staging zone" for all the objects loaded into the # database session object. Any change made against the objects in the # session won't be persisted into the database until you call # session.commit(). If you're not happy about the changes, you can # revert all of them back to the last commit by calling # session.rollback() session = DBSession() # startups startup1 = Startup(name="Machina") session.add(startup1) session.commit() founder1_1 = Founder(name="Misha", bio="Computer Scientest, Full Stack Developer, IOS Developer.", startup=startup1) session.add(founder1_1) session.commit() founder2_1 = Founder(name="Cameron", bio="Computer Scientest, Full Stack Developer, Data Scientest.", startup=startup1) session.add(founder2_1) session.commit()
def do_POST(self): try: if self.path.endswith('/edit'): ctype, pdict = cgi.parse_header( self.headers.getheader('content-type')) if ctype == 'multipart/form-data': fields = cgi.parse_multipart(self.rfile, pdict) startup_name = fields.get('name') startup_id = self.path.split("/")[2] startup = session.query(Startup).filter_by( id=startup_id).one() startup.name = startup_name[0] session.add(startup) session.commit() self.send_response(301) self.send_header('content-type', "text/html") self.send_header('Location', "/startups") self.end_headers() if self.path.endswith('/delete'): ctype, pdict = cgi.parse_header( self.headers.getheader('content-type')) if ctype == 'multipart/form-data': fields = cgi.parse_multipart(self.rfile, pdict) startup_id = self.path.split("/")[2] startup = session.query(Startup).filter_by( id=startup_id).one() session.delete(startup) session.commit() self.send_response(301) self.send_header('content-type', "text/html") self.send_header('Location', "/startups") self.end_headers() if self.path.endswith('/startups/new'): ctype, pdict = cgi.parse_header( self.headers.getheader('content-type')) if ctype == 'multipart/form-data': fields = cgi.parse_multipart(self.rfile, pdict) startup_name = fields.get('name') startup = Startup(name=startup_name[0]) session.add(startup) session.commit() self.send_response(301) self.send_header('content-type', "text/html") self.send_header('Location', "/startups") self.end_headers() if self.path.endswith('/startups/add'): ctype, pdict = cgi.parse_header( self.headers.getheader('content-type')) if ctype == 'multipart/form-data': fields = cgi.parse_multipart(self.rfile, pdict) founder_name = str(fields.get('name')[0]) startup_id = str(fields.get('startup_id')[0]) bio = str(fields.get('bio')[0]) founder = Founder(name=founder_name, startup_id=startup_id, bio=bio) session.add(founder) session.commit() self.send_response(301) self.send_header('content-type', "text/html") self.send_header('Location', "/startups/" + startup_id + "/founders") self.end_headers() except Exception as e: print e pass
def do_POST(self): print("Path:", self.path) print("is what we want", str(self.path.endswith('/details'))) try: if self.path.endswith('/details/add'): ctype, pdict = cgi.parse_header( self.headers.getheader('content-type')) if ctype == 'multipart/form-data': fields = cgi.parse_multipart(self.rfile, pdict) founder_name = fields.get('name') founder_bio = fields.get('bio') startup_id = fields.get('startup_id') founder = Founder(name=founder_name[0], bio=founder_bio[0], startup_id=startup_id[0]) session.add(founder) session.commit() self.send_response(200) self.send_header('content-type', "text/html") self.send_header('Location', "/startups/%s/details" % startup_id[0]) self.end_headers() founders = session.query(Founder).filter_by( startup_id=startup_id[0]).all() output = "" output += "<html><body>" output += "<br>" for founder in founders: output += "<br>" output += "<p >%s</p>" % founder.name output += "<br>" output += "<p >%s</p>" % founder.bio output += "<br><br>" output += "<form method ='POST' enctype='multipart/form-data' action =''>" output += "<input type='text' name='name' placeholder='name'/>" output += "<input type='hidden' name='startup_id' value='%s' />" % startup_id output += "<input type='text' name='bio' placeholder='bio'/>" output += "<button type='submit'> add founder! </button>" output += "</form></body></html>" self.wfile.write(output) if self.path.endswith('/edit'): ctype, pdict = cgi.parse_header( self.headers.getheader('content-type')) if ctype == 'multipart/form-data': fields = cgi.parse_multipart(self.rfile, pdict) startup_name = fields.get('name') startup_id = self.path.split("/")[2] startup = session.query(Startup).filter_by( id=startup_id).one() startup.name = startup_name[0] session.add(startup) session.commit() self.send_response(301) self.send_header('content-type', "text/html") self.send_header('Location', "/startups") self.end_headers() if self.path.endswith('/delete'): ctype, pdict = cgi.parse_header( self.headers.getheader('content-type')) if ctype == 'multipart/form-data': fields = cgi.parse_multipart(self.rfile, pdict) startup_id = self.path.split("/")[2] startup = session.query(Startup).filter_by( id=startup_id).one() session.delete(startup) session.commit() self.send_response(301) self.send_header('content-type', "text/html") self.send_header('Location', "/startups") self.end_headers() if self.path.endswith('/startups/new'): ctype, pdict = cgi.parse_header( self.headers.getheader('content-type')) if ctype == 'multipart/form-data': fields = cgi.parse_multipart(self.rfile, pdict) startup_name = fields.get('name') startup = Startup(name=startup_name[0]) session.add(startup) session.commit() self.send_response(301) self.send_header('content-type', "text/html") self.send_header('Location', "/startups") self.end_headers() except IOError: self.send_error(404, 'File Not Found: %s' % self.path)