This repository has been archived by the owner on Feb 22, 2024. It is now read-only.
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Matt Wright
committed
Apr 4, 2013
1 parent
c4a7c6e
commit 94ac607
Showing
8 changed files
with
117 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
# -*- coding: utf-8 -*- | ||
|
||
import sys | ||
import os | ||
|
||
sys.path.pop(0) | ||
sys.path.insert(0, os.getcwd()) | ||
|
||
from flask_peewee.db import Database | ||
from flask.ext.security import Security, UserMixin, RoleMixin, \ | ||
PeeweeUserDatastore | ||
from flask.ext.social import Social, PeeweeConnectionDatastore | ||
from peewee import * | ||
|
||
from tests.test_app import create_app as create_base_app, populate_data | ||
|
||
|
||
def create_app(config=None, debug=True): | ||
app = create_base_app(config, debug) | ||
app.config['DATABASE'] = { | ||
'name': 'example2.db', | ||
'engine': 'peewee.SqliteDatabase', | ||
} | ||
|
||
db = Database(app) | ||
|
||
class Role(db.Model, RoleMixin): | ||
name = TextField(unique=True) | ||
description = TextField(null=True) | ||
|
||
class User(db.Model, UserMixin): | ||
email = TextField() | ||
password = TextField() | ||
last_login_at = DateTimeField(null=True) | ||
current_login_at = DateTimeField(null=True) | ||
last_login_ip = TextField(null=True) | ||
current_login_ip = TextField(null=True) | ||
login_count = IntegerField(null=True) | ||
active = BooleanField(default=True) | ||
confirmed_at = DateTimeField(null=True) | ||
|
||
class UserRoles(db.Model): | ||
""" Peewee does not have built-in many-to-many support, so we have to | ||
create this mapping class to link users to roles.""" | ||
user = ForeignKeyField(User, related_name='roles') | ||
role = ForeignKeyField(Role, related_name='users') | ||
name = property(lambda self: self.role.name) | ||
description = property(lambda self: self.role.description) | ||
|
||
class Connection(db.Model): | ||
user = ForeignKeyField(User, related_name='connections') | ||
provider_id = TextField() | ||
provider_user_id = TextField() | ||
access_token = TextField() | ||
secret = TextField(null=True) | ||
display_name = TextField() | ||
profile_url = TextField() | ||
image_url = TextField() | ||
rank = IntegerField(null=True) | ||
|
||
app.security = Security(app, PeeweeUserDatastore(db, User, Role, UserRoles)) | ||
app.social = Social(app, PeeweeConnectionDatastore(db, Connection)) | ||
|
||
@app.before_first_request | ||
def before_first_request(): | ||
for Model in (Role, User, UserRoles, Connection): | ||
Model.drop_table(fail_silently=True) | ||
Model.create_table(fail_silently=True) | ||
populate_data() | ||
|
||
return app | ||
|
||
if __name__ == '__main__': | ||
create_app().run() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -59,7 +59,6 @@ def before_first_request(): | |
db.drop_all() | ||
db.create_all() | ||
populate_data() | ||
pass | ||
|
||
return app | ||
|
||
|