示例#1
0
文件: views.py 项目: WarmerHu/subject
def get_topic(req,param):
    dao = BBSDao({"id":int(param)})
    if req.COOKIES.has_key('userid'):
        dao = dao.select_topic(us=req.COOKIES['userid'])
    else:
        dao = dao.select_topic()
    return HttpResponse(json.dumps(dao),content_type="application/json")
示例#2
0
文件: views.py 项目: WarmerHu/subject
def add_a_bbs(req):
    if req.method == "POST" and req.COOKIES.has_key('username'):
        name = req.POST["name"]
        detail = req.POST["detail"]
        nlen = len(name)
        dlen = len(detail)
        if nlen<6 or nlen>50 or dlen<10 or dlen>10000:
            return HttpResponse(json.dumps({"tips":"请正确输入标题与详情,标题长度∈[6,50],详情长度∈[10,10000]"}),content_type="application/json")
        else:
            dao = BBSDao({"userid":req.COOKIES["userid"]}) 
            if dao.insert_a_topic({"name":name,"content":detail}):
                return HttpResponse(json.dumps(dao.select_newestTopic_byUs()),content_type="application/json")
    return HttpResponse(json.dumps({"tips":"登录用户一天内最多可发布5则话题"}),content_type="application/json")
示例#3
0
文件: views.py 项目: WarmerHu/subject
def opinion(req):
    id = req.COOKIES["userid"]  # @ReservedAssignment
    dao = BBSDao({'userid':id})
    p = int(req.GET.get('p'))
    e = int(req.GET.get('e'))
    cur = p
    rs = {}
    if p==0:
        cur = 1
        cn = dao.select_COBBS_by_us()
        rs['numT'] = cn
    ts = dao.select_Obbs_by_us(cur, e)
    rs['opinion'] = ts
    return HttpResponse(json.dumps(rs),content_type="application/json")
示例#4
0
文件: views.py 项目: WarmerHu/subject
def get_opinions(req,param):
    p = int(req.GET.get('p'))
    cur = p
    rs = {}
    dao = BBSDao({"id":int(param)})
    if p==0:
        cur = 1
        cn = dao.select_Copinion_byBBS()
        rs['numT'] = cn
    if req.COOKIES.has_key('userid'):
        rs['opinion'] = dao.select_opinions_byBBS(cur,us=req.COOKIES['userid'])
    else:
        rs['opinion'] = dao.select_opinions_byBBS(cur)
    return HttpResponse(json.dumps(rs),content_type="application/json")
示例#5
0
文件: views.py 项目: WarmerHu/subject
def add_a_opinion(req,param):
    if req.method == "POST" and req.COOKIES.has_key('userid'):
        content = req.POST["content"]
        auTp = int(req.POST["auTp"]) #发布话题的作者
        au = int(req.POST["au"]) #用户quote
        op = req.POST["op"]
        ph = req.POST["ph"]
        userid = req.COOKIES["userid"]
        dlen = len(content)
        if dlen<10 or dlen>10000:
            return HttpResponse(json.dumps({"tips":"请正确输入意见,长度∈[10,10000]"}),content_type="application/json")
        else:
            dao = BBSDao({"userid":userid,"id":int(param),'au':auTp}) 
            if dao.insert_a_opinion({"content":content,"userid":userid}):
                if au and op and ph:
                    regLIST = "<b>"+('引用').decode("utf-8")+"<a href='"+op+"'>"+ph+"</a>"+("的意见").decode("utf-8")+"</b>"
                    if re.match(regLIST,content):
                        dao = userDao({'userid':int(au)})
                        dao.update_point_byReq({'method':"+",'points':1})
                        dao.save_update()
                return HttpResponse(json.dumps({}),content_type="application/json")
    return HttpResponse(json.dumps({"tips":"登录用户每min只可发布一条意见"}),content_type="application/json")

        
示例#6
0
文件: dao.py 项目: WarmerHu/subject
 def update_a_complaint(self,key,method):
     if self.ex:
         cm = Complaint.objects.get(titleid=self.ex, userid=self.us,state="NORMAL")
         from exercise.dao import updateEXDao
         dao = updateEXDao()
         dao.update_exercise_complaint( method ,ex=self.ex)
         dao.update_ex_save()
     elif self.au:
         cm = Complaint.objects.get(authorid=self.au, userid=self.us,state="NORMAL")
         dao = userDao({'us':self.au})
         dao.update_complaint(method)
         dao.save_update()
     elif self.tp:
         cm = Complaint.objects.get(topicid=self.tp, userid=self.us,state="NORMAL")
         from bbs.dao import BBSDao
         dao = BBSDao({'bbs':self.tp})
         dao.update_Tcomplaint(method)
         dao.update_Tsave()
     elif self.op:
         cm = Complaint.objects.get(opinionid=self.op, userid=self.us,state="NORMAL")
         from bbs.dao import OpinDao
         dao = OpinDao({'op':self.op})
         dao.update_Ocomplaint(method)
         dao.update_save()
     elif self.rs:
         cm = Complaint.objects.get(resourceid=self.rs, userid=self.us,state="NORMAL")
         dao = rsUpdateDao(self.rs)
         dao.update_complaint(method)
         dao.update_save()
     if key=='state':
         cm.state = 'CANCEL'
     cm.save()
示例#7
0
文件: dao.py 项目: WarmerHu/subject
 def insert_a_complaint(self,req,method):
     if self.ex:
         n =  Complaint.objects.filter(titleid=self.ex,state='NORMAL').count()
         if n<5:
             Complaint(titleid=self.ex, content=req['content'],userid=self.us, state='NORMAL').save()
             from exercise.dao import updateEXDao
             dao = updateEXDao() 
             if dao.update_exercise_complaint( method='+',ex=self.ex)==5:
                 dao.update_exercise_state('ACTIVE', self.ex)
             dao.update_ex_save()
             return None
     elif self.au:
         n =  Complaint.objects.filter( authorid=self.au,state='NORMAL').count()
         if n<10:
             Complaint(authorid=self.au, content=req['content'],userid=self.us, state='NORMAL').save()
             dao = userDao({'us':self.au})
             if dao.update_complaint('+')==10:
                 dao.update_state('ACTIVE')
             dao.save_update()
             return None
     elif self.tp:
         n =  Complaint.objects.filter( topicid=self.tp,state='NORMAL').count()
         if n<10:
             Complaint(topicid=self.tp, content=req['content'],userid=self.us, state='NORMAL').save()
             from bbs.dao import BBSDao
             dao = BBSDao({'bbs':self.tp})
             if dao.update_Tcomplaint(method)==10:
                 dao.update_Tstate('ACTIVE')
             dao.update_Tsave()
             return None
     elif self.op:
         n =  Complaint.objects.filter(opinionid=self.op,state='NORMAL').count()
         if n<5:
             Complaint(opinionid=self.op, content=req['content'],userid=self.us, state='NORMAL').save()
             from bbs.dao import OpinDao
             dao = OpinDao({'op':self.op})
             if dao.update_Ocomplaint('+')==5:
                 dao.update_state('ACTIVE')
             dao.update_save()
             return None
     elif self.rs:
         n =  Complaint.objects.filter(resourceid=self.rs,state='NORMAL').count()
         if n<10:
             Complaint(resourceid=self.rs, content=req['content'],userid=self.us, state='NORMAL').save()
             dao = rsUpdateDao(self.rs)
             if dao.update_complaint('+')==10:
                 dao.update_state('ACTIVE')
             dao.update_save()
             return None
     return 'wrong request'