def add(cls, db, session_id, user_id, expires_at): sess = cls(session_id=session_id, user_id=user_id, expires_at=expires_at) db.add(sess) commit(db) return sess
def reset(cls, db, receiver_id, station_id=None, sender_id=None, count=0): unread = cls.get(db, receiver_id, station_id, sender_id) if unread is None: return Unread() unread.count = count commit(db) return unread
def add(cls, db, user_id, username, email, password): user = cls(user_id=user_id, username=username, password=password, email=email) db.add(user) commit(db) return user
def add(cls, db, message_id, receiver_id, sender_id, text, image_key, sent_at): message = StationChat(message_id=message_id, receiver_id=receiver_id, sender_id=sender_id, text=text, image_key=image_key, sent_at=sent_at) db.add(message) commit(db) return message
def subscribe(cls, db, user_id, endpoint, auth, p256dh): subscriber = cls.query_by_device_browser(db, endpoint, auth, p256dh) if subscriber is None: subscriber = PushNotification(user_id=user_id, endpoint=endpoint, auth=auth, p256dh=p256dh) db.add(subscriber) else: # Update new user to use this device_browser subscriber.user_id = user_id commit(db) return subscriber
def add(cls, db, receiver_id, station_id=None, sender_id=None): if station_id is None and sender_id is None: return None unread = cls.get(db, receiver_id, station_id, sender_id) if unread is None: unread = Unread(receiver_id=receiver_id, station_id=station_id, sender_id=sender_id, count=0) db.add(unread) unread.count += 1 commit(db) return unread
def ensure_stations(self, wide=45): """ Add 9 stations across -wide +wide in x and y axis * * * * * * * * * """ # Drop database to ensure these are only stations db = inject.instance('db') sbs = db.query(Subscriber).all() ss = db.query(Station).all() scs = db.query(StationChat).all() unreads = db.query(Unread).all() for unread in unreads: db.delete(unread) commit(db) for sc in scs: db.delete(sc) commit(db) for sb in sbs: db.delete(sb) commit(db) for s in ss: db.delete(s) commit(db) stations = [ self.add_station(-wide, wide), self.add_station(0, wide), self.add_station(wide, wide), self.add_station(-wide, 0), self.add_station(0, 0), self.add_station(wide, 0), self.add_station(-wide, -wide), self.add_station(0, -wide), self.add_station(wide, -wide), ] return stations
def unsubscribe(cls, db, subscriber): db.delete(subscriber) commit(db) return subscriber
def add(cls, db, station_id, lat, lon): station = cls(station_id=station_id, _latitude=lat, _longitude=lon) db.add(station) commit(db) return station
def add(cls, db, station_id, user_id): subscriber = cls(station_id=station_id, user_id=user_id) db.add(subscriber) commit(db) return subscriber
def delete(cls, db, session): db.delete(session) commit(db) return session
def update_expiring(cls, db, session, expires_at): session.expires_at = expires_at commit(db) return session
def update_avatar(cls, db, user, avatar_key): user.avatar_key = avatar_key commit(db) return user