def check_access(circle, member_required=False): """To see a circle, you must have a member or an invitation""" member = db.session.query(Member).filter(db.and_(Member.circle == circle, Member.user == g.user)).first() if member: return member elif member_required: abort(404) else: if str(circle.id) in g.invitations: return None else: abort(404)
def invitations_for_circle(circle, member): return db.session.query(Invitation).filter(db.and_(Invitation.inviter == member, Invitation.circle == circle))
def private_discussions_with(self, member): return db.session.query(PrivateDiscussion).filter(db.or_( db.and_(PrivateDiscussion.member1 == self, PrivateDiscussion.member2 == member), db.and_(PrivateDiscussion.member1 == member, PrivateDiscussion.member2 == self)) ).order_by(PrivateDiscussion.last_bumped.desc())
def find(self, circle, user=None): if not user: user = g.user return db.session.query(Member).filter( db.and_(Member.user == g.user, Member.circle == circle)).first()