New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
WIP: blog demo, v0.4 #33
Conversation
demos/blog/config.py
Outdated
@@ -0,0 +1,28 @@ | |||
import pathlib |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In my opinion, u need set all your settings in yml
file.
demos/blog/config.py
Outdated
import pathlib | ||
|
||
|
||
BASE_DIR = pathlib.Path(__file__).parent |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
where did u use BASE_DIR
?
demos/blog/db_auth.py
Outdated
async def permits(self, identity, permission, context=None): | ||
if identity is None: | ||
return False | ||
return True |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
async def permits(self, identity, permission, context=None):
return identity is not None:
demos/blog/views.py
Outdated
raise response | ||
|
||
|
||
return {} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
add flake8, please.
demos/blog/db.py
Outdated
loop.run_until_complete(db.gino.create_all()) | ||
|
||
loop.run_until_complete(create_sample_data()) | ||
# loop.run_until_complete(delete_sample_data()) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
remove that, if this is not necessary
demos/blog/forms.py
Outdated
|
||
|
||
async def validate_login_form(form): | ||
error = None |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
when did u use error
?
demos/blog/forms.py
Outdated
else: | ||
return None | ||
|
||
return 'error' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
when does your function return 'error'
?
demos/blog/requirements.txt
Outdated
aioredis | ||
|
||
#dev | ||
psycopg2 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
maybe psycopg2
should be in #database block
demos/blog/views.py
Outdated
@login_required | ||
@aiohttp_jinja2.template('index.html') | ||
async def index(request): | ||
username = await authorized_userid(request) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
authorized_user*id*
return username 🤔
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yes, I store username there.
http://aiohttp-security.readthedocs.io/en/stable/glossary.html#term-userid
demos/blog/views.py
Outdated
@aiohttp_jinja2.template('index.html') | ||
async def index(request): | ||
username = await authorized_userid(request) | ||
current_user = await User.query.where(User.username == username).gino.first() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
u will do it in every view
, maybe make sense use middleware
|
updated a bit (work in progress). But yes, And maybe anybody has other general objections? |
I would advise not to use Gino altogether if it support only global var way to create models... |
demos/blog/db_helpers.py
Outdated
teardown_db(executor_config=admin_db_config, target_config=user_db_config) | ||
setup_db(executor_config=admin_db_config, target_config=user_db_config) | ||
|
||
import asyncio |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
looks ugly probable should be at the top?
if username: | ||
raise redirect(request.app.router, 'index') | ||
|
||
if request.method == 'POST': |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lets make separate methods one for post second for get
I like changes, but flake issues should be resolved |
Having aiohttp-login example is good idea |
I've tried it and left an update to PR's description. |
lets merge this PR and do incremental udpdates |
Wanted to share my "work in progress" for
blog
demo.To discuss:
-readme
is empty, sorry for that. If someone wants to start it locally, I will work on those notes.- I've tried out gino for db access and so far it's been very convenientswitched back to sqlalchemy coreupdate:
I've tried out
aiohttp-login
. There are two ways to use it:AsyncpgStorage
storage.As in p.1. it will also require table for login-related user fields.
At the moment I don't like either of those options.
Please share your feedback.