Skip to content

Commit

Permalink
Binding DB sessions based on SQLAlchemy 1, changing how to declare Ba…
Browse files Browse the repository at this point in the history
…se Model classes, and other code modernization

- DB session binding based on SQLAlchemy 2, Base Model class declaration method change
- Reflected select, delete code based on SQLAlchemy 2
- Changed how to declare Model class based on SQLAlchemy 2
- Fixed issue with social connection termination
- Fixed import errors found in several examples
- Added pyproject.toml file after removing setup.py due to the introduction of PEP 517/518
- Fixed minimum installed version to Python 3.7
  • Loading branch information
이지호 committed Feb 24, 2024
1 parent 9bbede4 commit b8cc12c
Show file tree
Hide file tree
Showing 7 changed files with 70 additions and 54 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,12 @@ and this project adheres to [Semantic Versioning](http://semver.org/).

## [Unreleased]

### Changed
- Modified model and access code to work with SQLAlchemy version 2 (Issue #2)
- Updated packaging information files per PEP 517, PEP 518 (Issue #3)
- Restricted Python minimum working version to 3.7 or higher to align with SQLAlchemy 2 (Issue #2)
- Fixed csrfmiddlewaretoken argument error when calling disconnect method in view.py when disconnecting social connections (Issue #4)

## [1.0.0](https://github.com/python-social-auth/social-app-cherrypy/releases/tag/1.0.0) - 2017-01-22

### Added
Expand Down
8 changes: 2 additions & 6 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,12 +1,8 @@
build:
@ python setup.py sdist
@ python setup.py bdist_wheel --python-tag py2
@ BUILD_VERSION=3 python setup.py bdist_wheel --python-tag py3
@ python -m build

publish:
@ python setup.py sdist upload
@ python setup.py bdist_wheel --python-tag py2 upload
@ BUILD_VERSION=3 python setup.py bdist_wheel --python-tag py3 upload
@ twine upload dist/*

clean:
@ find . -name '*.py[co]' -delete
Expand Down
53 changes: 53 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
[build-system]
requires = ["setuptools"]
build-backend = "setuptools.build_meta"

[project]
name = 'social-auth-app-cherrypy'
dynamic = ["version"]
dependencies = [
"six",
"social-auth-core>=1.0.0",
"social-auth-storage-sqlalchemy>=1.0.0",
]
authors = [
{name = "Matias Aguirre", email = "matiasaguirre@gmail.com"},
{name = "Lee Ji-ho", email = "search5@gmail.com"},
]
description = 'Python Social Authentication, CherryPy integration.'
license = {text = 'BSD'}
keywords = ["cherrypy", "sqlalchemy", "social auth"]
readme = "README.md"
classifiers=[
'Development Status :: 4 - Beta',
'Topic :: Internet',
'License :: OSI Approved :: BSD License',
'Intended Audience :: Developers',
'Environment :: Web Environment',
'Programming Language :: Python',
'Programming Language :: Python :: 3.7',
'Programming Language :: Python :: 3.8',
'Programming Language :: Python :: 3.9',
'Programming Language :: Python :: 3.10',
'Programming Language :: Python :: 3.11',
'Programming Language :: Python :: 3.12'
]
requires-python = ">= 3.7"

[project.urls]
Repository = 'https://github.com/python-social-auth/social-app-cherrypy'
Documentation = 'http://python-social-auth.readthedocs.org'
Issues = 'https://github.com/python-social-auth/social-app-cherrypy/issues'
Changelog = 'https://github.com/python-social-auth/social-app-cherrypy/blob/master/CHANGELOG.md
[options]
zip_safe = false
[tool.setuptools]
include-package-data = true
[tool.setuptools.packages]
find = {}
[tool.setuptools.dynamic]
version = {attr = "social_cherrypy.__version__"}
3 changes: 0 additions & 3 deletions requirements.txt

This file was deleted.

36 changes: 0 additions & 36 deletions setup.py

This file was deleted.

16 changes: 8 additions & 8 deletions social_cherrypy/models.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
"""Flask SQLAlchemy ORM models for Social Auth"""
import cherrypy

from sqlalchemy import Column, Integer, String, ForeignKey
from sqlalchemy.orm import relationship
from sqlalchemy.ext.declarative import declarative_base
from sqlalchemy import String, ForeignKey
from sqlalchemy.orm import relationship, DeclarativeBase, Mapped, mapped_column

from social_core.utils import setting_name, module_member
from social_sqlalchemy.storage import SQLAlchemyUserMixin, \
Expand All @@ -13,7 +12,8 @@
BaseSQLAlchemyStorage


SocialBase = declarative_base()
class SocialBase(DeclarativeBase):
pass

DB_SESSION_ATTR = cherrypy.config.get(setting_name('DB_SESSION_ATTR'), 'db')
UID_LENGTH = cherrypy.config.get(setting_name('UID_LENGTH'), 255)
Expand All @@ -28,10 +28,10 @@ def _session(cls):

class UserSocialAuth(CherryPySocialBase, SQLAlchemyUserMixin, SocialBase):
"""Social Auth association model"""
uid = Column(String(UID_LENGTH))
user_id = Column(Integer, ForeignKey(User.id),
nullable=False, index=True)
user = relationship(User, backref='social_auth')
uid: Mapped[str] = mapped_column(String(UID_LENGTH))
user_id: Mapped[int] = mapped_column(ForeignKey(User.id),
nullable=False, index=True)
user: Mapped["User"] = relationship(User, backref='social_auth')

@classmethod
def username_max_length(cls):
Expand Down
2 changes: 1 addition & 1 deletion social_cherrypy/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ def complete(self, backend, *args, **kwargs):

@cherrypy.expose
@psa()
def disconnect(self, backend, association_id=None):
def disconnect(self, backend, association_id=None, csrfmiddlewaretoken=None):
user = getattr(cherrypy.request, 'user', None)
return do_disconnect(self.backend, user, association_id)

Expand Down

0 comments on commit b8cc12c

Please sign in to comment.