-
Notifications
You must be signed in to change notification settings - Fork 27
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
Binding DB sessions based on SQLAlchemy 1, changing how to declare Base Model classes, and other code modernization #50
base: master
Are you sure you want to change the base?
Changes from 4 commits
93b4de1
e063508
55c7d74
96aa71b
010a756
f4d595c
830c7a9
a509d64
a60326a
dbc3d62
5cc7e50
1b5c162
52771ce
f5afd8b
870463c
7e1db9f
0caca54
f24fc11
e6b31e0
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,5 @@ | ||
from sqlalchemy.ext.declarative import declarative_base | ||
from sqlalchemy.orm import DeclarativeBase | ||
|
||
Base = declarative_base() | ||
|
||
class Base(DeclarativeBase): | ||
pass |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
from django.contrib import admin | ||
from django.contrib import admin # noqa: F401 | ||
|
||
# Register your models here. |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
from django.test import TestCase | ||
from django.test import TestCase # noqa: F401 | ||
|
||
# Create your tests here. |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,12 @@ | ||
import json | ||
|
||
from django.conf import settings | ||
from django.contrib.auth import login | ||
from django.contrib.auth import logout as auth_logout | ||
from django.contrib.auth.decorators import login_required | ||
from django.http import HttpResponse, HttpResponseBadRequest | ||
from django.shortcuts import redirect | ||
from social_core.backends.google import GooglePlusAuth | ||
from social_core.backends.oauth import BaseOAuth1, BaseOAuth2 | ||
from social_core.backends.utils import load_backends | ||
from social_django.utils import load_strategy, psa | ||
from social_django.utils import psa | ||
|
||
from .decorators import render_to | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Detected a potential XSS vulnerability in the |
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
from django.contrib import admin | ||
from django.contrib import admin # noqa: F401 | ||
|
||
# Register your models here. |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
from django.test import TestCase | ||
from django.test import TestCase # noqa: F401 | ||
|
||
# Create your tests here. |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,12 @@ | ||
import json | ||
|
||
from django.conf import settings | ||
from django.contrib.auth import login | ||
from django.contrib.auth import logout as auth_logout | ||
from django.contrib.auth.decorators import login_required | ||
from django.http import HttpResponse, HttpResponseBadRequest | ||
from django.shortcuts import redirect | ||
from social_core.backends.google import GooglePlusAuth | ||
from social_core.backends.oauth import BaseOAuth1, BaseOAuth2 | ||
from social_core.backends.utils import load_backends | ||
from social_django.utils import load_strategy, psa | ||
from social_django.utils import psa | ||
|
||
from .decorators import render_to | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Detected direct rendering of data to the end user via 'HttpResponse'. This could potentially lead to Cross-Site Scripting (XSS) vulnerabilities if the data is not properly sanitized. Consider using Django's template engine to safely render HTML, which automatically escapes variables unless explicitly marked otherwise. - return HttpResponse(json.dumps(data), mimetype="application/json")
+ return JsonResponse(data) Note: |
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,2 @@ | ||
from example.models import user | ||
from social_flask_sqlalchemy import models | ||
from example.models import user # noqa: F401 | ||
from social_flask_sqlalchemy import models # noqa: F401 |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,2 @@ | ||
from example.routes import main | ||
from social_flask import routes | ||
from example.routes import main # noqa: F401 | ||
from social_flask import routes # noqa: F401 |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,17 @@ | ||
#!/usr/bin/env python | ||
import click | ||
from example import app, db | ||
from flask_script import Manager, Server, Shell | ||
from flask.cli import FlaskGroup | ||
|
||
manager = Manager(app) | ||
manager.add_command("runserver", Server()) | ||
manager.add_command("shell", Shell(make_context=lambda: {"app": app, "db": db})) | ||
|
||
@click.group(cls=FlaskGroup, create_app=lambda: app) | ||
def cli(): | ||
"""Management script for the Example Flask Social Login application.""" | ||
|
||
@app.shell_context_processor | ||
def make_shell_context(): | ||
return dict(db=db) | ||
|
||
|
||
if __name__ == "__main__": | ||
manager.run() | ||
cli() |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,3 @@ | ||
-r ../requirements.txt | ||
flask-script | ||
flask-mongoengine | ||
social-auth-app-flask-mongoengine |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,2 @@ | ||
from example.models import user | ||
from social_flask_peewee import models | ||
from example.models import user # noqa: F401 | ||
from social_flask_peewee import models # noqa: F401 |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,2 @@ | ||
from example.routes import main | ||
from social_flask import routes | ||
from example.routes import main # noqa: F401 | ||
from social_flask import routes # noqa: F401 |
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.
The update to the database connection string formatting using
format
is correct and improves readability. However, consider using f-strings for string formatting as they are more readable and efficient in Python 3.6+.Committable suggestion