예제 #1
0
 def post(self, request):
     if not request.session.has_key("openId") or request.session.get(
             "openId") == "":
         return myResponse.AuthError("您未登录")
     try:
         thisFunctionary = functionary.objects.get(
             user__openid=request.session.get("openId"))
     except:
         return myResponse.AuthError("您不是工作人员")
     try:
         img = request.FILES.get("img")
         eid = request.data['eid']
         type = request.data['type']
     except:
         return myResponse.Error("上传异常")
     try:
         res = upload(img.file, img.name)
         if res == 200:
             thisImage = eventImage(
                 event=event.objects.get(id=int(eid)),
                 type=type,
                 url="https://xwareimage.oss-cn-beijing.aliyuncs.com/" +
                 img.name)
             thisImage.save()
         else:
             return myResponse.Error("后端异常")
     except:
         return myResponse.Error("后端异常")
     return myResponse.OK(data=thisImage.url)
예제 #2
0
 def put(self, request):
     try:
         fid = request.query_params['fid']
         thisFunctionary = functionary.objects.get(id=fid)
     except:
         return myResponse.Error("后端错误")
     if thisFunctionary.userName != request.session.get(
             "username") and request.session.get(
                 "auth") <= thisFunctionary.auth:
         return myResponse.AuthError("您无此权限")
     js_body = json.loads(request.body)
     try:
         realName = js_body['realName']
         if request.session.get("auth") >= 4 and int(
                 js_body['auth']) < request.session.get("auth"):
             auth = js_body['auth']
         else:
             auth = thisFunctionary.auth
     except:
         return myResponse.Error("字段不足")
     thisFunctionary.auth = auth
     thisFunctionary.realName = realName
     thisFunctionary.save()
     return myResponse.OK(
         data=f_serializer.FunctionarySerializers(thisFunctionary).data)
예제 #3
0
 def post(self, request):
     if not request.session.has_key("openId") or request.session.get(
             "openId") == "":
         return myResponse.AuthError("您未登录")
     try:
         eid = request.data['eid']
         thisEvent = event.objects.get(id=int(eid))
     except:
         return myResponse.Error("后端异常")
     if thisEvent.handler.user.openid != request.session.get("openId"):
         return myResponse.AuthError("您无权修改该事件")
     try:
         detectProblemType = request.data['detectProblemType']
         detectInfo = request.data['detectInfo']
         handleWay = request.data['handleWay']
         finalStatus = request.data['finalStatus']
         status = request.data['status']
         thisEvent.detectInfo = detectInfo
         thisEvent.handlerWay = handleWay
         thisEvent.finalStatus = finalStatus
         thisEvent.detectProblemType = detectProblemType
         thisEvent.status = status
         thisEvent.save()
         if status == "处理完成":
             thisEvent.appointment.status = 4
             thisEvent.appointment.save()
     except:
         return myResponse.Error("后端异常")
     return myResponse.OK(data=EventSerializers(thisEvent).data)
예제 #4
0
 def post(self, request):
     try:
         fid = request.query_params['fid']
         thisFunctionary = functionary.objects.get(id=fid)
     except:
         return myResponse.Error("后端错误")
     if thisFunctionary.userName != request.session.get(
             "username") and request.session.get(
                 "auth") <= thisFunctionary.auth:
         return myResponse.AuthError("您无此权限")
     js_body = json.loads(request.body)
     try:
         old = js_body['old']
         newPassword = js_body['new']
     except:
         return myResponse.Error("字段错误")
     if request.session.get("auth") >= 4:
         thisFunctionary.passWord = passwordSalt(newPassword)
     else:
         if thisFunctionary.passWord == passwordSalt(old):
             thisFunctionary.passWord = passwordSalt(newPassword)
         else:
             return myResponse.Error("旧密码错误")
     thisFunctionary.save()
     return myResponse.OK("修改成功")
예제 #5
0
 def get(self, request):
     if not request.session.has_key("openId") or request.session.get(
             "openId") == "":
         return myResponse.AuthError("您未登录")
     try:
         eid = request.query_params['eid']
         thisEvent = event.objects.get(id=int(eid))
     except:
         return myResponse.Error("后端异常")
     if thisEvent.handler.user.openid == request.session.get("openId"):
         return myResponse.OK(data=EventSerializers(thisEvent).data)
     elif thisEvent.appointment.user.openid == request.session.get(
             "openId"):
         return myResponse.OK(data=EventSerializers(thisEvent).data)
     else:
         return myResponse.AuthError("您无权限查看该事件")
예제 #6
0
 def get(self, request):
     if not request.session.has_key("openId") or request.session.get(
             "openId") == "":
         return myResponse.AuthError("您未登录")
     try:
         thisFunctionary = functionary.objects.get(
             user__openid=request.session.get("openId"))
     except:
         return myResponse.AuthError("您不是工作人员")
     try:
         UUID = request.query_params['uuid']
         thisAppointment = Appointment.objects.get(uuid=UUID)
     except:
         return myResponse.AuthError("预约获取错误")
     try:
         if thisAppointment.status != 2 and thisAppointment.status != 1 and thisAppointment.status != 3:
             return myResponse.AuthError("事件已结束")
         thisEvent = event(appointment=thisAppointment,
                           handler=thisFunctionary,
                           status="正在维修")
         thisEvent.save()
         thisAppointment.status = 3
         thisAppointment.save()
     except:
         return myResponse.Error("后端异常")
     return myResponse.OK("绑定成功", data={"eid": thisEvent.id})
예제 #7
0
 def get(self, request):
     try:
         eid = int(request.query_params['eid'])
         thisEvent = event.objects.get(id=eid)
     except:
         return myResponse.Error("后端异常")
     return myResponse.OK(
         data=f_serializer.EventSerializers(thisEvent).data)
예제 #8
0
 def put(self, request):
     try:
         uuid = request.query_params['uuid']
         status = 2
     except:
         return myResponse.Error("字段不足")
     Appointment.objects.filter(uuid=uuid).update(status=status)
     return myResponse.OK("操作成功")
예제 #9
0
 def get(self, request):
     if not request.session.has_key("openId") or request.session.get(
             "openId") == "":
         return myResponse.AuthError("您未登录")
     allApp = Appointment.objects.filter(
         user__openid=request.session.get("openId")).order_by("-id")
     return myResponse.OK(
         data=shortAppointmentSerializers(allApp, many=True).data)
예제 #10
0
 def get(self, request):
     username = request.session.get("username")
     userList = functionary.objects.filter(userName=username)
     if userList.count() == 0:
         return myResponse.Error("无此用户")
     thisuser = userList[0]
     return myResponse.OK(
         "已登录",
         f_serializer.FunctionarySerializers(thisuser).data)
예제 #11
0
 def get(self, request):
     now = datetime.datetime.now()
     timeslots = TimeSlot.objects.filter(End__gte=now)
     ret = []
     for slot in timeslots:
         nowAppointCount = slot.appointment_set.count()
         if slot.AllowNumber > nowAppointCount:
             ret.append(slot)
     return myResponse.OK(data=timeSlotSerializers(ret, many=True).data)
예제 #12
0
 def get(self, request):
     try:
         tids = request.query_params['tids'].split(",")
         inttids = []
         for tid in tids:
             inttids.append(int(tid))
     except:
         return myResponse.Error("无法取得时间段")
     allAppointment = Appointment.objects.filter(slot_id__in=tids)
     return myResponse.OK(msg="获取成功",
                          data=f_serializer.AppointmentDetailSerializers(
                              allAppointment, many=True).data)
예제 #13
0
 def get(self, request):
     if not request.session.has_key("openId") or request.session.get(
             "openId") == "":
         return myResponse.AuthError("您未登录")
     try:
         aid = request.query_params['aid']
         thisAppointment = Appointment.objects.get(id=int(aid))
     except:
         return myResponse.Error("预约获取异常")
     if request.session.get("openId") != thisAppointment.user.openid:
         return myResponse.AuthError("您无权获取该预约")
     return myResponse.OK(
         data=AppointmentDetailSerializers(thisAppointment).data)
예제 #14
0
 def get(self, request):
     if not request.session.has_key("openId") or request.session.get(
             "openId") == "":
         return myResponse.AuthError("您未登录")
     try:
         thisFunctionary = functionary.objects.get(
             user__openid=request.session.get("openId"))
     except:
         return myResponse.AuthError("您不是工作人员")
     allMyEvent = event.objects.filter(
         handler=thisFunctionary).order_by("-id")
     pg = SelfdefinedPage()
     pgr = pg.paginate_queryset(queryset=allMyEvent,
                                request=request,
                                view=self)
     return myResponse.OK(data=shortEventSerializers(pgr, many=True).data)
예제 #15
0
 def post(self, request):
     data = json.loads(request.body)
     if "username" not in data or "password" not in data:
         return myResponse.Error("数据不全")
     username = data['username']
     password = passwordSalt(data['password'])
     userList = functionary.objects.filter(userName=username)
     if userList.count() == 0:
         return myResponse.AuthError("无此用户")
     thisuser = userList[0]
     if thisuser.passWord != password:
         return myResponse.AuthError("密码错误")
     request.session['auth'] = thisuser.auth
     request.session['username'] = thisuser.userName
     return myResponse.OK(
         "登录成功",
         f_serializer.FunctionarySerializers(thisuser).data)
예제 #16
0
 def post(self, request):
     try:
         js_body = json.loads(request.body)
         date = datetime.datetime.strptime(js_body['date'], "%Y-%m-%d")
         starttime = datetime.datetime.strptime(js_body['start'],
                                                "%Y-%m-%d %H:%M:%S")
         endtime = datetime.datetime.strptime(js_body['end'],
                                              "%Y-%m-%d %H:%M:%S")
         number = int(js_body['number'])
     except:
         return myResponse.Error("后端异常")
     newTimeSlop = TimeSlot(Date=date,
                            Start=starttime,
                            End=endtime,
                            AllowNumber=number)
     newTimeSlop.save()
     return myResponse.OK(
         data=f_serializer.timeSlotSerializers(newTimeSlop).data)
예제 #17
0
 def post(self, request):
     if not request.session.has_key("openId") or request.session.get(
             "openId") == "":
         return myResponse.AuthError("您未登录")
     thisUser = user.objects.get(openid=request.session.get("openId"))
     try:
         username = request.data['username']
         password = request.data['password']
         thisFunctionary = functionary.objects.get(userName=username)
         finalPassword = passwordSalt(password)
         if thisFunctionary.passWord != finalPassword:
             return myResponse.AuthError("密码错误")
         thisFunctionary.user = thisUser
         thisFunctionary.save()
     except:
         return myResponse.Error("后端异常")
     return myResponse.OK(
         data={"userInfo": userHandle(request.session.get("openId"))})
예제 #18
0
 def post(self, request):
     data = request.data
     if not request.session.has_key("openId") or request.session.get(
             "openId") == "":
         return myResponse.AuthError("您未登录")
     if not ("realName" in data and "phone" in data and "NO" in data):
         return myResponse.Error("请求参数过少")
     try:
         realName = request.data["realName"]
         phone = request.data["phone"]
         NO = request.data["NO"]
         thisUser = user.objects.get(openid=request.session.get("openId"))
         thisUser.realName = realName
         thisUser.phone = phone
         thisUser.NO = NO
         thisUser.save()
     except:
         return myResponse.Error("后端异常")
     return myResponse.OK(
         "修改成功", {"userInfo": userHandle(request.session.get("openId"))})
예제 #19
0
 def get(self, request):
     if "jscode" not in request.query_params:
         return myResponse.Error("无jscode")
     jscode = request.query_params['jscode']
     openId = ""
     try:
         res = requests.get("https://api.weixin.qq.com/sns/jscode2session",
                            params={
                                "appid": appId,
                                "secret": appSecret,
                                "js_code": jscode,
                                "grant_type": "authorization_code",
                            },
                            timeout=5)
         res = json.loads(res.text)
         openId = res['openid']
         request.session['openId'] = openId
         request.session['info'] = res
     except:
         return myResponse.Error("后端请求错误")
     return myResponse.OK(
         "登录成功", {"userInfo": userHandle(request.session.get("openId"))})
예제 #20
0
 def post(self, request):
     data = request.data
     if not request.session.has_key("openId") or request.session.get(
             "openId") == "":
         return myResponse.AuthError("您未登录")
     if not ("problemType" in data and "ProblemDetail" in data
             and "sid" in data):
         return myResponse.Error("请求参数过少")
     try:
         sid = data['sid']
         problemType = data['problemType']
         ProblemDetail = data['ProblemDetail']
         thisUUID = uuid.uuid4()
         thisUser = user.objects.get(openid=request.session.get("openId"))
         thisSlot = TimeSlot.objects.get(id=int(sid))
         exist = Appointment.objects.filter(user=thisUser,
                                            slot__Date=thisSlot.Date,
                                            status__lte=4)
         if exist.count() != 0:
             return myResponse.AuthError("该日您已有预约")
         sourseInfo = {
             "realName": thisUser.realName,
             "phone": thisUser.phone,
             "NO": thisUser.NO,
         }
         newAppointment = Appointment(
             problemType=problemType,
             uuid=thisUUID,
             user=thisUser,
             slot=thisSlot,
             describe=ProblemDetail,
             sourseInfo=sourseInfo,
         )
         newAppointment.save()
     except:
         return myResponse.Error("后端异常")
     return myResponse.OK(
         "提交成功", data=shortAppointmentSerializers(newAppointment).data)
예제 #21
0
 def put(self, request):
     try:
         tid = int(request.query_params['tid'])
         js_body = json.loads(request.body)
         date = datetime.datetime.strptime(js_body['date'], "%Y-%m-%d")
         starttime = datetime.datetime.strptime(js_body['start'],
                                                "%Y-%m-%d %H:%M:%S")
         endtime = datetime.datetime.strptime(js_body['end'],
                                              "%Y-%m-%d %H:%M:%S")
         number = int(js_body['number'])
     except:
         return myResponse.Error("后端异常")
     try:
         thisTimeSlop = TimeSlot.objects.get(id=tid)
     except:
         return myResponse.Error("无法取得此时间段")
     thisTimeSlop.Date = date
     thisTimeSlop.Start = starttime
     thisTimeSlop.End = endtime
     thisTimeSlop.AllowNumber = number
     thisTimeSlop.save()
     return myResponse.OK(
         data=f_serializer.timeSlotSerializers(thisTimeSlop).data)
예제 #22
0
 def post(self, request):
     if request.session.get("auth") < 4:
         return myResponse.AuthError("您无此权限")
     js_body = json.loads(request.body)
     try:
         username = js_body['username']
         password = js_body['password']
         realName = js_body['realName']
         auth = js_body['auth']
     except:
         return myResponse.Error("字段不全")
     if functionary.objects.filter(userName=username).count() != 0:
         return myResponse.Error("已存在用户名")
     if request.session.get("auth") <= int(auth):
         return myResponse.AuthError("权限不足")
     newFunctionary = functionary(
         userName=username,
         passWord=passwordSalt(password),
         auth=int(auth),
         realName=realName,
     )
     newFunctionary.save()
     return myResponse.OK(
         data=f_serializer.FunctionarySerializers(newFunctionary).data)
예제 #23
0
 def get(self, request):
     userList = functionary.objects.filter(
         auth__lt=request.session.get("auth"))
     return myResponse.OK(
         data=f_serializer.FunctionarySerializers(userList, many=True).data)
예제 #24
0
 def get(self, request):
     problemtypes = mainProblemType.objects.all()
     ser = mainProblemSerializers(problemtypes, many=True)
     data = ser.data
     return myResponse.OK(data=data)
예제 #25
0
 def get(self, request):
     request.session.flush()
     return myResponse.OK("退出成功")
예제 #26
0
 def get(self, request):
     allTime = TimeSlot.objects.all().order_by("-id")
     return myResponse.OK(
         data=f_serializer.timeSlotSerializers(allTime, many=True).data)
예제 #27
0
 def get(self, request):
     allevent = event.objects.filter(
         handler__userName=request.session.get("username"))
     return myResponse.OK(
         data=f_serializer.shortEventSerializers(allevent, many=True).data)