root / social / apps / webpy_app / models.py @ a0a04c0a
History | View | Annotate | Download (1.7 kB)
1 |
"""Flask SQLAlchemy ORM models for Social Auth"""
|
---|---|
2 |
import web |
3 |
|
4 |
from sqlalchemy import Column, Integer, String, ForeignKey |
5 |
from sqlalchemy.orm import relationship |
6 |
from sqlalchemy.ext.declarative import declarative_base |
7 |
|
8 |
from social.utils import setting_name, module_member |
9 |
from social.storage.sqlalchemy_orm import SQLAlchemyUserMixin, \ |
10 |
SQLAlchemyAssociationMixin, \
|
11 |
SQLAlchemyNonceMixin, \
|
12 |
SQLAlchemyCodeMixin, \
|
13 |
BaseSQLAlchemyStorage
|
14 |
|
15 |
|
16 |
SocialBase = declarative_base() |
17 |
|
18 |
UID_LENGTH = web.config.get(setting_name('UID_LENGTH'), 255) |
19 |
User = module_member(web.config[setting_name('USER_MODEL')])
|
20 |
|
21 |
|
22 |
class WebpySocialBase(object): |
23 |
@classmethod
|
24 |
def _session(cls): |
25 |
return web.db_session
|
26 |
|
27 |
|
28 |
class UserSocialAuth(WebpySocialBase, SQLAlchemyUserMixin, SocialBase): |
29 |
"""Social Auth association model"""
|
30 |
uid = Column(String(UID_LENGTH)) |
31 |
user_id = Column(Integer, ForeignKey(User.id), |
32 |
nullable=False, index=True) |
33 |
user = relationship(User, backref='social_auth')
|
34 |
|
35 |
@classmethod
|
36 |
def username_max_length(cls): |
37 |
return User.__table__.columns.get('username').type.length |
38 |
|
39 |
@classmethod
|
40 |
def user_model(cls): |
41 |
return User
|
42 |
|
43 |
|
44 |
class Nonce(WebpySocialBase, SQLAlchemyNonceMixin, SocialBase): |
45 |
"""One use numbers"""
|
46 |
pass
|
47 |
|
48 |
|
49 |
class Association(WebpySocialBase, SQLAlchemyAssociationMixin, SocialBase): |
50 |
"""OpenId account association"""
|
51 |
pass
|
52 |
|
53 |
|
54 |
class Code(WebpySocialBase, SQLAlchemyCodeMixin, SocialBase): |
55 |
pass
|
56 |
|
57 |
|
58 |
class WebpyStorage(BaseSQLAlchemyStorage): |
59 |
user = UserSocialAuth |
60 |
nonce = Nonce |
61 |
association = Association |
62 |
code = Code |