async def setup(request): page = dict() if config['SETUP_DB']: dform = DatabaseForm(request) if request.method == 'POST' and dform.validate(): valid = await sql_validate(dform.user.data, dform.password.data, dform.name.data, dform.host.data, dform.type.data) if not valid: print('Error - DB Not Valid') return redirect(app.url_for('setup')) config['SETUP_DB'] = False return redirect(app.url_for('setup')) page['title'] = 'Blog First Start' page['header'] = 'Setup Database' page[ 'text'] = 'Below you should enter your database connection details.' return jrender('page.html', request, page=page, form=dform) elif config['SETUP_BLOG']: wform = WelcomeForm(request) if request.method == 'POST' and wform.validate(): user = User(id=1, name=wform.username.data) auth.login_user(request, user) config['SETUP_BLOG'] = False uri = config['DB_URI'] dbt = config['DB_TYPE'] with open("config.py", "wt") as o: o.write(f'DB_URI = {repr(uri)}\n') o.write(f'DB_TYPE = {repr(dbt)}\n') o.write('DEMO_CONTENT = False\n') o.write('SETUP_DB = False\n') o.write('SETUP_BLOG = False\n') await sql_demo() con = await sql_connection() date = datetime.datetime.now() await con.execute( f'INSERT INTO "blog_settings" (`title`,`created_on`,`username`,`password`,`email`,`hidden' f'`) VALUES ("{wform.title.data}","{date}","{wform.username.data}","{wform.password.data}' f'","{wform.email.data}","{wform.seo.data}");') await con.commit() await con.close() return redirect('/') page['title'] = 'Blog First Start' page['header'] = 'Welcome' page[ 'text'] = 'Before you get blogging, we need to setup a few things.' return jrender('page.html', request, page=page, form=wform) page['title'] = 'Setup' page['header'] = 'Already Completed' page['text'] = 'Redirecting in 3 seconds...' return jrender( 'page.html', request, page=page, js_head_end= '<script defer>window.setTimeout(function(){ window.location = "/"; },3000);</script>' )
async def setup(request): page = dict() if config['SETUP_DB']: dform = DatabaseForm(request) if request.method == 'POST' and dform.validate(): print('Setting up DB') data = (dform.user.data, dform.password.data, dform.name.data, dform.host.data, dform.type.data) await sql_master(data) # if not valid: # print('Error - DB Not Valid') # return redirect(app.url_for('setup')) config['SETUP_DB'] = False print('DB Setup Finished') return redirect(app.url_for('setup')) page['title'] = 'Blog First Start' page['header'] = 'Setup Database' page['text'] = 'Below you should enter your database connection details.' return jrender('page.html', request, page=page, form=dform) elif config['SETUP_BLOG']: print('Setting up Blog') wform = WelcomeForm(request) if request.method == 'POST' and wform.validate(): user = User(id=1, name=wform.username.data) auth.login_user(request, user) # uri = config['DB_URI'] # dbt = config['DB_TYPE'] # with open("config.py", "wt") as o: # o.write(f'DB_URI = {repr(uri)}\n') # o.write(f'DB_TYPE = {repr(dbt)}\n') # o.write('DEMO_CONTENT = False\n') # o.write('SETUP_DB = False\n') # o.write('SETUP_BLOG = False\n') # print('Wrote config.py') # demo = await sql_demo() # print('Injected Demo Content') # if not demo: # print('Demo content broke') # return redirect(app.url_for('setup')) # print('Finished With Demo Content') data = (wform.title.data, wform.username.data, wform.password.data, wform.email.data) finish_up = await sql_master(data) if not finish_up: return redirect(app.url_for('setup')) config['SETUP_BLOG'] = False return redirect('/') page['title'] = 'Blog First Start' page['header'] = 'Welcome' page['text'] = 'Before you get blogging, we need to setup a few things.' return jrender('page.html', request, page=page, form=wform) page['title'] = 'Setup' page['header'] = 'Already Completed' page['text'] = 'Redirecting in 3 seconds...' return jrender('page.html', request, page=page, js_head_end='<script defer>window.setTimeout(function(){ window.location = "/"; },3000);</script>')
def test_get_categories_for_store_returns_empty_response_when_no_store( self): request, response = app.test_client.get( app.url_for('inventory.get_categories_for_store', store=-1)) assert response.status == 200 assert not response.json assert isinstance(response.json, list), 'Wrong response format'
async def _signup(request): form = SignUpForm(request.form) if request.method == 'POST': print(form.errors) if form.validate(): email = form.email.data user = await fetch_user(email) if user is None: user = await User.new_user(email=email, password=form.password.data) login_user(request, user) return response.redirect(app.url_for('home')) form.email.errors.append( 'An account with this email already exists!') return template('signup.html', form=form) return template('signup.html', form=SignUpForm())
async def pokertables(request): user = request.cookies.get('username') tables = [{ "id": table.id, "name": table.name, "seats": table.seats, "seats_taken": table.seats - table.seats_free, "buyin": table.buyin, "minbuyin": table.minbuyin, "small_blind": table.small_blind, "big_blind": table.big_blind, "url": app.url_for("table", table_id=table.id) } for table in PokerGame] return render_template( 'template_pokertables', request, {'username': user, 'tables': tables, **getHeaders} )
def get_absolute_url(self): return app.url_for('Prs', kwargs={"slug": self.slug})
def test_get_median_for_category_doesnt_accept_non_get_requests(self): request, response = app.test_client.post( app.url_for('inventory.get_median_for_category', category=1)) assert response.status == 405
def test_get_median_for_category_returns_null_for_empty_category(self): request, response = app.test_client.get( app.url_for('inventory.get_median_for_category', category=20)) assert response.status == 200 assert response.json is None, 'Not null response'
def test_get_median_for_category_returns_200(self): request, response = app.test_client.get( app.url_for('inventory.get_median_for_category', category=1)) assert response.status == 200 assert isinstance(response.json, float) or isinstance( response.json, int), 'Wrong response format'
def test_get_item_inventory_doesnt_accept_non_get_requests(self): request, response = app.test_client.post( app.url_for('inventory.get_item_inventory', item='shorts')) assert response.status == 405
def test_get_item_inventory_returns_200(self): request, response = app.test_client.get( app.url_for('inventory.get_item_inventory', item='time')) assert response.status == 200 assert not response.json assert isinstance(response.json, list), 'Wrong response format'
def test_get_categories_for_store_doesnt_accept_non_get_requests(self): request, response = app.test_client.post( app.url_for('inventory.get_categories_for_store', store=1)) assert response.status == 405
from app import ( app, config, dbase, PokerGame, PokerGameDatabase, DatabaseBrowser ) import asyncio from sanic.log import logger app.static('/static', 'app/static') css_files = ['main', 'base', 'navbar', 'forms', 'database', 'pokertables', 'pokertable'] getHeaders = { 'css_urls': [app.url_for('static', filename=f'css/{file}.css') for file in css_files], 'favicon_url': app.url_for('static', filename='favicon.ico') } setup(app, loader=DictLoader({ "template_base": open('app/templates/base.html').read(), "template_signin": open('app/templates/signin.html').read(), "template_signup": open('app/templates/signup.html').read(), "template_database": open('app/templates/database.html').read(), "template_table": open('app/templates/table.html').read(), "template_pokertables": open('app/templates/pokertables.html').read() })) def signinValidate(form): password = form.get('password').encode('utf-8') passhash = sha256(password).hexdigest()
async def not_found_handler(request, exception): return response.redirect(app.url_for('not_found'))
async def logout(request): auth.logout_user(request) return response.redirect(app.url_for('index'))