def get(identifier): """Return the paste for an identifier. Private pastes must be loaded with their unique hash and public with the paste id. """ if isinstance(identifier, basestring) and not identifier.isdigit(): return Paste.query.filter(Paste.private_id == identifier).first() return Paste.query.filter( db.and_(Paste.paste_id == int(identifier), Paste.private_id == None)).first()
def get(identifier): """Return the paste for an identifier. Private pastes must be loaded with their unique hash and public with the paste id. """ if isinstance(identifier, basestring) and not identifier.isdigit(): return Paste.query.filter(Paste.private_id == identifier).first() return Paste.query.filter(db.and_( Paste.paste_id == int(identifier), Paste.private_id == None)).first()
def _set_private(self, value): if not value: self.private_id = None return if self.private_id is None: while 1: self.private_id = generate_paste_hash() paste = Paste.query.filter(db.and_(Paste.private_id == self.private_id, Paste.paste_id != self.paste_id)) \ .first() if paste is None: break
def fetch_replies(): """Get the new replies for the ower of a request and flag them as handled. """ #XXX:dc:clean this query up to just return the ids ids = [x.paste_id for x in Paste.query.filter_by( user_hash=local.request.user_hash).all()] paste_list = Paste.query.filter(db.and_( Paste.parent_id.in_(ids), Paste.handled == False, )).order_by(Paste.paste_id.desc()).all() for paste in paste_list: paste.handled = True db.session.commit() return paste_list
def fetch_replies(): """Get the new replies for the ower of a request and flag them as handled. """ # TODO(dc): clean this query up to just return the ids ids = [x.paste_id for x in Paste.query.filter_by( user_hash=local.request.user_hash).all()] paste_list = Paste.query.filter(db.and_( Paste.parent_id.in_(ids), Paste.handled is False, )).order_by(Paste.paste_id.desc()).all() for paste in paste_list: paste.handled = True db.session.commit() return paste_list
def fetch_replies(): """Get the new replies for the ower of a request and flag them as handled. """ ids = db.session.query(Paste.paste_id) \ .filter(Paste.user_hash == local.request.user_hash) paste_list = db.session.query(Paste.paste_id).filter(db.and_( Paste.parent_id.in_(ids), Paste.handled == False, Paste.user_hash != local.request.user_hash, )).order_by(Paste.paste_id.desc()).all() to_mark = [p.paste_id for p in paste_list] if to_mark: Paste.query.filter(Paste.paste_id.in_(to_mark)) \ .update(values={'handled': True}) db.session.commit() return paste_list
def fetch_replies(): """Get the new replies for the ower of a request and flag them as handled. """ ids = db.session.query(Paste.paste_id) \ .filter(Paste.user_hash == local.request.user_hash) paste_list = db.session.query(Paste).filter(db.and_( Paste.parent_id.in_(ids), Paste.handled == False, Paste.user_hash != local.request.user_hash, )).order_by(Paste.paste_id.desc()).all() to_mark = [p.paste_id for p in paste_list] if to_mark: Paste.query.filter(Paste.paste_id.in_(to_mark)) \ .update(values={'handled': True}, synchronize_session='fetch') db.session.commit() return paste_list