Exemple #1
0
def addAlumni():
    pass
    ret = checkAuth()
    if ret != None:
        return ret
    mysqlSession = mysql.session
    form = AlumniForm(lst=mysqlSession.query(School).all())
    error = None
    if form.validate_on_submit():
        alumni = Alumni()
        alumni.name = request.form['name']
        alumni.graduate = request.form['graduate']
        alumni.email = request.form['email']
        alumni.tel = request.form['tel']
        alumni.email = request.form['email']
        alumni.remark = request.form['remark']
        alumni.industry = request.form['industry']
        alumni.manager = request.form['manager']
        try:
            mysqlSession.add(alumni)
            mysqlSession.commit()
        except sqlalchemy.exc.IntegrityError, e:
            mysqlSession.rollback()
            return bad_request(e)
        except Exception, e:
            mysqlSession.rollback()
            return bad_request(e)
Exemple #2
0
def updAlumni():
    pass
    ret = checkAuth()
    if ret != None:
        return ret
    alumni_id = request.args.get('alumni_id')
    if alumni_id == None:
        return bad_request(None, 'alumni_id is None')
    mysqlSession = mysql.session
    form = AlumniForm(lst=mysqlSession.query(School).all())
    alumni = mysqlSession.query(Alumni).filter(Alumni.alumni_id == alumni_id).first()
    error = None
    if form.validate_on_submit():
        alumni.name = request.form['name']
        alumni.graduate = request.form['graduate']
        alumni.email = request.form['email']
        alumni.tel = request.form['tel']
        alumni.email = request.form['email']
        alumni.remark = request.form['remark']
        alumni.industry = request.form['industry']
        alumni.manager = request.form['manager']
        try:
            mysqlSession.add(alumni)
            mysqlSession.commit()
            return execSuccess('修改成功')
        except sqlalchemy.exc.IntegrityError, e:
            mysqlSession.rollback()
            return bad_request(e)
        except Exception, e:
            mysqlSession.rollback()
            return bad_request(e)
Exemple #3
0
def updSchool():
    pass
    ret = checkAuth()
    if ret != None:
        return ret
    sch_id = request.args.get('sch_id')
    if sch_id == None:
        return bad_request(None, 'sch_id is None')
    mysqlSession = mysql.session
    school = mysqlSession.query(School).filter(School.sch_id == sch_id).first()
    form = SchoolForm()
    if form.validate_on_submit():
        pass
        school.full_name = request.form['full_name']
        school.en_name = request.form['en_name']
        school.nick_list = request.form['nick_list']
        school.tel = request.form['tel']
        school.email = request.form['email']
        school.push_url = request.form['push_url']
        try:
            mysqlSession.add(school)
            mysqlSession.commit()
            return execSuccess('修改成功')
        except sqlalchemy.exc.IntegrityError, e:
            mysqlSession.rollback()
            return bad_request(e)
        except Exception, e:
            mysqlSession.rollback()
            return bad_request(e)
Exemple #4
0
def checkAuth(isAdmin=True):
    pass
    if isAdmin ==False:
        if BINGONE__WEB__USER__KEY not in session:
            return bad_request('请先登录')
        else:
            return
    if (BINGONE__WEB__ADMIN__KEY not in session) or session[BINGONE__WEB__ADMIN__KEY] != True:
        return bad_request(None, 'No Auth')
Exemple #5
0
def login():
    pass
    form = LoginForm()
    if(BINGONE__WEB__USER__KEY in session):
        flash('您已登陆')
        return index()
    if request.method == 'POST':
        # if(form.register.data == True):
        #     flash('欢迎注册校友订阅系统')
        #     return render_template('common/form.html',form=RegisterForm(),)
        if form.validate_on_submit():
            username = form.username.data
            password = form.password.data
            user = DAO.getUser(User.username == username)
            if user != None and user.verify_password(password):
                session[BINGONE__WEB__USER__KEY] = user.username
                session[BINGONE__WEB__USERID__KEY] = user.user_id
                userCache.put(user.username,user.user_id)
                session.permanent = False
                if username == ADMIN.username and ADMIN.verify_password(password):
                    session[BINGONE__WEB__ADMIN__KEY] = True
                return execSuccess('login success')
            return bad_request(msg='login failed')
    flash('欢迎登陆校友订阅系统')
    return defaultRender('common/form.html', form=form,register=True)
Exemple #6
0
def register():
    pass
    form = UserForm()
    if request.method == 'POST':
        if form.validate_on_submit():
            user=User()
            user.username = form.username.data
            M = hashlib.md5()
            M.update(form.password.data)
            user.password = unicode(M.hexdigest())
            user.callback_url = form.callback_url.data
            user.email = form.email.data
            user.last_seen=datetime.datetime.now()
            user.role = 1
            user.user_tag = 0
            if form.is_pushUrl.data == True:
                user.set_pushUrl()
            if form.is_sendEmail.data == True:
                user.set_sendEmail()
            dbUser = DAO.getUser(User.username == user.username)
            if dbUser != None:
                return bad_request(msg='register failed,because the userName has exist!')
            DAO.addUser(user)
            dbUser = DAO.getUser(User.username == form.username.data)
            session[BINGONE__WEB__USER__KEY] = form.username.data
            session[BINGONE__WEB__USERID__KEY] = dbUser.user_id
            userCache.put(dbUser.username,dbUser.user_id)
            session.permanent = False
            return execSuccess('login success')
    flash('欢迎注册校友订阅系统')
    return defaultRender('user/add_user.html', form=form)
def getCrawlerRecord():
    pass
    page = int(request.args.get('page', '1'))
    if page <= 0:
        return bad_request(None, 'wrong page num')
    sch_id = request.args.get('sch_id')
    alumni_id = request.args.get('alumni_id')
    start_day = request.args.get('start_day')
    end_day = request.args.get('end_day')
    schoolName = None
    mysqlSession = mysql.session
    query = mysqlSession.query(CrawlerRecord)
    # retList = query.all()
    if sch_id != None and sch_id!='':
        query = query.filter(CrawlerRecord.sch_id == sch_id)
        schoolName = mysqlSession.query(School).filter(School.sch_id == sch_id).first().full_name
    if alumni_id != None and alumni_id!='':
        query = query.filter(CrawlerRecord.alumni_id == alumni_id)
    if start_day != None and end_day != None:
        pass
        try:
            start_time = datetime.datetime.strptime(start_day,'%Y-%m-%d')
            end_time = datetime.datetime.strptime(end_day, '%Y-%m-%d')
            start_time = start_day.encode('utf8')
            end_time = end_day.encode('utf8')
            query = query.filter((CrawlerRecord.gmt_created >= start_time),(CrawlerRecord.gmt_created <= end_time))
            # query = query.filter((CrawlerRecord.gmt_created <= end_time))
        except Exception, e:
            logger.error('start_day or end_day is wrong format')
Exemple #8
0
def delAlumni():
    pass
    ret = checkAuth()
    if ret != None:
        return ret
    alumni_id = request.args.get('alumni_id')
    if alumni_id == None:
        return bad_request(None, 'alumni_id is None')
    mysqlSession = mysql.session
    try:
        ret = mysqlSession.query(Alumni).filter(Alumni.alumni_id == alumni_id).delete()
        mysqlSession.commit()
        if ret > 0:
            return execSuccess('del Alumni')
        elif ret == 0:
            return bad_request(None, 'Alumni is wrong ')
    except sqlalchemy.exc.IntegrityError, e:
        mysqlSession.rollback()
        return bad_request(e)
def delCrawlerRecord():
    pass
    ret = checkAuth()
    if ret != None:
        return ret
    crawler_id = request.args.get('crawler_id')
    if crawler_id == None:
        return bad_request(None, 'crawler_id is None')
    mysqlSession = mysql.session
    try:
        ret = mysqlSession.query(School).filter(CrawlerRecord.crawler_id == crawler_id).delete()
        mysqlSession.commit()
        if ret > 0:
            return execSuccess('del crawler_record')
        elif ret == 0:
            return bad_request(None, 'crawler_id is wrong ')
    except sqlalchemy.exc.IntegrityError, e:
        mysqlSession.rollback()
        return bad_request(e)
Exemple #10
0
def delSchool():
    pass
    ret = checkAuth()
    if ret != None:
        return ret
    sch_id = request.args.get('sch_id')
    if sch_id == None:
        return bad_request(None, 'sch_id is None')
    mysqlSession = mysql.session
    try:
        ret = mysqlSession.query(School).filter(School.sch_id == sch_id).first()
        mysqlSession.delete(ret)
        mysqlSession.commit()
        if ret > 0:
            return execSuccess('del school')
        elif ret == 0:
            return bad_request(None, 'sch_id is wrong ')
    except sqlalchemy.exc.IntegrityError, e:
        mysqlSession.rollback()
        return bad_request(e)
Exemple #11
0
 def delSchool(self,condition):
     mysqlSession = self.mysql.session
     ret = mysqlSession.query(School).filter(condition).all()
     if ret <= 0:
         mysqlSession.close()
         return False
     try:
         ret = mysqlSession.delete(ret)
     except sqlalchemy.exc.IntegrityError, e:
         mysqlSession.rollback()
         return bad_request(e)
Exemple #12
0
def addSchool():
    pass
    ret = checkAuth()
    if ret != None:
        return ret
    form = SchoolForm()
    if form.validate_on_submit():
        school = School()
        school.full_name = request.form['full_name']
        school.en_name = request.form['en_name']
        school.nick_list = request.form['nick_list']
        school.tel = request.form['tel']
        school.email = request.form['email']
        school.push_url = request.form['push_url']
        mysqlSession = mysql.session
        try:
            mysqlSession.add(school)
            mysqlSession.commit()
        except sqlalchemy.exc.IntegrityError, e:
            mysqlSession.rollback()
            return bad_request(e)
        except Exception, e:
            mysqlSession.rollback()
            return bad_request(e)
Exemple #13
0
def getChartAlumniJson():
    pass
    # ret = checkAuth(False)
    # if ret != None:
    #     return ret
    # if request.method =='POST':
    input_time = request.form.get("input_time")
    alumni_id = request.form.get("alumni_id")
    if alumni_id == None:
        return bad_request("请选择校友")
    mysqlSession = mysql.session
    query = mysqlSession.query(CrawlerRecord)
    query = query.filter(CrawlerRecord.alumni_id == alumni_id)
    alumniName = mysqlSession.query(Alumni).filter(Alumni.alumni_id == alumni_id).first().name
    try:
        end_time = datetime.datetime.strptime(input_time, "%Y-%m-%d")
        start_time = (end_time - datetime.timedelta(days=6)).strftime("%Y-%m-%d")
        query = query.filter((CrawlerRecord.gmt_created >= start_time), (CrawlerRecord.gmt_created <= end_time))
    except Exception, e:
        logger.error("start_day or end_day is wrong format.e=" + e.message)
Exemple #14
0



@app.route('/alumni/del', methods=['GET', 'POST'])
def delAlumni():
    pass
    ret = checkAuth()
    if ret != None:
        return ret
    alumni_id = request.args.get('alumni_id')
    if alumni_id == None:
        return bad_request(None, 'alumni_id is None')
    mysqlSession = mysql.session
    try:
        ret = mysqlSession.query(Alumni).filter(Alumni.alumni_id == alumni_id).delete()
        mysqlSession.commit()
        if ret > 0:
            return execSuccess('del Alumni')
        elif ret == 0:
            return bad_request(None, 'Alumni is wrong ')
    except sqlalchemy.exc.IntegrityError, e:
        mysqlSession.rollback()
        return bad_request(e)
    except Exception, e:
        mysqlSession.rollback()
        return bad_request(e)
    finally:
        mysqlSession.close()
        # mysqlSession = mysqlSession()
Exemple #15
0
 def wrapper(*args,**kwargs):
     if (BINGONE__WEB__ADMIN__KEY not in session) or session[BINGONE__WEB__ADMIN__KEY] != True:
         return bad_request(None, 'No Auth')
     return func(*args,**kwargs)