def submit_order(request): result = {'code': 100, 'log': 'Has notified the barber.'} re_data = None try: data = Checker.request(request, ['barphone', 'cusphone', 'cusname', 'sex', 'time', 'distance', 'hairstyle', 'remark']) #try: # _ = CustomerProxy(data['cusphone']) #except CustomerDoesNotExistError: CustomersManager.add_customer(phone=data['cusphone'], name=data['cusname'], sex=data['sex']) #time_conflict(phone=data['cusphone'], time_=data['time']) # ?? order_clash(bar_phone=data['barphone'], time_=data['time']) time_ = calculate_order_time(hairstyle=data['hairstyle'], time_=data['time']) order = OrdersManager.add_order(cus_phone=data['cusphone'], bar_phone=data['barphone'], time_=time_, hairstyle=data['hairstyle'], remark=data['remark'], accepted=True).get_dict() order.pop('accepted') push_msg(alias=order['barphone'], msg=order) except JianyueError as e: result = e.info finally: result['data'] = re_data return HttpResponse(encode(result))
def pull_msg(request): #now = current_time() msgs = Message.objects.all() #later = lambda t: t >= now dict_m = lambda m: {'id': m.user.name, 'time': m.time[0:10]+' '+m.time[11:16], 'content': m.content} msg_q = [dict_m(m) for m in msgs] msg_q.sort(key=lambda m: m['time'], reverse=True) return HttpResponse(encode(msg_q))
def get_api(request): data = Checker.request(request, ['name']) api = Api.objects.get(name=data['name']) return HttpResponse(encode({'url': api.url, 'name': api.name, 'digest': api.digest, 'request': api.request, 'response': api.response}))
def pull_bug(request): bugs = Bug.objects.all() dict_b = lambda b: {'src': b.source.name, 'desc': b.description, 'reptr': b.reporter.name, 'checked': b.checked, 'time': b.time, 'id': b.id} bug_q = [dict_b(b) for b in bugs if not (b.checked and b.dealt)] bug_q.sort(key=lambda b: b['time'], reverse=True) return HttpResponse(encode(bug_q))
def push_msg(request): data = Checker.request(request, ['user', 'content']) user = Member.objects.get(name=data['user']) msg = Message() msg.user = user msg.content = data['content'] msg.time = current_time() msg.save() return HttpResponse(encode({"code": 100, "log": "Normal", "data": None}))
def update_api(request): data = Checker.request(request, ['name', 'digest', 'url', 'response', 'request']) api = Api() api.request = data['request'] api.name = data['name'] api.digest = data['digest'] api.url = data['url'] api.response = data['response'] api.save() return HttpResponse(encode({"code": 100, "log": "Normal", "data": None}))
def report_bug(request): data = Checker.request(request, ['src', 'desc', 'reptr']) bug = Bug() bug.source = Api.objects.get(name=data['src']) bug.reporter = Member.objects.get(name=data['reptr']) bug.description = data['desc'] bug.time = current_time() bug.checked = True bug.save() return HttpResponse(encode({"code":100, "log": "Normal", "data": None}))
def update_name(request): result = {'code': 100, 'log': "Customer's name update success!"} re_data = None try: data = Checker.request(request, ['phone', 'name']) CustomerProxy(phone=data['phone']).name = data['name'] except JianyueError as e: result = e.info finally: result['data'] = re_data return HttpResponse(encode(result))
def set_appt_time(request): result = {'code': 100, 'log': 'time set success'} re_data = None try: data = Checker.request(request, ['phone', 'time']) BarberProxy(data['phone']).set_appt_time(data['time']) except JianyueError as e: result = e.info finally: result['data'] = re_data return HttpResponse(encode(result))
def update_sex(request): result = {'code': 100, 'log': "Barber's sex update success!"} re_data = None try: data = Checker.request(request, ['phone', 'sex']) BarberProxy(phone=data['phone']).sex = data['sex'] except JianyueError as e: result = e.info finally: result['data'] = re_data return HttpResponse(encode(result))
def login(request): result = {'code': 100, 'log': 'login success'} re_data = None try: data = Checker.request(request, ['phone', 'password']) BarberProxy(data['phone']).match(data['password']) except JianyueError as e: result = e.info finally: result['data'] = re_data return HttpResponse(encode(result))
def get_comment(request): result = {'code': 100, 'log': "Comment has returned."} re_data = None try: data = Checker.request(request, ['phone']) re_data = BarberProxy(phone=data['phone']).get_comment() except JianyueError as e: result = e.info finally: result['data'] = re_data return HttpResponse(encode(result))
def is_register(request): result = {'code': 100, 'log': "User has existed,return user's info"} re_data = None try: data = Checker.request(request, ['phone']) customer = CustomerProxy(data['phone']) re_data = customer.get_dict()#会返回头像 except JianyueError as e: result = e.info finally: result['data'] = re_data return HttpResponse(encode(result))
def get_near_shop(request): result = {'code': 100, 'log': 'barber list has returned'} re_data = None try: data = Checker.request(request, ['longitude', 'latitude']) shops = ShopsManager.get_near_shop(longitude=float(data['longitude']), latitude=float(data['latitude']), range_=1500) re_data = shops except JianyueError as e: result = e.info finally: result['data'] = re_data return HttpResponse(encode(result))
def get_barber(request): result = {'code': 100, 'log': 'Barber info has returned.'} re_data = None try: data = Checker.request(request, ['phone', 'date']) #re_data = process_time(barbers=[BarberProxy(data['phone'])], date=data['date'])[0] #怎么感觉这个get barber 有问题 应该返回的是用户请求的时间段的的理发师 re_data = process_time(barbers=[BarberProxy(data['phone'])], date=data['date'])[0] except JianyueError as e: result = e.info finally: result['data'] = re_data return HttpResponse(encode(result))
def is_register(request): result = {'code': 504, 'log': 'Barber has register'} # BarhasRegister re_data = None try: data = Checker.request(request, ['phone']) _ = BarberProxy(data['phone']) except JianyueError as e: result = e.info except Exception: result['code'] = 101 result['log'] = 'Internal error' finally: result['data'] = re_data return HttpResponse(encode(result))
def update_profile(request): result = {'code': 100, 'log': '文件上传所需信息已返回'} re_data = None try: data = Checker.request(request, ['phone']) customer = CustomerProxy(phone=data['phone']) customer.profile = 'profile/customer/' + customer.phone + '.png' re_data = {'key': customer.profile, 'bucket_name': 'jianyue-img', 'access_key_id': 'DS1sGprn39SnhFDV', 'access_key_secret': 'dFmlLMHapOfyUKTDeeUFCp7M64U1aD', } except JianyueError as e: result = e.info finally: result['data'] = re_data return HttpResponse(encode(result))
def register(request): result = {'code': 100, 'log': 'register success'} re_data = None try: data = Checker.request(request, ['phone', 'name', 'sex', 'password', 'shop', 'time']) try: _ = BarberProxy(data['phone']) except BarberDoesNotExistError: BarbersManager.add_barber(phone=data['phone'], name=data['name'], sex=data['sex'], password=data['password'], shop=data['shop'], time_=data['time']) else: raise BarberHasRegister except JianyueError as e: result = e.info finally: result['data'] = re_data return HttpResponse(encode(result))
def accepted_order(request): result = {'code': 100, 'log': 'Order has been accepted successfully.'} re_data = None try: #result = {'code': 100, 'log': 'Order has been accepted successfully.'} data = Checker.request(request, ['orderID', 'phone', 'distance']) time_ = current_time() order = OrderProxy(int(data['orderID'])) if order.accepted: raise OrderHasAccepted order = order.update(bar_phone=data['phone'], time_=time_, accepted=True).get_dict() barber = BarberProxy(data['phone']) order['distance'], order['shop'], order['address'] = data['distance'], barber.shop, barber.address notify_cus_order_accepted(order) except JianyueError as e: result = e.info finally: result['data'] = re_data return HttpResponse(encode(result))
def quick_appt(request): result = {'code': 100, 'log': 'Order has been sent to the barber end.'} re_data = None try: #result = {'code': 100, 'log': 'Order has been sent to the barber end.'} data = Checker.request(request, ['phone', 'name', 'longitude', 'latitude', 'sex']) try: _ = CustomerProxy(data['phone']) except CustomerDoesNotExistError: CustomersManager.add_customer(phone=data['phone'], name=data['name'], sex=data['sex']) order = OrdersManager.add_order(cus_phone=data['phone']) barbers, dis = BarbersManager.get_near_barber(longitude=float(data['longitude']), latitude=float(data['latitude']), range_=1500) push_order_to_barber_test(order=order, barbers=barbers, dis_list=dis) except JianyueError as e: result = e.info finally: result['data'] = re_data return HttpResponse(encode(result))
def normal_appt(request): result = {'code': 100, 'log': 'Barber list has been returned.'} re_data = None try: data = Checker.request(request, ['longitude', 'latitude', 'date']) barbers, dis_list = BarbersManager.get_near_barber(longitude=float(data['longitude']), latitude=float(data['latitude']), range_=1500) barbers = process_time(barbers=barbers, date=data['date']) l = len(barbers) for i in range(0, l): barbers[i]['distance'] = dis_list[i] barbers.sort(key=lambda d: d['distance']) if not barbers: raise NoBarberHasRegister re_data = barbers except JianyueError as e: result = e.info finally: result['data'] = re_data return HttpResponse(encode(result))
def comment(request): result = {'code': 100, 'log': 'Comment submit successfully'} re_data = None #从request中取出customer信息 #获取评论内容 #获取评级 #获取当前时间 #添加信息到数据库 try: data = Checker.request(request, ['cus_phone', 'bar_phone', 'content', 'rank']) CommentManager.add_comment(content=data['content'], cus_phone=data['cus_phone'], bar_phone=data['bar_phone'], rank=data['rank'], time=current_time()) except JianyueError as e: result = e.info finally: result['data'] = re_data; return HttpResponse(encode(result))
def deal_bug(request): data = Checker.request(request, ['id']) bug = Bug.objects.get(id=data['id']) bug.checked = True bug.dealt = True return HttpResponse(encode({"code": 100, "log": "Normal", "data": None}))