def search(self, keywords): criteria = [] for keyword in keywords.split(): keyword = "%" + keyword + "%" criteria.append(db.or_(Group.name.ilike(keyword))) q = reduce(db.and_, criteria) return self.filter(q).order_by(Group.num_members.desc())
def search(self, keywords): criteria = [] for keyword in keywords.split(): keyword = "%" + keyword + "%" criteria.append(db.or_(Group_Topic.title.ilike(keyword), Group_Topic.description.ilike(keyword))) q = reduce(db.and_, criteria) return self.filter(q).order_by(Group_Topic.num_comment.desc())
def search(self, keywords): criteria = [] for keyword in keywords.split(): keyword = "%" + keyword + "%" criteria.append(db.or_(Question.title.ilike(keyword), Question.description.ilike(keyword))) q = reduce(db.and_, criteria) return self.filter(q).order_by(Question.votes.desc(), Question.id.desc())
def tags_search(self, keywords): criteria = [] for keyword in keywords.split(): keyword = "%" + keyword + "%" criteria.append(db.or_(Tag.slug.ilike(keyword), Tag.description.ilike(keyword))) q = reduce(db.and_, criteria) return self.filter(q).distinct()
def authenticate(self, login, password): user = self.filter(db.or_(User.username==login, User.email==login)).first() if user: authenticated = user.check_password(password) else: authenticated = False return user, authenticated