Exemple #1
0
 def put(self, request, pk, format=None):
     registration = self.get_object(pk)
     serializer = RegistrationSerializer(registration, data=request.data)
     if serializer.is_valid():
         serializer.save()
         return Response(serializer.data)
     else:
         return Response(serializer.errors,
                         status=status.HTTP_400_BAD_REQUEST)
Exemple #2
0
    def post(self, request, format=None):
        serializer = RegistrationSerializer(data=request.data)
        if serializer.is_valid():
            serializer.save()

            self.generate_verification_email(serializer.data)
            return Response(serializer.data, status=status.HTTP_201_CREATED)
        else:
            return Response(serializer.errors,
                            status=status.HTTP_400_BAD_REQUEST)
Exemple #3
0
 def get_current_registration(self, obj):
     try:
         current_reg = obj.registrations\
             .filter(status=REGISTRATION_STATUS_WAITING).order_by('id').first()
         return RegistrationSerializer(
             current_reg).data if current_reg else None
     except Exception, e:
         logger.error(e)
         return None
Exemple #4
0
def make_expired(request, pk):
    """
    将号码状态改为过号
    """
    try:
        reg = Registration.objects.get(pk=pk)
    except Registration.DoesNotExist:
        return Response('registration not found', status=status.HTTP_404_NOT_FOUND)
    data = {
        'status': REGISTRATION_STATUS_EXPIRED
    }
    serializer = RegistrationSerializer(reg, data=data, partial=True)
    if serializer.is_valid():
        reg = serializer.save()
        reg.end_time = datetime.datetime.now()
        reg.save()

        # 通知后面第n位的顾客就餐
        _notify_ready(reg.table_type)

        return Response(serializer.data, status=status.HTTP_200_OK)
    return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST)
Exemple #5
0
 def get_queue_registrations(self, obj):
     try:
         queue_registrations = obj.registrations\
              .filter(status=REGISTRATION_STATUS_WAITING).order_by('id')
         rt = [
             RegistrationSerializer(reg).data for reg in queue_registrations
         ]
         if len(rt) > 0:
             rt = rt[1:]
         return rt
     except Exception, e:
         logger.error(e)
         return None
Exemple #6
0
def join_queue(request):
    """
    选择餐桌,及确认取号
    ---
    request_serializer: RegistrationSerializer

    parameters:
        - name: phone
          type: string
          paramType: form
          required: true
        - name: table_type_id
          type: string
          paramType: form
          required: true

    responseMessages:
        - code: 400
          message: Field Error
        - code: 400
          message: Parameter Error(can not get member)

    """

    restaurant = request.current_restaurant

    phone = request.DATA.get('phone')
    table_type_id = request.DATA.get('table_type_id')

    member = Member.objects.get_or_create(phone=phone)[0]

    try:
        table_type = TableType.objects.get(pk=table_type_id)
    except TableType.DoesNotExist:
        return Response('table type not found', status=status.HTTP_404_NOT_FOUND)

    data = {
        'restaurant': restaurant.pk,
        'member': member.pk,
        'queue_name': table_type.name,
        'queue_number': table_type.next_queue_number,
        'table_min_seats': table_type.min_seats,
        'table_max_seats': table_type.max_seats,
        'reg_method': REG_METHOD_PHONE,
        'table_type': table_type.pk
    }
    serializer = RegistrationSerializer(data=data)

    if serializer.is_valid():
        obj = serializer.save()
        # 让餐桌的拍号+1
        obj.table_type.next_queue()

        # 给顾客发送短信提醒
        content = render_join(restaurant.name, obj.queue_name, obj.queue_number,\
                (obj.table_type.get_registration_left() - 1))
        send_sms.delay(obj.member.phone, content)
        
        return Response(serializer.data, status.HTTP_200_OK)
    else:
        return Response(serializer.errors, status.HTTP_400_BAD_REQUEST)
Exemple #7
0
 def get(self, request, pk, format=None):
     registration = self.get_object(pk)
     serializer = RegistrationSerializer(registration)
     return Response(serializer.data)
Exemple #8
0
 def get(self, request, format=None):
     registrations = Registration.objects.all()
     serializer = RegistrationSerializer(registrations, many=True)
     return Response(serializer.data)
Exemple #9
0
def confirm_table_type(request):
    """
    选择餐桌,及确认取号
    ---
    request_serializer: RegistrationSerializer

    parameters:
        - name: restaurant_openid
          type: string
          paramType: form
          required: true
        - name: table_type_id
          type: string
          paramType: form
          required: true

    responseMessages:
        - code: 400
          message: Field Error
        - code: 400
          message: Parameter Error(can not get member)

    """

    member = request.member
    if not member:
        return Response('Parameter Error(can not get member)',\
                status.HTTP_400_BAD_REQUEST)

    restaurant_openid = request.DATA.get('restaurant_openid')
    table_type_id = request.DATA.get('table_type_id')

    try:
        restaurant = Restaurant.objects.get(openid=restaurant_openid)
    except Restaurant.DoesNotExist:
        return Response('restaurant not found', status=status.HTTP_404_NOT_FOUND)

    try:
        table_type = TableType.objects.get(pk=table_type_id)
    except TableType.DoesNotExist:
        return Response('table type not found', status=status.HTTP_404_NOT_FOUND)

    data = {
        'restaurant': restaurant.pk,
        'member': member.pk,
        'queue_name': table_type.name,
        'queue_number': table_type.next_queue_number,
        'table_min_seats': table_type.min_seats,
        'table_max_seats': table_type.max_seats,
        'reg_method': REG_METHOD_WECHAT,
        'table_type': table_type.pk
    }
    serializer = RegistrationSerializer(data=data)

    if serializer.is_valid():
        obj = serializer.save()
        # 让餐桌的拍号+1
        obj.table_type.next_queue()

        # 加入计时队列
        try:
            pass
        except Exception, e:
            logger.error(e)

        # 给顾客发送短信提醒
        try:
            content = render_join(
                    restaurant.name,
                    obj.queue_name,
                    obj.queue_number,
                    (obj.table_type.get_registration_left() - 1)
                    )
            url = 'http://www.diankuai.cn'
            send_article_message(obj.member.wp_openid, [
                {
                    'title': content,
                    'description': content,
                    'url': url,
                },
            ])
        except Exception, e:
            logger.error(e)
Exemple #10
0
def confirm_table_type(request):
    """
    选择餐桌,及确认取号
    ---
    request_serializer: RegistrationSerializer

    parameters:
        - name: restaurant_openid
          type: string
          paramType: form
          required: true
        - name: table_type_id
          type: string
          paramType: form
          required: true

    responseMessages:
        - code: 400
          message: Field Error
        - code: 400
          message: Parameter Error(can not get member)

    """

    member = request.member
    if not member:
        return Response('Parameter Error(can not get member)',\
                status.HTTP_400_BAD_REQUEST)

    restaurant_openid = request.DATA.get('restaurant_openid')
    table_type_id = request.DATA.get('table_type_id')

    try:
        restaurant = Restaurant.objects.get(openid=restaurant_openid)
    except Restaurant.DoesNotExist:
        return Response('restaurant not found',
                        status=status.HTTP_404_NOT_FOUND)

    try:
        table_type = TableType.objects.get(pk=table_type_id)
    except TableType.DoesNotExist:
        return Response('table type not found',
                        status=status.HTTP_404_NOT_FOUND)

    data = {
        'restaurant': restaurant.pk,
        'member': member.pk,
        'queue_name': table_type.name,
        'queue_number': table_type.next_queue_number,
        'table_min_seats': table_type.min_seats,
        'table_max_seats': table_type.max_seats,
        'reg_method': REG_METHOD_WECHAT,
        'table_type': table_type.pk
    }
    serializer = RegistrationSerializer(data=data)

    if serializer.is_valid():
        obj = serializer.save()
        # 让餐桌的拍号+1
        obj.table_type.next_queue()

        # 加入计时队列
        try:
            pass
        except Exception, e:
            logger.error(e)

        # 给顾客发送短信提醒
        try:
            content = render_join(restaurant.name, obj.queue_name,
                                  obj.queue_number,
                                  (obj.table_type.get_registration_left() - 1))
            url = 'http://www.diankuai.cn'
            send_article_message(obj.member.wp_openid, [
                {
                    'title': content,
                    'description': content,
                    'url': url,
                },
            ])
        except Exception, e:
            logger.error(e)