class War(db.Model): __tablename__ = "war" id = db.Column(db.Integer, primary_key = True) savegame_id = db.Column(db.Integer, db.ForeignKey('savegame.id')) name = db.Column(db.String, default = False) ongoing = db.Column(db.Boolean) infantry = db.Column(db.Integer, default = 0) cavalry = db.Column(db.Integer, default = 0) artillery = db.Column(db.Integer, default = 0) attrition = db.Column(db.Integer, default = 0) combat = db.Column(db.Integer, default = 0) total = db.Column(db.Integer, default = 0) participants = db.relationship("WarParticipant", cascade = "all, delete") army_battles = db.relationship("ArmyBattle", cascade = "all, delete") navy_battles = db.relationship("NavyBattle", cascade = "all, delete")
class Nation(db.Model): __tablename__ = 'nation' tag = db.Column(db.String(3), primary_key = True) name = db.Column(db.String) savegame_data = db.relationship("NationSavegameData", backref = "nation", cascade = "all, delete") savegame_goods_produced = db.relationship("NationSavegameGoodsProduced", backref = "nation", cascade = "all, delete") savegame_points_spent = db.relationship("NationSavegamePointsSpent", backref = "nation", cascade = "all, delete") savegame_income_per_year = db.relationship("NationSavegameIncomePerYear", backref = "nation", cascade = "all, delete") savegame_army_losses = db.relationship("NationSavegameArmyLosses", backref = "nation", cascade = "all, delete") savegame_navy_losses = db.relationship("NationSavegameNavyLosses", backref = "nation", cascade = "all, delete") provinces = db.relationship("NationSavegameProvinces", backref = "nation", cascade = "all, delete")
class User(db.Model, UserMixin): __tablename__ = 'user' id = db.Column(db.Integer, primary_key = True) username = db.Column(db.String(20), unique = True, nullable = False) email = db.Column(db.String(120), unique = True, nullable = False) password = db.Column(db.String(60), nullable = False) savegames = db.relationship("Savegame", backref = "owner", lazy = True) def get_reset_token(self, expires_sec = 1800): s = Serializer(current_app.config["SECRET_KEY"], expires_sec) return s.dumps({"user_id": self.id}).decode("utf-8") @staticmethod def verify_reset_token(token): s = Serializer(current_app.config["SECRET_KEY"]) try: user_id = s.loads(token)['user_id'] except: return None return User.query.get(user_id) def __repr__(self): return f"User('{self.username}','{self.email}','{self.image_file}')"
class MP(db.Model): __tablename__ = 'mp' id = db.Column(db.Integer, primary_key = True) name = db.Column(db.String, nullable = False) savegames = db.relationship("Savegame", backref = "mp", lazy = True)
class SuperRegion(db.Model): __tablename__ = "superregion" id = db.Column(db.Integer, primary_key = True) name = db.Column(db.String) provinces = db.relationship("Region", backref = "superregion")
class Region(db.Model): __tablename__ = "region" id = db.Column(db.Integer, primary_key = True) name = db.Column(db.String) superregion_id = db.Column(db.Integer, db.ForeignKey("superregion.id")) areas = db.relationship("Area", backref = "region")
class Area(db.Model): __tablename__ = "area" id = db.Column(db.Integer, primary_key = True) name = db.Column(db.String) region_id = db.Column(db.Integer, db.ForeignKey("region.id")) provinces = db.relationship("Province", backref = "area")
class TradeGood(db.Model): __tablename__ = 'trade_good' id = db.Column(db.Integer, primary_key = True) name = db.Column(db.String) savegame_total_goods_produced = db.relationship("TotalGoodsProduced", backref = "trade_good", cascade = "all, delete")
class Savegame(db.Model): __tablename__ = 'savegame' id = db.Column(db.Integer, primary_key = True) mp_id = db.Column(db.Integer, db.ForeignKey('mp.id')) user_id = db.Column(db.Integer, db.ForeignKey('user.id')) institution = db.Column(db.Enum(Institutions), nullable = True) name = db.Column(db.String, nullable = True) year = db.Column(db.Integer, default = None) file = db.Column(db.String(120), nullable = False) map_file = db.Column(db.String(120), nullable = True) parse_flag = db.Column(db.Boolean, default = False, nullable = False) nations = db.relationship("Nation", secondary = savegame_nations) player_nations = db.relationship("Nation", secondary = savegame_player_nations) army_battles = db.relationship("ArmyBattle", backref = "savegame", cascade = "all, delete") navy_battles = db.relationship("NavyBattle", backref = "savegame", cascade = "all, delete") wars = db.relationship("War", backref = "savegame", cascade = "all, delete") nation_data = db.relationship("NationSavegameData", backref = "savegame", cascade = "all, delete") nation_goods_produced = db.relationship("NationSavegameGoodsProduced", backref = "savegame", cascade = "all, delete") total_trade_goods = db.relationship("TotalGoodsProduced", backref = "savegame", cascade = "all, delete") nation_points_spent = db.relationship("NationSavegamePointsSpent", backref = "savegame", cascade = "all, delete") nation_income_per_year = db.relationship("NationSavegameIncomePerYear", backref = "savegame", cascade = "all, delete") nation_army_losses = db.relationship("NationSavegameArmyLosses", backref = "savegame", cascade = "all, delete") nation_navy_losses = db.relationship("NationSavegameNavyLosses", backref = "savegame", cascade = "all, delete") provinces = db.relationship("NationSavegameProvinces", backref = "savegame", cascade = "all, delete") new_plots = db.relationship("SavegamePlots", backref = "new_savegame", foreign_keys = 'SavegamePlots.new_savegame_id', cascade = "all, delete") old_plots = db.relationship("SavegamePlots", backref = "old_savegame", foreign_keys = 'SavegamePlots.old_savegame_id', cascade = "all, delete") def __commit_delete__(self): try: os.remove(os.path.join(app.root_path, 'static/savegames', self.file)) except FileNotFoundError: print(os.path.join(app.root_path, 'static/savegames', self.file)) if self.map_file: try: os.remove(os.path.join(app.root_path, 'static/maps', self.map_file)) except FileNotFoundError: print(os.path.join(app.root_path, 'static/maps', self.map_file))