Example #1
0
    def find_url_or_404(cls, url: str):
        """
        Method looks up for objects with given url
        In case of multiple matches, returns the newest one
        Raises 404 error if it doesn't exist

        Args:
            url (str): URL to look for

        Returns:
            BasePage: found object if exists
        """

        return (cls.query.filter_by(url=url).order_by(db.desc(
            cls.created_at)).first_or_404())
Example #2
0
    def get(cls, user_id: int):
        """Return confirmation for a given user. For testing only"""
        user = UserModel.find_by_id(user_id)

        if not user:
            return {'message': 'user not found'}, 404

        return {
            "current time":
            int(time()),
            "Confirmations": [
                confirmationSchema.dump(each)
                for each in user.confirmation.order_by(
                    db.desc(ConfirmationModel.expire_at))
            ]
        }
Example #3
0
 def most_recent_confirmation(self):
     return self.confirmation.order_by(db.desc(
         ConfirmationModel.expire_at)).first()
Example #4
0
 def find_by_name_order_by_date(cls, city_name):
     return cls.query.filter_by(city=city_name).order_by(
         db.desc(WeatherModel.date)).limit(5).all()
Example #5
0
 def most_recent_reservation(self) -> "ReservationModel":
     # ordered by expiration time (in descending order)
     return self.confirmation.order_by(db.desc(
         ReservationModel.expire_at)).first()
Example #6
0
 def get_my_last_request(cls, deviceId, userId):
     return cls.query.filter((cls.deviceId == deviceId)
                             & (cls.userId == userId)).order_by(
                                 db.desc(cls.reqId)).first()
Example #7
0
 def most_recent_confirmation(self) -> "ConfirmationModel":
     """get most recent confirmation that belongs to the user"""
     return self.confirmation.order_by(db.desc(
         ConfirmationModel.expire_at)).first()
Example #8
0
 def most_recent_reset(self) -> "ResetTokenModel":
     return self.reset_token.order_by(db.desc(
         ResetTokenModel.expire_at)).first()
Example #9
0
 def last_confirmation(self) -> 'ConfirmationModel':
     # self.confirmation is alreay a query object because of lazy='dynamic'
     return self.confirmation.order_by(db.desc(
         ConfirmationModel.expires_at)).first()
Example #10
0
 def find_last_confirmation(self) -> "ConfirmationModel":
     return self.confirmation.order_by(db.desc(ConfirmationModel.expire_at)).first()
Example #11
0
 def find_my_device(cls, deviceId, userId):
     return cls.query.filter((cls.deviceId==deviceId)&(cls.userId==userId)).order_by(db.desc(cls.id)).first()
Example #12
0
 def most_recent_confirmation(
     self
 ) -> "ConfirmationModel":  #if a user has multiple confirmation, this will pick the most recent confirmation
     # it goes to the above confirmation variable and then ordered by expiration time (in descending order)
     return self.confirmation.order_by(db.desc(
         ConfirmationModel.expire_at)).first()