Browse Source

make model modules itself import each other with relative imports

testing
Burathar 4 years ago
parent
commit
bbb5504dad
  1. 25
      app/models/__init__.py
  2. 4
      app/models/game.py
  3. 5
      app/models/game_player.py
  4. 2
      app/models/notification.py
  5. 3
      app/models/objective.py
  6. 13
      app/models/user.py

25
app/models/__init__.py

@ -1,16 +1,11 @@
from app import login
from app.models.game import Game from .game import Game
from app.models.game_player import GamePlayer from .game_player import GamePlayer
from app.models.game_state import GameState from .game_state import GameState
from app.models.location import Location, LocationEncoder from .location import Location, LocationEncoder
from app.models.notification_player import NotificationPlayer from .notification_player import NotificationPlayer
from app.models.objective import Objective, ObjectiveMinimalEncoder from .objective import Objective, ObjectiveMinimalEncoder
from app.models.player_caught_player import PlayerCaughtPlayer from .player_caught_player import PlayerCaughtPlayer
from app.models.player_found_objective import PlayerFoundObjective from .player_found_objective import PlayerFoundObjective
from app.models.role import Role from .role import Role
from app.models.user import User from .user import User
@login.user_loader
def load_user(id):
return User.query.get(int(id))

4
app/models/game.py

@ -1,6 +1,8 @@
from sqlalchemy.ext.associationproxy import association_proxy from sqlalchemy.ext.associationproxy import association_proxy
from app import db from app import db
from app.models import GameState, GamePlayer, Role from .game_state import GameState
from .game_player import GamePlayer
from .role import Role
class Game(db.Model): class Game(db.Model):
__tablename__ = 'game' __tablename__ = 'game'

5
app/models/game_player.py

@ -1,7 +1,10 @@
from sqlalchemy.ext.associationproxy import association_proxy from sqlalchemy.ext.associationproxy import association_proxy
from app import db from app import db
from app.models import Role, NotificationPlayer, PlayerFoundObjective, PlayerCaughtPlayer from .role import Role
from .notification_player import NotificationPlayer
from .player_found_objective import PlayerFoundObjective
from .player_caught_player import PlayerCaughtPlayer
class GamePlayer(db.Model): class GamePlayer(db.Model):
__tablename__ = 'game_player' __tablename__ = 'game_player'

2
app/models/notification.py

@ -2,7 +2,7 @@ from sqlalchemy.ext.associationproxy import association_proxy
from sqlalchemy.sql import func from sqlalchemy.sql import func
from app import db from app import db
from app.models import NotificationPlayer from .notification_player import NotificationPlayer
class Notification(db.Model): class Notification(db.Model):
__tablename__ = 'notification' __tablename__ = 'notification'

3
app/models/objective.py

@ -3,7 +3,8 @@ from json import JSONEncoder
from sqlalchemy.ext.associationproxy import association_proxy from sqlalchemy.ext.associationproxy import association_proxy
from app import db from app import db
from app.models import PlayerFoundObjective, Role from .player_found_objective import PlayerFoundObjective
from .role import Role
class Objective(db.Model): class Objective(db.Model):
""" !Always call set_hash after() creating new instance! """ """ !Always call set_hash after() creating new instance! """

13
app/models/user.py

@ -5,8 +5,8 @@ from flask_login import UserMixin
from sqlalchemy.ext.associationproxy import association_proxy from sqlalchemy.ext.associationproxy import association_proxy
from werkzeug.security import generate_password_hash, check_password_hash from werkzeug.security import generate_password_hash, check_password_hash
from app import db from app import db, login
from app.models import GamePlayer, PlayerFoundObjective, PlayerCaughtPlayer, NotificationPlayer, Role from app.models import GamePlayer, Role
class User(UserMixin, db.Model): class User(UserMixin, db.Model):
""" !Always call set_auth_hash() after creating new instance! """ """ !Always call set_auth_hash() after creating new instance! """
@ -24,10 +24,6 @@ class User(UserMixin, db.Model):
creator=lambda game: GamePlayer(game=game)) creator=lambda game: GamePlayer(game=game))
locations = db.relationship( locations = db.relationship(
'Location', 'Location',
lazy='select', lazy='select',
@ -78,3 +74,8 @@ class User(UserMixin, db.Model):
def delete_orphans(): def delete_orphans():
User.query.filter(~User.user_games.any()).delete() User.query.filter(~User.user_games.any()).delete()
db.session.commit() db.session.commit()
@login.user_loader
def load_user(id):
return User.query.get(int(id))
Loading…
Cancel
Save