def authenticate(cls, user_name, password): user = User.query.filter(db.or_(User.user_name == user_name)).first() if user: authenticated = user.check_password(password) else: authenticated = False return user, authenticated
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
def find_is_closed(campus: Campus, day: datetime.date) -> 'Optional[ClosingDays]': return ClosingDays.query.filter(db.and_(ClosingDays.campus_id == campus.id, ClosingDays.first_day <= day, db.or_( ClosingDays.last_day == None, ClosingDays.last_day >= day ) )).first()
def sendSMS(): '''批量发送短信处理''' print 'start to send sms', SMS = models.SMS _all_sms = SMS.query.filter(db.or_(SMS.status==1, db.and_(SMS.status==9,SMS.fail_times<=3))) for sms in _all_sms: print '%d|%d'%(sms.seqid,int(sms.send_sms())) print 'complete.'
def sendSMS(): '''批量发送短信处理''' print 'start to send sms', SMS = models.SMS _all_sms = SMS.query.filter( db.or_(SMS.status == 1, db.and_(SMS.status == 9, SMS.fail_times <= 3))) for sms in _all_sms: print '%d|%d' % (sms.seqid, int(sms.send_sms())) print 'complete.'
def authenticate(cls, login, password): user = cls.query.filter(db.or_(User.name == login, User.email == login)).first() if user: authenticated = user.check_password(password) else: authenticated = False return user, authenticated
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
def authenticate(self, login, password): current_app.logger.info(login, password) user = self.filter(db.or_(User.username == login, User.email == login)).first() if user: current_app.logger.info(user) authenticated = user.check_password(password) else: authenticated = False return user, authenticated
def find_closing_days_including(campus: Campus, start_date: datetime.date, end_date: datetime.date) -> 'List[ClosingDays]': return ClosingDays.query.filter(db.and_(ClosingDays.campus_id == campus.id, ClosingDays.first_day <= end_date, db.or_( ClosingDays.last_day == None, ClosingDays.last_day >= start_date ) )).all()
def search(cls, keywords): criteria = [] for keyword in keywords.split(): keyword = '%' + keyword + '%' criteria.append(db.or_( User.name.ilike(keyword), User.email.ilike(keyword), )) q = reduce(db.and_, criteria) return cls.query.filter(q)
def authenticate(self, username, password): member = self.filter( db.or_(Member.username==username)).first() # print '<>'*80,dir(member) if member: authenticated = (member.password == password) else: authenticated = False return member, authenticated
def search(cls, keywords): criteria = [] for keyword in keywords.split(): keyword = '%' + keyword + '%' criteria.append( db.or_( User.name.ilike(keyword), User.email.ilike(keyword), )) q = reduce(db.and_, criteria) return cls.query.filter(q)
def authenticate(self, login, password): current_app.logger.info(login) user = self.filter( db.or_( User.username == login, User.email == login, User.mobile == login, )).first() if user: current_app.logger.info(user) am = Auth_Manager() authenticated = am.username_auth(user.uid, password) else: authenticated = False return user, authenticated
def get_heartbeat(self, page, type_id, agent_status=None): query = db.session.query(CI.ci_id, CI.heartbeat) expire = datetime.datetime.now() - datetime.timedelta(minutes=72) if type_id: query = query.filter(CI.type_id == type_id) else: query = query.filter(db.or_(CI.type_id == 7, CI.type_id == 8)) if agent_status == -1: query = query.filter(CI.heartbeat == None) elif agent_status == 0: query = query.filter(CI.heartbeat <= expire) elif agent_status == 1: query = query.filter(CI.heartbeat > expire) numfound = query.count() per_page_count = current_app.config.get("DEFAULT_PAGE_COUNT") cis = query.offset( (page - 1) * per_page_count).limit(per_page_count).all() ci_ids = [ci.ci_id for ci in cis] heartbeat_dict = {} for ci in cis: if agent_status is not None: heartbeat_dict[ci.ci_id] = agent_status else: if ci.heartbeat is None: heartbeat_dict[ci.ci_id] = -1 elif ci.heartbeat <= expire: heartbeat_dict[ci.ci_id] = 0 else: heartbeat_dict[ci.ci_id] = 1 current_app.logger.debug(heartbeat_dict) ci_ids = map(str, ci_ids) res = get_cis_by_ids(ci_ids, fields=["hostname", "private_ip"]) result = [(i.get("hostname"), i.get("private_ip")[0], i.get("ci_type"), heartbeat_dict.get(i.get("_id"))) for i in res if i.get("private_ip")] return numfound, result
def ads_list(page=1, ads_per_page=15): oblast_district = request.args.get('oblast_district') new_building = request.args.get('new_building') min_price = request.args.get('min_price') max_price = request.args.get('max_price') ads = Advert.query.filter(Advert.active == True) if oblast_district: ads = ads.filter(Advert.oblast_district == oblast_district) if new_building: ads = ads.filter( db.or_(Advert.under_construction == True, Advert.construction_year >= datetime.date.today().year - 2)) if ispositive_int(max_price): ads = ads.filter(Advert.price <= int(max_price)) if ispositive_int(min_price): ads = ads.filter(Advert.price >= int(min_price)) return render_template( 'ads_list.html', ads=ads.order_by(Advert.price.asc()).paginate(page, ads_per_page), oblast_district=oblast_district, new_building=new_building, min_price=min_price, max_price=max_price, )
def getdmuser(): html = StringIO() url = r'%sgetuser'%DMURL print datetime.now() print url c = pycurl.Curl() c.setopt(pycurl.URL, url) c.setopt(pycurl.SSL_VERIFYHOST, False) c.setopt(pycurl.SSL_VERIFYPEER, False) c.setopt(pycurl.WRITEFUNCTION, html.write) c.setopt(pycurl.FOLLOWLOCATION, 1) c.perform() ll = str(html.getvalue()) users = json.loads(ll) for u in users: user = User() p = User_Phone.query.filter(db.or_(User_Phone.phone == u['phone'],User_Phone.phone == u['phone2'])).first() purchases = u['name']+u'于'+u['gmdate']+u' 在 '+u['gmaddress']+u' 购买了大盒'+str(u['gmbigcount'])+u'盒,小盒'+str(u['gmsmallcount'])+u'盒,备注:'+u['remark']+u',电话:'+u['phone']+','+u['phone2']+u',年龄:'+str(u['ages'])+u',性别:'+u['gender']+u',区域:'+u['area'] if p: pass#如果存在,不处理20141224 # user = User.query.get_or_404(p.user_id) # user.operator_id = 1 # user.origin = int(u['origin']) # user.user_type = 5#服务客户 # #user.assign_operator_id = 1 # user.purchases = str(user.purchases)+purchases # user.qxhdm_user_id = u['id'] # user.area = u['area'] # user.pharmacy = u['pharmacy'] # user.promoters = u['promoters'] # user.pharmacystores = u['pharmacystores'] # # user.qxhdm_time = datetime.now().strftime('%Y-%m-%d') # db.session.add(user) # # #分配记录 # assign_log = User_Assign_Log() # assign_log.user_id = user.user_id # assign_log.assign_operator_id = None # assign_log.operator_id = 1 # assign_log.user_type = user.user_type # db.session.add(assign_log) else: user.operator_id = 1 user.origin = int(u['origin']) user.user_type = 5#服务客户 #user.assign_operator_id = 1 user.name = u['name'] user.phone = u['phone'] user.phone2 = u['phone2'] user.gender = u['gender'] user.ages = u['ages'] user.is_new = u['is_new'] user.disease = u['disease'] user.fugou = u['fugou'] user.remark = u['remark'] user.area = u['area'] user.pharmacy = u['pharmacy'] user.promoters = u['promoters'] user.pharmacystores = u['pharmacystores'] user.purchases = purchases user.qxhdm_user_id = u['id'] user.qxhdm_time = datetime.now().strftime('%Y-%m-%d') db.session.add(user) db.session.flush() #分配记录 assign_log = User_Assign_Log() assign_log.user_id = user.user_id assign_log.assign_operator_id = None assign_log.operator_id = 1 assign_log.user_type = user.user_type db.session.add(assign_log) db.session.add(User_Phone.add_phone(user.user_id,user.phone)) if user.phone2: db.session.add(User_Phone.add_phone(user.user_id,user.phone2)) url = r'%supdateuser?id=%s&user_id=%s'%(DMURL,u['id'],user.user_id) print url c = pycurl.Curl() c.setopt(pycurl.URL, url) c.setopt(pycurl.SSL_VERIFYHOST, False) c.setopt(pycurl.SSL_VERIFYPEER, False) c.setopt(pycurl.WRITEFUNCTION, html.write) c.setopt(pycurl.FOLLOWLOCATION, 1) c.perform() db.session.commit()
import sys import inspect currentdir = os.path.dirname(os.path.abspath(inspect.getfile(inspect.currentframe()))) parentdir = os.path.dirname(currentdir) sys.path.insert(0, parentdir) from crabber import app from extensions import db from models import ( Card, ) from sqlalchemy import desc, func, or_ from sqlalchemy.sql import expression app.app_context().push() blanks = Card.query.filter_by(ready=True, failed=False).filter( db.or_( Card.title == expression.null(), Card.title.like("404 %"), Card.title.like("403 %"), Card.title.like("500 %"), ) ) print(f"Found {blanks.count()} blank cards.") blanks.update({"ready": False, "failed": True}, synchronize_session=False) db.session.commit() print("Removed.")
def search(self, key): query = self.filter( db.or_(User.email == key, User.nickname.ilike('%' + key + '%'), User.username.ilike('%' + key + '%'))) return query