Exemple #1
0
 def get_all_acricles_bytree(cls, whereitem, wherestr):
     '''抓取sidebar目录,全部'''
     if whereitem == 'link_project':
         return [{
             "project_name":
             project.name,
             "link_articles":
             [article.json() for article in project.articles]
         } for project in ProjectModel.query.filter_by(id=wherestr).all()]
     elif whereitem == 'link_date':
         return [{
             "project_name":
             project.name,
             "link_articles": [
                 article.json() for article in project.articles.filter(
                     db.and_(
                         db.extract('month', ArticleModel.create_time) ==
                         wherestr[5:7],
                         db.extract('year', ArticleModel.create_time) ==
                         wherestr[:4])).all()
             ]
         } for project in ProjectModel.query.all()]
     else:
         print(whereitem)
         return [{
             "project_name":
             project.name,
             "link_articles": [
                 article.json() for article in project.articles.filter(
                     db.or_(
                         ArticleModel.topic.like('%' + wherestr + '%'),
                         ArticleModel.introduce.like('%' + wherestr +
                                                     '%'))).all()
             ]
         } for project in ProjectModel.query.all()]
Exemple #2
0
 def search(latitude, longitude):
     query = Toilet.query
     latitude_min = latitude - 0.25
     latitude_max = latitude + 0.25
     if latitude_min < -90:
         latitude_min += 180
         query = query.filter(db.or_(Toilet.lat >= latitude_min, Toilet.lat <= latitude_max))
     elif latitude_max > 90:
         latitude_max -= 180
         query = query.filter(db.or_(Toilet.lat >= latitude_min, Toilet.lat <= latitude_max))
     else:
         query = query.filter(Toilet.lat >= latitude_min, Toilet.lat <= latitude_max)
     longitude_min = longitude - 0.5
     longitude_max = longitude + 0.5
     if longitude_min < -180:
         longitude_min += 360
         query = query.filter(db.or_(Toilet.lng >= longitude_min, Toilet.lng <= longitude_max))
     elif longitude_max > 180:
         longitude_max -= 360
         query = query.filter(db.or_(Toilet.lng >= longitude_min, Toilet.lng <= longitude_max))
     else:
         query = query.filter(Toilet.lng >= longitude_min, Toilet.lng <= longitude_max)
     return query
Exemple #3
0
 def authenticate(username, passwd):
     user = User.query.filter(db.or_(User.login == username,
                                      User.email == username)).first()
     authenticated = user.check_passwd(passwd) if user else False
     print 'authenticate().user', user, passwd
     return user, authenticated
Exemple #4
0
 def country_id_from_name_or_code(cls, name_or_code):
     country_row = cls.query.filter(
         db.or_(Country.name == name_or_code,
                Country.code == name_or_code)).first()
     return country_row.id if country_row else None