def newStartup(): if request.method == 'POST': startup = Startup(name=request.form['name']) session.add(startup) session.commit() flash('New Startup Created') return redirect(url_for('showStartups')) else: return render_template('newStartup.html')
def newStartup(): if request.method == 'POST': newstartup = Startup(name=request.form['name']) session.add(newstartup) session.commit() flash("new startup created!") return redirect(url_for('index')) else: return render_template('new.html')
def newStartup(): if 'username' not in login_session: return redirect('/login') if request.method == 'POST': newStartup = Startup(name=request.form['name']) session.add(newStartup) session.commit() flash("new startup created!") return redirect(url_for('showStartup')) else: return render_template('newStartup.html')
def newstartup(): if 'username' not in login_session: return redirect('/login') if request.method == 'POST': newstartup = Startup(name=request.form['name'], user_id=login_session['user_id']) session.add(newstartup) session.commit() flash("Startup Added successfully") return redirect(url_for('showstartups')) else: return render_template('newstartup.html')
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() except: pass
# declaratives can be accessed through a DBSession instance Base.metadata.bind = engine DBSession = sessionmaker(bind=engine) # A DBSession() instance establishes all conversations with the database # 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)
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)