class TrackerEntryModel(db.Model): __tablename__ = "TrackerEntries" id = db.Column(db.Integer, primary_key=True) time = db.Column(db.DateTime, nullable=False, default=datetime.now) value = db.Column(db.Float, nullable=False) unit_id = db.Column(db.Integer, db.ForeignKey("UnitIndex.id"), nullable=False) unit = db.relationship("UnitModel", foreign_keys="TrackerEntryModel.unit_id") parent_tracker_id = db.Column(db.Integer, db.ForeignKey("TrackerIndex.id"), nullable=False) tracker = db.relationship( "TrackerModel", back_populates="entries", foreign_keys="TrackerEntryModel.parent_tracker_id") def __str__(self): return "%u Tracker Entry: %s %s, tracker (%u) @ %s" % ( int(self.id), str(self.value), str(self.unit.abbreviation), int(self.parent_tracker_id), str(self.time)) @staticmethod def has_owner(self): return True # Returns True is the given user id is considered the owner of this # tracker entry def check_owner(self, id): return self.tracker.check_owner(id)
class GymEquipmentAssociation(db.Model): __tablename__ = "GymEquipmentList" equipment_id = db.Column(db.Integer, db.ForeignKey( "EquipmentIndex.id"), nullable=False, primary_key=True) gym_id = db.Column(db.Integer, db.ForeignKey( "GymIndex.id"), nullable=False, primary_key=True) def __str__(self): return "GymEquipAssoc (GymID -> EquipID): %u -> %u " % (self.gym.id, self.equipment.id)
class MuscleGroupAssociationTable(db.Model): """Association table. Associates MuscleGroups with their Muscles and vice-versa""" __tablename__ = "MuscleGroupAssociation" group_id = db.Column(db.Integer, db.ForeignKey("MuscleGroupIndex.id"), primary_key=True) muscle_id = db.Column(db.Integer, db.ForeignKey("MuscleIndex.id"), primary_key=True) def __str__(self): return "MuscleGroupAssociation: group %u -> muscle %u" % ( self.group_id, self.muscle_id)
class MealPlanModel(db.Model): __tablename__ = "MealPlanIndex" id = db.Column(db.Integer, primary_key=True) # Management Info # Name of this meal plan name = db.Column(db.String(60), unique=True, nullable=False) description = db.Column(db.Text, nullable=True) # If set to true, all users can see this ingredient is_public = db.Column(db.Boolean, nullable=False, default=False) # The user who added this mealplan to the database owner_id = db.Column(db.Integer, db.ForeignKey( "UserIndex.id"), nullable=False) owner = db.relationship("UserModel", back_populates="mealplans") days = db.relationship("MealPlanDayModel", back_populates="mealplan") @staticmethod def has_owner(): return True def check_owner(self, id): return self.owner_id == id
class ExerciseEquipmentAssociation(db.Model): __tablename__ = "ExerciseEquipmentList" equipment_id = db.Column(db.Integer, db.ForeignKey("EquipmentIndex.id"), nullable=False, primary_key=True) exercise_id = db.Column(db.Integer, db.ForeignKey("ExerciseIndex.id"), nullable=False, primary_key=True) def __str__(self): return "GymEquipAssoc: %u -> %u " % (self.exercise.id, self.equipment.id)
class ConsumedEntryModel(db.Model): __tablename__ = "ConsumedEntryIndex" id = db.Column(db.Integer, primary_key=True) # Name of the food that was consumed. name = db.Column(db.String(60), nullable=False) # Time when this entry was made time = db.Column(db.DateTime(), nullable=False, default=datetime.now()) # The user who added this mealplan to the database owner_id = db.Column(db.Integer, db.ForeignKey( "UserIndex.id"), nullable=False) owner = db.relationship("UserModel", back_populates="consumption_entries") # Nutritional Info # Amount of calories consumed (grams) calories = db.Column(db.Float, nullable=False, default=0) # Amount of protein consumed (grams) protein = db.Column(db.Float, nullable=False, default=0) # Amount of carbohydrates consumed (grams) carbohydrates = db.Column(db.Float, nullable=False, default=0) # Amount of fats consumed (grams) fat = db.Column(db.Float, nullable=False, default=0) # Linking to a Consumable servings = db.Column(db.Float, nullable=False, default=1) consumable_id = db.Column(db.Integer, db.ForeignKey("ConsumableIndex.id")) consumable = db.relationship("ConsumableModel") @staticmethod def has_owner(): return True def check_owner(self, id): return self.owner_id == id def __str__(self): return "%u ConsumedEntryModel: %s @ %s, o(%u), c(%u)" % ( self.id, self.name, str(self.time), self.owner_id, self.consumable_id)
class ExerciseModel(db.Model): __tablename__ = "ExerciseIndex" id = db.Column(db.Integer, primary_key=True) # Internal name of the exercise for linking + id canonical_name = db.Column(db.String(100), unique=True, nullable=False) # Name of the exercise to display to the user name = db.Column(db.String(100), unique=True, nullable=False) description = db.Column(db.Text, nullable=True) # Is this exercise measured in time? use_duration = db.Column(db.Boolean, nullable=False, default=0) # Is this exercise measured in distance? use_distance = db.Column(db.Boolean, nullable=False, default=0) # Is this exercise measured in weight? use_weight = db.Column(db.Boolean, nullable=False, default=0) # What pieces of equipment does this exercise use? equipment = db.relationship("EquipmentModel", secondary="ExerciseEquipmentList", back_populates="exercises") # Is this exercise a variation of another exercise, if so, which exercise? # (Ex: Close grip bench is a variation of bench press) parent_exercise_id = db.Column(db.Integer, db.ForeignKey("ExerciseIndex.id"), nullable=True) parent_exercise = db.relationship( "ExerciseModel", foreign_keys="ExerciseModel.parent_exercise_id", back_populates="variations") variations = db.relationship("ExerciseModel") def __str__(self): return "%u Exercise: %s dur(%s), dis(%s), wght(%s), equip(%s)" % ( self.id, self.name, str(self.use_duration), str(self.use_distance), str(self.use_weight), str(self.equipment.name)) @staticmethod def has_owner(): return False
class GymModel(db.Model): __tablename__ = "GymIndex" """ Every Gym can have multiple pieces of equipment associated with it. Gyms can be public or private (private by default). Gyms are really nothing more than a collection of equipment, making it easier to plan workouts """ id = db.Column(db.Integer, primary_key=True) # Name of the gym name = db.Column(db.String(100), unique=False, nullable=False) # Location of the gym location = db.Column(db.String(100), nullable=True) description = db.Column(db.Text, nullable=True) ### Ownership and visibility # Is this gym visible to all users? If set to true, then all users can use # this gym is_public = db.Column(db.Boolean, nullable=False, default=False) # The user who added this gym to the database owner_id = db.Column(db.Integer, db.ForeignKey( "UserIndex.id"), nullable=False) owner = db.relationship("UserModel", backref="gyms") equipment = db.relationship("EquipmentModel", secondary="GymEquipmentList") @staticmethod def has_owner(): return True def check_owner(self, id): return self.owner.id == id def __str__(self): return "%u Gym: %s public(%s), owned by %u (%s)" % ( self.id, self.name, str(self.is_public), self.owner.id, self.owner.username)
class MealPlanDayModel(db.Model): __tablename__ = "MealPlanDayIndex" id = db.Column(db.Integer, primary_key=True) # What day in the meal plan is this? First day == 1, no order = 0 daynumber = db.Column(db.Integer, nullable=False, default=0) # What mealplan does this belong to? parent_mealplan_id = db.Column( db.Integer, db.ForeignKey("MealPlanIndex.id"), nullable=False) mealplan = db.relationship("MealPlanModel", back_populates="days") # List of meals in this day meals = db.relationship("MealModel", back_populates="mealday") @staticmethod def has_owner(): return True def check_owner(self, id): return self.mealplan.check_owner(id)
class MealModel(db.Model): __tablename__ = "MealIndex" id = db.Column(db.Integer, primary_key=True) # What meal in the day is this? First meal == 1, no order = 0 mealnumber = db.Column(db.Integer, nullable=False, default=0) # Around what time is this meal eaten? mealtime = db.Column(db.Time, nullable=True) # Parent mealday that this meal exists in parent_mealday_id = db.Column(db.Integer, db.ForeignKey( "MealPlanDayIndex.id"), nullable=False) mealday = db.relationship("MealPlanDayModel", back_populates="meals") @staticmethod def has_owner(): return True def check_owner(self, id): return self.mealday.check_owner(id)
class WorkoutProgramModel(db.Model): __tablename__ = "WorkoutProgramIndex" id = db.Column(db.Integer, primary_key=True) # Name of the workout program name = db.Column(db.String(100), nullable=False) # Description of the workout program description = db.Column(db.String(300), nullable=True) # Can other users see this workout program? is_public = db.Column(db.Boolean, nullable=False, default=False) # User who owns this program owner_id = db.Column(db.Integer, db.ForeignKey("UserIndex.id"), nullable=False) owner = db.relationship("UserModel", back_populates="programs") # Workouts in this program workouts = db.relationship("WorkoutModel", back_populates="program", cascade="all, delete") @staticmethod def has_owner(self): return True # Returns True is the given user id is considered the owner of this # tracker entry def check_owner(self, id): return self.owner_id == id def __str__(self): return "%u ProgramModel: %s, %u(%s), public(%s)" % ( self.id, self.name, self.owner_id, self.owner.username, str(self.is_public))
class MuscleSectionModel(db.Model): __tablename__ = "MuscleSectionIndex" id = db.Column(db.Integer, primary_key=True) # Optional: ID of this muscle section sused to locate on the anatomy chart diagram_id = db.Column(db.Integer, nullable=True) # Name of this muscle section. For example "Upper pec" name = db.Column(db.String(100), unique=True, nullable=False) # What muscle is this muscle section of? parent_muscle_id = db.Column(db.Integer, db.ForeignKey("MuscleIndex.id"), nullable=False) parent_muscle = db.relationship("MuscleModel", backref="sections") @staticmethod def has_owner(): return False def __str__(self): return "%i MuscleSectionModel: %s" % (self.id, self.name)
class WorkoutModel(db.Model): __tablename__ = "WorkoutIndex" id = db.Column(db.Integer, primary_key=True) # Name of the workout day name = db.Column(db.String(100), nullable=False) # What day does this occur on? Freeform entry day = db.Column(db.String(20), nullable=True) # What week does this occur on? Freeform entry week = db.Column(db.String(20), nullable=True) # Sets of exercises that are performed on this day sets = db.relationship("SetPlanModel", back_populates="workout", cascade="all, delete") # Workout Program this workout belongs to parent_program_id = db.Column(db.Integer, db.ForeignKey("WorkoutProgramIndex.id"), nullable=False) program = db.relationship("WorkoutProgramModel", back_populates="workouts") @staticmethod def has_owner(self): return True # Returns True is the given user id is considered the owner of this # tracker entry def check_owner(self, id): return self.program.check_owner(id) def __str__(self): return "%u WorkoutModel: %s on %s, %u" % (self.id, self.name, self.day, self.week_id)
class TrackerModel(db.Model): __tablename__ = "TrackerIndex" id = db.Column(db.Integer, primary_key=True) name = db.Column(db.String(40), nullable=False) dimension = db.Column(db.String(20), nullable=False) owner_id = db.Column(db.Integer, db.ForeignKey("UserIndex.id"), nullable=False) owner = db.relationship("UserModel", back_populates="trackers") entries = db.relationship("TrackerEntryModel", back_populates="tracker") def __str__(self): return "%u Tracker: %s (%s), user %s (%u)" % (int( self.id), str(self.name), str( self.dimension), str(self.owner.username), int(self.owner_id)) @staticmethod def has_owner(self): return True def check_owner(self, id): return self.owner_id == id
class UserModel(db.Model): __tablename__ = "UserIndex" id = db.Column(db.Integer, primary_key=True) # Management Info username = db.Column(db.String(30), unique=True, nullable=False) # Email address of the user. NOTE: Can be NULL! email = db.Column(db.String(80), nullable=True) # Password hash of the user. password = db.Column(db.String(128), nullable=False) # Date this user was born. Used for calculating age. birthdate = db.Column(db.Date(), nullable=False) # Datetime this user was created. created_on = db.Column(db.DateTime(), nullable=False, default=datetime.now()) # User role. Current values: "user", "admin" role = db.Column(db.String(10), nullable=False, default="user") # User Data # List of trackers this user has running trackers = db.relationship( "TrackerModel", back_populates="owner", cascade="all, delete") # List of nutritional items created by this user consumables = db.relationship( "ConsumableModel", back_populates="owner", cascade="all, delete") recipies = db.relationship( "RecipeModel", back_populates="owner", cascade="all, delete") mealplans = db.relationship( "MealPlanModel", back_populates="owner", cascade="all, delete") set_entries = db.relationship( "SetEntryModel", back_populates="owner", cascade="all, delete") consumption_entries = db.relationship( "ConsumedEntryModel", back_populates="owner", cascade="all, delete") programs = db.relationship( "WorkoutProgramModel", back_populates="owner", cascade="all, delete") # Unit Display Preferences # lb or kg exercise_weight_unit_id = db.Column( db.Integer, db.ForeignKey("UnitIndex.id"), nullable=False) exercise_weight_unit = db.relationship( "UnitModel", foreign_keys="UserModel.exercise_weight_unit_id") # mile or km exercise_distance_unit_id = db.Column( db.Integer, db.ForeignKey("UnitIndex.id"), nullable=False) exercise_distance_unit = db.relationship( "UnitModel", foreign_keys="UserModel.exercise_distance_unit_id") # oz/lb or grams food_weight_unit_id = db.Column( db.Integer, db.ForeignKey("UnitIndex.id"), nullable=False) food_weight_unit = db.relationship( "UnitModel", foreign_keys="UserModel.food_weight_unit_id") # fl. oz or Liters food_volume_unit_id = db.Column( db.Integer, db.ForeignKey("UnitIndex.id"), nullable=False) food_volume_unit = db.relationship( "UnitModel", foreign_keys="UserModel.food_volume_unit_id") # Pounds, stone, or kg? body_weight_unit_id = db.Column( db.Integer, db.ForeignKey("UnitIndex.id"), nullable=False) body_weight_unit = db.relationship( "UnitModel", foreign_keys="UserModel.body_weight_unit_id") # Feet or meters? body_distance_large_unit_id = db.Column( db.Integer, db.ForeignKey("UnitIndex.id"), nullable=False) body_distance_large_unit = db.relationship( "UnitModel", foreign_keys="UserModel.body_distance_large_unit_id") # Inches or cm? body_distance_small_unit_id = db.Column( db.Integer, db.ForeignKey("UnitIndex.id"), nullable=False) body_distance_small_unit = db.relationship( "UnitModel", foreign_keys="UserModel.body_distance_small_unit_id") # Diet Settings # Can this user not eat peanuts? (setting to True means that no recipies # containing peanuts will be suggested) no_peanuts = db.Column(db.Boolean, nullable=True) # Can this user not eat treenuts? no_treenuts = db.Column(db.Boolean, nullable=True) # Can this user not eat dairy? no_dairy = db.Column(db.Boolean, nullable=True) # Can this user not eat eggs? no_eggs = db.Column(db.Boolean, nullable=True) # Can this user not eat pork? no_pork = db.Column(db.Boolean, nullable=True) # Can this user not eat beef (cow)? no_beef = db.Column(db.Boolean, nullable=True) # Can this user not eat meat? no_meat = db.Column(db.Boolean, nullable=True) # Can this user not eat fish? no_fish = db.Column(db.Boolean, nullable=True) # Can this user not eat shellfish? no_shellfish = db.Column(db.Boolean, nullable=True) # Can this user not eat gluten? no_gluten = db.Column(db.Boolean, nullable=True) # Does this user require vegetarian only foods? is_vegetarian = db.Column(db.Boolean, nullable=True) # Does this user require vegan only foods? is_vegan = db.Column(db.Boolean, nullable=True) # Does this user require kosher only foods? is_kosher = db.Column(db.Boolean, nullable=True) # Returns the age (in years) of this user. Integer, not a fraction def age(self): bday = datetime.date(self.birthdate) today = date.today() return today.year - bday.year - \ ((today.month, today.day) < (bday.month, bday.day)) def get_tags(self): tags = [] if self.no_pork: tags.append("nopork") if self.no_meat: tags.append("nomeat") if self.no_fish: tags.append("nofish") if self.no_shellfish: tags.append("noshellfish") if self.no_beef: tags.append("nobeef") if self.no_dairy: tags.append("nodairy") if self.no_eggs: tags.append("noeggs") if self.no_peanuts: tags.append("nopeanuts") if self.no_gluten: tags.append("nogluten") if self.no_treenuts: tags.append("notreenuts") if self.is_vegan: tags.append("vegan") if self.is_vegetarian: tags.append("vegetarian") if self.is_kosher: tags.append("kosher") return tags def set_password(self, password): self.password = generate_password_hash(password) def check_password(self, password): return check_password_hash(self.password, password) @staticmethod def has_owner(self): return False
class SetPlanModel(db.Model): __tablename__ = "SetPlanIndex" id = db.Column(db.Integer, primary_key=True) # What exercise is being done for this set? exercise_id = db.Column(db.Integer, db.ForeignKey("ExerciseIndex.id"), nullable=False) exercise = db.relationship("ExerciseModel", foreign_keys="SetPlanModel.exercise_id") # What workout day does this belond to? workout_id = db.Column(db.Integer, db.ForeignKey("WorkoutIndex.id"), nullable=False) workout = db.relationship("WorkoutModel", foreign_keys="SetPlanModel.workout_id", back_populates="sets") # Field for specifying where this set falls. order = db.Column(db.Integer, nullable=True) # Number of times this exercise was performed in this set reps = db.Column(db.Integer, nullable=False, default=1) # Duration that this exercise was done for (if it is measured in time) duration = db.Column(db.Float, nullable=True) duration_unit_id = db.Column(db.Integer, db.ForeignKey("UnitIndex.id"), nullable=False) duration_unit = db.relationship( "UnitModel", foreign_keys="SetPlanModel.duration_unit_id") # Distance that this exercise was done for (if it is measured in distance) distance = db.Column(db.Float, nullable=True) distance_unit_id = db.Column(db.Integer, db.ForeignKey("UnitIndex.id"), nullable=False) distance_unit = db.relationship( "UnitModel", foreign_keys="SetPlanModel.distance_unit_id") # Weight that this exercise was done with (if this uses weight) weight = db.Column(db.Float, nullable=True) weight_unit_id = db.Column(db.Integer, db.ForeignKey("UnitIndex.id"), nullable=False) weight_unit = db.relationship("UnitModel", foreign_keys="SetPlanModel.weight_unit_id") # Lambda measures. These are for dynamically generated goals. Aka, 90% of 1 rep max, etc # Each lambda function can take a Float parameter and a Tracker parameter. duration_lambda_id = db.Column(db.Integer, db.ForeignKey("LambdaIndex.id"), nullable=True) duration_lambda = db.relationship( "LambdaModel", foreign_keys="SetPlanModel.duration_lambda_id") duration_lambda_param = db.Column(db.Float, nullable=True) duration_lambda_tracker_id = db.Column(db.Integer, db.ForeignKey("TrackerIndex.id"), nullable=True) duration_lambda_tracker_param = db.relationship( "TrackerModel", foreign_keys="SetPlanModel.duration_lambda_tracker_id") distance_lambda_id = db.Column(db.Integer, db.ForeignKey("LambdaIndex.id"), nullable=True) distance_lambda = db.relationship( "LambdaModel", foreign_keys="SetPlanModel.distance_lambda_id") distance_lambda_param = db.Column(db.Float, nullable=True) distance_lambda_tracker_id = db.Column(db.Integer, db.ForeignKey("TrackerIndex.id"), nullable=True) distance_lambda_tracker_param = db.relationship( "TrackerModel", foreign_keys="SetPlanModel.distance_lambda_tracker_id") weight_lambda_id = db.Column(db.Integer, db.ForeignKey("LambdaIndex.id"), nullable=True) weight_lambda = db.relationship( "LambdaModel", foreign_keys="SetPlanModel.weight_lambda_id") weight_lambda_param = db.Column(db.Float, nullable=True) weight_lambda_tracker_id = db.Column(db.Integer, db.ForeignKey("TrackerIndex.id"), nullable=True) weight_lambda_tracker_param = db.relationship( "TrackerModel", foreign_keys="SetPlanModel.weight_lambda_tracker_id") def get_weight(self): return 0 # TODO: Implement this, should return the weight either from value or lambda def get_duration(self): return 0 # TODO: Implement this, should return the weight either from value or lambda def get_distance(self): return 0 # TODO: Implement this, should return the weight either from value or lambda @staticmethod def has_owner(self): return True # Returns True is the given user id is considered the owner of this # tracker entry def check_owner(self, id): return self.workout.check_owner(id) def __str__(self): return "%u SetPlanModel: w%u, %u reps, %u(%s)" % ( self.id, self.workout_id, self.reps, self.exercise_id, self.exercise.name)
class SetEntryModel(db.Model): """These are sets that have been completed by users""" __tablename__ = "SetEntryIndex" id = db.Column(db.Integer, primary_key=True) # Time this set was done/entered time = db.Column(db.DateTime, nullable=False, default=datetime.now()) # Exercise performed for this Set exercise_id = db.Column(db.Integer, db.ForeignKey("ExerciseIndex.id"), nullable=False) exercise = db.relationship("ExerciseModel", foreign_keys="SetEntryModel.exercise_id") # Number of times this exercise was performed in this set reps = db.Column(db.Integer, nullable=False, default=1) # Duration that this exercise was done for (if it is measured in time) duration = db.Column(db.Float, nullable=True) duration_unit_id = db.Column(db.Integer, db.ForeignKey("UnitIndex.id"), nullable=False) duration_unit = db.relationship( "UnitModel", foreign_keys="SetEntryModel.duration_unit_id") # Distance that this exercise was done for (if it is measured in distance) distance = db.Column(db.Float, nullable=True) distance_unit_id = db.Column(db.Integer, db.ForeignKey("UnitIndex.id"), nullable=False) distance_unit = db.relationship( "UnitModel", foreign_keys="SetEntryModel.distance_unit_id") # Weight that this exercise was done with (if this uses weight) weight = db.Column(db.Float, nullable=True) weight_unit_id = db.Column(db.Integer, db.ForeignKey("UnitIndex.id"), nullable=False) weight_unit = db.relationship("UnitModel", foreign_keys="SetEntryModel.weight_unit_id") owner_id = db.Column(db.Integer, db.ForeignKey("UserIndex.id"), nullable=False) owner = db.relationship("UserModel", foreign_keys="SetEntryModel.owner_id", back_populates="set_entries") @staticmethod def has_owner(self): return True # Returns True is the given user id is considered the owner of this set # entry def check_owner(self, id): return self.owner_id == id def __str__(self): return "%u SetEntryModel: @%s o%u(%s) e%u(%s) r(%u)" % ( self.id, str(self.time), self.owner.id, self.owner.username, self.exercise_id, self.exercise.name, self.reps)
class PermissionModel(db.Model): __tablename__ = "PermissionIndex" id = db.Column(db.Integer, primary_key=True) # Action that is permitted. (Ex: tracker.entry.new) action = db.Column(db.String(100), nullable=False) # Allow all users with this role to perform this action. (Ex: admin) allow_role = db.Column(db.String(20), nullable=True) # Allow the given user ID to perform this action. allow_user = db.Column(db.Integer, db.ForeignKey( "UserIndex.id"), nullable=True) # If set to true, the perms will check to make sure that the action is being performed by the user that owns the given database row entry # Ownership is tracked by the "owner" property allow_owner = db.Column(db.Boolean, nullable=True) # If set to true, the perms will check to make sure that the action being performed is on a row that has is_public set to True # Example: Some Recipes can be public for everyone to view, others are # private check_public = db.Column(db.Boolean, nullable=True) # If set to true, this action can be performed by ANY client. # Example: Viewing the list of units # Usually just used for view actions force_public = db.Column(db.Boolean, nullable=True) # For debugging and CLI purposes def __str__(self): return "Perm ID %5i: %25s - r(%s), u(%s), o(%s), cp(%s), fp(%s)" % (int(self.id), str(self.action), str(self.allow_role), str(self.allow_user), str(self.allow_owner), str(self.check_public), str(self.force_public)) # Validation process: # Get all rows with the target action # For each row: If user fits into 1 row, then return True # If user does not fit into any rows, return False # Parameters: user - the UserModel of the user that is performing the action # model - the SQLAlchemyModel of what is being modified def check_user(self, user, model): if self.force_public is not None: return self.force_public if user: # If the client is not logged in, then it's ok to pass False instead of a UserModel if self.allow_user is not None: if self.allow_user == user.id: return True if self.allow_role is not None: if self.allow_role == user.role: return True if self.allow_owner is not None: # If the model is able to have an owner, then check if the owner matches the current user id if model: # If the model has not been loaded yet then we cannot check for an owner if model.has_owner() and model.check_owner(user.id): return True else: logging.warning("Attempted to check ownership of a model for perms rule " + str(self)) # TODO: Make a log somewhere to notify dev that we attempted to # check owner of a None model if self.check_public is not None: if model: # If the model has not been loaded yet then we cannot check for an owner if model.is_public: return True # TODO: Make a log somewhere to notify dev that we attempted to # check owner of a None model return False