Exemple #1
0
 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()
Exemple #2
0
 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'        
Exemple #3
0
def download_resources(req):
    if req.COOKIES.has_key('userid'):
        resourceID = int(req.GET.get('rs'))
        downloader = req.COOKIES['userid']
        dao = Source.objects.get(id=resourceID)
        downloadPoint = dao.points
        uploader = dao.userid
#         downloadPoint = int(req.POST["points"])
#         uploader = int(req.POST["uploader"])
#         resourceID = int(req.POST["resourceID"])
        if User.objects.filter(id=downloader,points__gte=downloadPoint):
            dao = userDao({'userid':downloader})
            dao.update_point_byReq({'method':'-','points':downloadPoint})
            dao.save_update() 
            dao = userDao({'us':uploader})
            dao.update_point_byReq({'method':'+','points':downloadPoint})
            dao.save_update()
            dao = rsUpdateDao(rsid=resourceID)
            count = dao.update_content()
            dao.update_save()
            content = (' 下载资源: ').decode("utf-8") + dao.rs.download
            downloadPath = settings.MEDIA_ROOT+dao.rs.download  
            ADao = activityDao({"userid":downloader})
            ADao.add_a_activity(content)
            
            def file_iterator(file_name, chunk_size=512):
                with open(file_name) as f:
                    while True:
                        c = f.read(chunk_size)
                        if c:
                            yield c
                        else:
                            break
            
            response = StreamingHttpResponse(file_iterator(downloadPath))
            response['Content-Type'] = 'application/octet-stream'
            response['Content-Disposition'] = 'attachment;filename="{0}"'.format(dao.rs.download) #默认文件名
            return response
#             return HttpResponse(json.dumps({'resourceID':resourceID,"count":count,'dURL':downloadURL}),content_type="application/json")
        return  HttpResponse('积分不足')
    return  HttpResponse('请先登录')