Exemplo n.º 1
0
    def get(self):
        if isStudent(self):
            self.finish(success=False,notification='权限不足,无法修改数据')
            return

        idc = self.get_argument('idc','')
        name = self.get_argument('name','')

        stu = Student.instance()

        if name == '' :
            stu.logger.warning('request param name is empty')
            self.finish(success=False)
            return
        if idc == '' :
            stu.logger.warning('request param idc is empty')
            self.finish(success=False)
            return
        sid = stu.getStuIdOnName(name)
        ret = self.searchAndDelRI(sid,idc)
        if ret == 0 :
            stu.logger.info('Delete reward info done')
            self.finish(success=True)
            return

        self.finish(success=False)
        return
Exemplo n.º 2
0
    def get(self):
        stu = Student.instance()
        try:
            cname = self.get_argument('class','').strip()
            bdate = self.get_argument('begin','').strip()
            edate = self.get_argument('end','').strip()
            name = self.get_argument('name','').strip()

            #rinfos = stu.getAllRewardInfo()
            ris = []
            if name != '':
                sid = stu.getStuIdOnName(name)
                if sid != '':
                    ris = stu.getRewardInfo2(sid)
            else:
                ris = stu.getAllRewardInfo2()

            stu.logger.info(ris)
            ris = self.filterRewardInfoBetween(ris,bdate,edate)
            stu.logger.info(ris)
            if cname != '':
                ris = filter(lambda ri: ri['class']==cname,ris)
            stu.logger.info(ris)

            total = len(ris)
            ris = doPage(self,ris)

            self.finish('data',ris,total=total)
        except Exception,e:
            stu.logger.error(e)
Exemplo n.º 3
0
    def get(self):
        stu = Student.instance()
        begin = self.get_argument('begin','0')
        stu.logger.info(begin)
        end = self.get_argument('end','0')
        stu.logger.info(end)
        name = self.get_argument('name','').strip()
        if begin=='0' and end=='0':
            stu.logger.info('begin =0 and end =0,so return the lastest 7 days quaninfo')
            #get the last week quan info
            end = datetime.today()
            begin = end - timedelta(6)
        else:
            begin = datetime.strptime(begin,'%Y/%m/%d')
            end = datetime.strptime(end,'%Y/%m/%d')

        ret = getQuanInfoBetween(begin,end)

        #generate xls
        r = genxls(r'/opt/simp/static/downloads/quaninfo.xls',cquaninfo,ret)
        if r:
            stu.logger.info('generate xls file success')
        else:
            stu.logger.error('generate xls file failed')


        total = len(ret)
        ret = doPage(self,ret)
        #stu.logger.info(ret)
        #stu.logger.info(name)
        #ret = self.filterStuName()
        if name != '' :
            ret = filter(lambda info: info.has_key('student') and info['student']==name ,ret)

        self.finish('quan',ret,total=total)
Exemplo n.º 4
0
    def get(self):
        stu = None
        try:
            stu = Student.instance()
            classid = self.get_argument('classid','')
            stu.logger.info("classid="+classid)
            if classid == '':
                stu.logger.warning('the request param classid is empty')
                self.finish(success=False)
                return
            if not classid.isdigit() :
                classid = stu.getClassIdOnName(classid)
            stu.logger.info('the request class id is %s' % classid)
            #classid = stu.getClassIdOnName(classid)
            #stu.logger.info("############classname="+str(classid))
            stuids = stu.getStuIdsofClass(classid)

            stu.logger.info(stuids)
            stuInfo = []
            for stuid in stuids:
                si = stu.getStuInfo(stuid)
                if si == None:
                    continue
                name = si['name']
                if name == "":
                    stu.logger.info(stuid+" is not fond in db")
                else:
                    stuInfo.append({"name":name,"id":stuid})
            stuInfo = stuInfo + [{'id':'0','name':'所有学生'}]
            self.finish("stunameids",stuInfo)
        except Exception ,e :
            stu.logger.warning(e)
            raise tornado.web.HTTPError(404)
Exemplo n.º 5
0
    def get(self):
        if isStudent(self):
            self.finish(success=False,notification='权限不足,无法修改数据')
            return


        day = self.get_argument('date','')
        idc = self.get_argument('idc','')

        stu = Student.instance()

        if day == '':
            stu.logger.warning('request param day is empty')
            self.finish(success=False)
            return
        if idc == '' :
            stu.logger.warning('request param idc is empty')
            self.finish(success=False)
            return
        ret = self.searchAndDelAI(day,idc)
        if ret == 0 :
            stu.logger.info('Delete attend info done')
            self.finish(success=True)
            return
        self.finish(success=False)
        return
Exemplo n.º 6
0
    def getAttendInfoBetween(self,begin,end):
        stu = Student.instance()
        try:
            if type(begin) != type(datetime) :
                begin = datetime.strptime(begin,'%Y/%m/%d')

            if type(end) != type(datetime) :
                end = datetime.strptime(end,'%Y/%m/%d')
            stu.logger.info(begin)
            stu.logger.info(end)
            if end < begin :
                return []

            days = (end-begin).days
            stu.logger.info(days)
            rets=[]
            for n in range(0,days+1):
                day = begin + timedelta(n)
                day = day.strftime('%Y/%m/%d')
                stu.logger.info(day)
                ret = stu.getAttendInfo(day)
                stu.logger.info(ret)
                for info in ret:
                    info = json.loads(info)
                    rets.append(info)

            return rets
        except Exception,e:
            stu.logger.error(e)
Exemplo n.º 7
0
    def post(self):
        try:
            if isStudent(self):
                self.finish(success=False,notification='权限不足,无法修改数据')
                return
            stu = Student.instance()
            stuinfo = json.loads(self.request.body)
            if type(stuinfo)==type({}) and stuinfo.has_key('data') :
                sis = stuinfo['data']
                if type(sis)==type({}):
                    sis = [sis]
                for si in sis:
                    ret = stu.getStuInfo(si['stuid'])
                    if si.has_key('idc') and not si['idc'].startswith('stu_'):
                        si['idc'] = u'stu_' +stu.getuuid()
                    if not si.has_key('idc'):
                        si['idc'] = u'stu_' +stu.getuuid()

                    if si.has_key('class') and not si['class'].isdigit() :
                        si['class'] = stu.getClassIdOnName(si['class'])
                    stu.setStuIdOnName(si['name'],si['stuid'])
                    stu.logger.info('set stu id(%s) on name(%s) ' % (si['stuid'],si['name']))
                    stu.setStuIDofClass(si['stuid'],si['class'])
                    stu.logger.info('set stu id(%s) on class id (%s) ' % (si['stuid'],si['class']))

                    stu.logger.info('set stu info %s' % str(si))
                    stu.setStuInfo(si)
        except Exception,e:
            stu.logger.error(e)
            self.finish(success=False)
            return
Exemplo n.º 8
0
    def get(self):
        try:
            if isStudent(self):
                self.finish(success=False,notification='权限不足,无法修改数据')
                return

            stu = Student.instance()
            noticeidc = self.get_argument('noticeidc','')
            if noticeidc=='':
                stu.logger.warning('notice idc is empty')
                return

            news = stu.getNotices()
            ret=[]
            for new in news:
                tmp = stu.str2dict(new)
                if tmp['idc'] == noticeidc:
                    stu.logger.info('find the  notice of idc :%s , that is %s' % (noticeidc,new))
                    ret = stu.deleteNotice(new)
                    if ret>0:
                        stu.logger.info('delete notice of idc :%s done' % noticeidc)
                        self.finish()
                        return
                    else:
                        stu.logger.warning('delete notice idc: %s failed' % noticeidc)
                        self.finish(success=False)
                        return
            self.finish(success=False)
            return
        except Exception,e:
            stu.logger.error(e)
            self.finish(success=False)
            return
Exemplo n.º 9
0
    def get(self):
        try:
            if isStudent(self):
                self.finish(success=False,notification='权限不足,无法修改数据')
                return


            stu = Student.instance()
            quanidc = self.get_argument('idc','')
            cname = self.get_argument('cname','')
            if quanidc == '':
                stu.logger.warning('request param idc is empty')
                self.finish(success=False)
                return
            if cname == '':
                stu.logger.warning('request param cname is empty')
                self.finish(success=False)
                return

            cid = stu.getClassIDbyName(cname)
            ret = self.searchAndDelQI(cid,quanidc)
            if ret == 0:
                stu.logger.info('delete qi done')
                self.finish(success=True)
                return
            self.finish(success=False)
            return
        except Exception,e:
            stu.logger.error(e)
            self.finish(success=False)
            return
Exemplo n.º 10
0
    def get(self):
        try:
            if isStudent(self):
                self.finish(success=False,notification='权限不足,无法修改数据')
                return

            user = self.get_argument('user','')
            stu = Student.instance()
            if user == '':
                stu.logger.warning('request param user is empty')
                self.finish(success=False)
                return
            ret = stu.deleteUserInfo(user)
            if ret == 0:
                stu.logger.error('delete user failed ,user:%s is not in db' % user)
                self.finish(success=False)
                return

            self.finish(success=True)
            return

        except Exception,e:
            stu.logger.error(e)
            self.finish(success=False)
            return
Exemplo n.º 11
0
    def post(self):
        try:
            if isStudent(self):
                self.finish(success=False,notification='权限不足,无法修改数据')
                return


            stu = Student.instance()
            news = json.loads(self.request.body)
            news = news['data']
            if type(news)==type({}) :
                news = [news]
            all_news = stu.getNotices()
            for n in news:
                if n['author'] == '':
                    n['author'] == unicode('轶名')
                if n.has_key('content'):
                    n['content'] = n['content'].replace('\n','</p><p>')
                    n['content'] = '<p>' +n['content']
                    n['content'] = n['content'] + '</p>'
                if n.has_key('idc') and n['idc'].startswith('news_') :
                    #modify and first del it
                    stu.logger.info('modify the news')
                    for ns in all_news:
                        tmp = stu.str2dict(ns)
                        if tmp['idc'] == n['idc']:
                            stu.deleteNotice(ns)
                            stu.logger.info('delete the news : %s' % ns)
                            break
                n['idc'] = 'news_'+ stu.getuuid()
                stu.setNotice(n)
        except Exception,e:
            stu.logger.error(e)
            self.finish(success=False)
Exemplo n.º 12
0
    def get(self):
        try:
            stu = Student.instance()
            begin = self.get_argument('begin','')
            end = self.get_argument('end','')
            today = datetime.today()
            if begin == '':
                begin = today - timedelta(365*10)
            else:
                begin = datetime.strptime(begin,'%Y/%m/%d')
            if end == '':
                end = today
            else:
                end = datetime.strptime(end,'%Y/%m/%d')

            news = stu.getNotices()
            ret=[]
            for new in news:
                new = stu.str2dict(new)
                date = datetime.strptime(new['date'],'%Y/%m/%d')
                if date>= begin and date <=end :
                    ret.append(new)

            total = len(ret)
            ret = doPage(self,ret)

            self.finish("data",ret,total=total)
            return
        except Exception,e:
            stu.logger.error(e)
Exemplo n.º 13
0
    def post(self):
        try:
            if isStudent(self):
                self.finish(success=False,notification='权限不足,无法修改数据')
                return

            stu = Student.instance()
            stu.logger.info('set attend info')
            ris = json.loads(self.request.body)['data']
            if type(ris) == type({}):
                ris= [ris]
            for ri in ris :
                #day = ri['date']
                name = ri['student']
                sid = stu.getStuIdOnName(name)
                if sid == '':
                    stu.logger.error('cant find stu id of '+name)
                    self.finish(success=False,notification='姓名错误')
                    return

                stu.logger.info(ri['idc'])
                if ri.has_key('idc') and ri['idc'].startswith('reward_'):
                    stu.logger.info('modify reward info,first delete')
                    self.searchAndDelRI(sid,ri['idc'])
                else:
                    stu.logger.info('a new reward info')
                    ri['idc'] = 'reward_' + stu.getuuid()

                ret = stu.setRewardInfo(sid,ri)

        except Exception,e:
            stu.logger.error(e)
Exemplo n.º 14
0
 def get(self):
     try:
         stu = Student.instance()
         stu.logger.info('in GetQuanTypesHandler')
         types = stu.getQuanTypes()
         self.finish("quantypes",types)
     except Exception ,e :
         raise tornado.web.HTTPError(404)
Exemplo n.º 15
0
 def get(self):
     try:
         stu = Student.instance()
         stu.logger.info("in getAllClassIDs")
         ret = stu.getAllClassIDs()
         ret = ret + [{'id':'0','name':'所有班级'}]
         self.finish("classids",ret)
     except Exception ,e :
         raise tornado.web.HTTPError(404)
Exemplo n.º 16
0
 def get(self):
     try:
         stu = Student.instance()
         newslist = self.getNewsList()
         #treenode = [{'id':'newslistnode','rootVisible':'false','text':'','children':newslist}]
         treenode = json.dumps(newslist)
         self.write(treenode)
     except Exception,e:
         stu.logger.error(e)
Exemplo n.º 17
0
 def getNewsList(self,count=25):
     stu = Student.instance()
     news = stu.getNotices(to=count-1)
     ret=[]
     for new in news:
         new = stu.str2dict(new)
         if new.has_key('idc') and new.has_key('title') :
             ret.append({'id':new['idc'],'text':new['title'],'leaf':'true','icon':'static/pic/rss.gif'})
     return ret
Exemplo n.º 18
0
def setStuIDOnName():
    stu = Student.instance()
    r = stu.getDB()
    sks = r.keys('student:20*')
    for sk in sks:
        sid = sk[8:]
        si = stu.getStuInfo(sid)
        sn = si['name']
        stu.setStuIdOnName(sn,sid)
        print sid,sn
Exemplo n.º 19
0
    def compRank(self,data,key,value):
        stu = Student.instance()

        tmp=[]
        for d in data.values():
            tmp.append(float(d[key]))
        tmp = list(set(tmp))
        tmp.sort(reverse=True)
        for d in data.values():
            d[value] = tmp.index(float(d[key])) + 1
Exemplo n.º 20
0
 def searchAndDelRI(self,sid,idc):
     try:
         stu = Student.instance()
         ris = stu.getRewardInfo(sid)
         for ri in ris:
             tmp = stu.str2dict(ri)
             if idc == tmp['idc'] :
                 stu.deleteRewardInfo(sid,ri)
                 break
     except Exception,e:
         stu.logger.error(e)
Exemplo n.º 21
0
    def post(self):
        try:
            if isStudent(self):
                self.finish(success=False,notification='权限不足,无法修改数据')
                return

            stu = Student.instance()
            #infos = self.get_argument('quaninfos')
            #for k,v in self.request.arguments:
            quaninfos = json.loads(self.request.body)
            qis = quaninfos['quaninfos']
            if type(qis)==type({}):
                qis = [qis]
            for qi in qis:
                cn = unicode(qi['class'])
                cid = stu.getClassIDbyName(cn)
                stu.logger.info(cid)
                stu.logger.info(cn)
                if cid == 0:
                    stu.logger.error('cant find class in db' + cn)
                    self.finish(success=False)
                    continue
                sn = qi['student']
                sid = stu.getStuIdOnName(sn)
                stu.logger.info(sn)
                stu.logger.info(sid)
                if sid == 0:
                    stu.logger.error('cant find student in db'+sn)
                    self.finish(success=False)
                    continue
                qn = qi['quan_type']
                qid = stu.getQuanIdOnName(qn)
                if qid == 0:
                    stu.logger.error('cant find quan type in db'+qn)
                    self.finish(success=False)
                    continue

                qi['class'] = int(cid)
                qi['student'] = int(sid)
                qi['quan_type'] = int(qid)
                stu.logger.info('###########test ponit 1')
                if qi.has_key('idc') and qi['idc'].startswith('quan_'):
                    stu.logger.info('modify,delete first')
                    self.searchAndDelQI(cid,qi['idc'])
                else:
                    stu.logger.info('new one ,set idc')
                    qi['idc'] = 'quan_'+stu.getuuid()
                stu.logger.info(qi)
                stu.setQuanInfo(cid,qi)
            stu.logger.info(stu.getQuanInfo(cid))
        except Exception,e:
            stu.logger.error(e)
Exemplo n.º 22
0
 def get(self):
     stu = Student.instance()
     newsid = self.get_argument('id','')
     news = stu.getNotices()
     content = NEWS_TEMPLATE
     for n in news:
         n = stu.str2dict(n)
         if n.has_key('idc') and (n['idc'] == newsid or newsid==''):
             stu.logger.info(n)
             content = (content) % (n['title'] ,n['author'],n['date'],n['content'])
             self.write(content)
             return
     self.write('')
     return
Exemplo n.º 23
0
    def searchAndDelAI(self,day,idc) :
        try:
            stu = Student.instance()
            ais = stu.getAttendInfo(day)
            for ai in ais:
                tmp = stu.str2dict(ai)
                if tmp.has_key('idc') and tmp['idc'] == idc :
                    stu.deleteAttendInfo(day,ai)
                    return 0
            return 1

        except Exception,e:
            stu.logger.info(e)
            return -1
Exemplo n.º 24
0
    def get(self):
        stu = Student.instance()
        try:
            cname = self.get_argument('class','').strip()
            bdate = self.get_argument('begin','').strip()
            edate = self.get_argument('end','').strip()
            name = self.get_argument('name','').strip()

            stu.logger.info(bdate)
            stu.logger.info(edate)


            firstDay,lastDay = getDateOfNWeek(0)

            if bdate == '' :
                bdate = firstDay.strftime('%Y/%m/%d')

            if edate == '' :
                edate = lastDay.strftime('%Y/%m/%d')
            stu.logger.info(bdate)
            stu.logger.info(edate)

            attendInfos = self.getAttendInfoBetween(bdate,edate)
            stu.logger.info(attendInfos)
            ret = []
            if cname == '':
                stu.logger.info("class='',so get attend info or all classes")
                ret = attendInfos
            else:
                for ai in attendInfos :
                    if cname == ai['class']:
                        ret.append(ai)
            #generate xls
            r = genxls(r'/opt/simp/static/downloads/attendinfo.xls',cattendinfo,ret)
            if r:
                stu.logger.info('generate xls file success')
            else:
                stu.logger.error('generate xls file failed')

            total = len(ret)
            ret = doPage(self,ret)
            #stu.logger.info(ret)
            stu.logger.info(name)
            if name != '' :
                ret = filter(lambda info: info.has_key('student') and info['student']==name ,ret)

            self.finish('data',ret,total=total)
        except Exception,e :
            stu.logger.error(e)
Exemplo n.º 25
0
def initClass():

    stu = Student.instance()

    cls = stu.getAllClassIDs()
    for c in cls:
        ci={}
        ci['id'] = c['id']
        ci['name'] = c['name']
        ci['teacher']='' #head teacher
        ci['telephone']='' # teacher's phone number
        ci['master']='' # master of the class
        ci['mphone'] ='' # master 's phone
        ci['stuids']=[] # all stu id
        stu.setClassInfo(c['id'],ci)
Exemplo n.º 26
0
    def searchAndDelQI(self,cid,idc):
        try:
            stu = Student.instance()
            qs = stu.getQuanInfo(cid)
            for q in qs:
                tmp = stu.str2dict(q)
                if tmp.has_key('idc') and tmp['idc'] == idc :
                    stu.deleteQuanInfo(cid,q)
                    return 0

            return 1

        except Exception,e:
            stu.logger.error(e)
            return -1
Exemplo n.º 27
0
    def post(self):
        try:
            if isStudent(self):
                self.finish(success=False,notification='权限不足,无法修改数据')
                return

            stu = Student.instance()
            userinfo = json.loads(self.request.body)
            if type(userinfo)==type({}) and userinfo.has_key('data') :
                uis = userinfo['data']
                if type(uis)==type({}):
                    uis = [uis]
                all_ui = stu.getAllUserInfo()

                for ui in uis:
                    #check if user is exist in the db, if so ,rewrite the info
                    if ui.has_key('idc') and ui['idc'].startswith('user_'):
                        pass
                        #modeify and first delete it
                        stu.logger.info('modify user info')
                        for u in all_ui :
                            stu.logger.info(str(u))
                            if u.has_key('idc') and ui['idc'] == u['idc']:
                                stu.logger.info('find the user info %s' % str(u))
                                stu.deleteUserInfo(u['user'])
                                stu.logger.info('delete user info : %s' % str(u))
                                break

                    if not ui['idc'].startswith('user_'):
                        ui['idc'] = stu.getuuid()
                    #number to text
                    if ui['role'].isdigit():
                        if ui['role'] == u'0' :
                            ui['role'] == u'管理员'
                        elif ui['role'] == u'1' :
                            ui['role'] == u'老师'
                        elif ui['role'] == u'2' :
                            ui['role'] == u'学生'
                        else:
                            stu.logger.warning('role type is unknow which is %s' % str(ui['role']))

                    stu.logger.info(ui)
                    stu.setUserInfo(ui)
        except Exception,e:
            stu.logger.error(e)
            self.finish(success=False)
            return
Exemplo n.º 28
0
    def get(self):

        try:
            stu = Student.instance()
            classid = self.get_argument('cid',u'0')
            name = self.get_argument('name','')
            stu.logger.info('get all stuinfo handler cid: %s' % classid)
            ret = stu.getAllStuInfo()

            cid2cname = {}
            stuinfo=[]
            for r in ret:
                cid = unicode(r['class'])
                if classid != '0' and classid != cid :
                    continue
                if not cid2cname.has_key(cid):

                    try:
                        if cid.isdigit() :
                            cid2cname[cid] = stu.getClassNameOnId(cid)
                            stu.logger.info('get class name on id: %s, and name is %s' % (cid,cid2cname[cid]))
                        else:
                            stu.logger.info('class id  and name is the same %s' % cid)
                            cid2cname[cid] = cid
                    except Exception,e:
                        stu.logger.error('cid is not correct ,cid:'+cid)
                        stu.logger.error(e)
                        continue
                    #else:
                r['class'] = cid2cname[cid]
                stuinfo.append(r)


            ret = genxls(r'/opt/simp/static/downloads/stuinfo.xls',cstuinfo,stuinfo)
            if ret:
                stu.logger.info('generate xls file success')
            else:
                stu.logger.error('generate xls file failed')
            total = len(stuinfo)
            stuinfo = doPage(self,stuinfo)
            if name != '' :
                stuinfo = filter(lambda info: info.has_key('name') and info['name']==name ,stuinfo)

            stu.logger.info(stuinfo)
            stu.logger.info(name)
            self.finish("data",stuinfo,total=total)
            return
Exemplo n.º 29
0
def addUser():
    stu = Student.instance()
    r = stu.getDB()
    stuKeys = r.keys("student:*")
    for key in stuKeys:
        value={}
        stuInfo = r.get(key)
        #stuid = key.replace('student:','')
        if stuInfo!= None:
            stuInfo = json.loads(stuInfo)
            if stuInfo['stuid']=='0':
                continue
            else:
                value['user'] = stuInfo['stuid']
                value['role'] = '80000' #student
                value['pwd'] = stuInfo['identify'][-8:]
                stu.setUserInfo(stuInfo['user'],value)
                print stuInfo['stuid'],value
Exemplo n.º 30
0
def getQuanInfoBetween(begin,end):
    stu = Student.instance()
    stu.logger.info("begin:"+str(begin)+" end:"+str(end))
    ret = []
    qinfos = stu.getAllQuanInfos()
    for qi in qinfos:
        date = datetime.strptime(str(qi['quan_date']),'%Y/%m/%d')
        if begin<= date and end>= date:
            stu.logger.info('quaninfo:'+str(qi))
            try:
                qi['student'] = stu.getStuNameOnId(qi['student'])
                qi['quan_type']= stu.getQuanNameOnId(qi['quan_type']).decode('utf-8')
                qi['class'] = stu.getClassNameOnId(qi['class'])
                stu.logger.info('qinfo : %s' % str(qi))
            except Exception,e:
                stu.logger.error(e)
                continue

            ret.append(qi)