示例#1
0
def activate_animal_by_id(request):
    animal_id = request.matchdict['device_id']
    if check_permission('admin', request):
        email = None
    else:
        email = get_user_email(request)

    if animal_id != None:
        animal = Animal().queryObject().filter(Animal.id == animal_id).scalar()
        if (email != None):
            if (animal.user.email != email):
                return
        animal.active = True
        animal.update()

        same_order_devices = animal.order.devices
        all_active = True
        for device in same_order_devices:
            all_active = all_active and device.active
        if all_active:
            active_order_state = Order_state._STATES[len(Order_state._STATES)
                                                     - 2]
            if device.order.states[0].state != active_order_state:
                ondestan.services.order_service.update_order_state(
                                animal.order.id, active_order_state, request)
示例#2
0
def activate_animal_by_id(request):
    animal_id = request.matchdict['device_id']
    if check_permission('admin', request):
        email = None
    else:
        email = get_user_email(request)

    if animal_id != None:
        animal = Animal().queryObject().filter(Animal.id == animal_id).scalar()
        if (email != None):
            if (animal.user.email != email):
                return
        animal.active = True
        animal.update()

        same_order_devices = animal.order.devices
        all_active = True
        for device in same_order_devices:
            all_active = all_active and device.active
        if all_active:
            active_order_state = Order_state._STATES[len(Order_state._STATES) -
                                                     2]
            if device.order.states[0].state != active_order_state:
                ondestan.services.order_service.update_order_state(
                    animal.order.id, active_order_state, request)
示例#3
0
def create_animal(imei, phone, order, name=''):
    animal = Animal()
    animal.active = False
    animal.imei = imei
    animal.phone = phone
    if (name != None and name != ''):
        animal.name = name
    if (order != None and order.user != None):
        animal.order_id = order.id
        animal.user_id = order.user.id
        animal.save()
示例#4
0
def create_animal(imei, phone, order, name=''):
    animal = Animal()
    animal.active = False
    animal.imei = imei
    animal.phone = phone
    if (name != None and name != ''):
        animal.name = name
    if (order != None and order.user != None):
        animal.order_id = order.id
        animal.user_id = order.user.id
        animal.save()
示例#5
0
def deactivate_animal_by_id(request):
    animal_id = request.matchdict['device_id']
    if check_permission('admin', request):
        email = None
    else:
        email = get_user_email(request)

    if animal_id != None:
        animal = Animal().queryObject().filter(Animal.id == animal_id).scalar()
        if (email != None):
            if (animal.user.email != email):
                return
        animal.active = False
        animal.update()
示例#6
0
def deactivate_animal_by_id(request):
    animal_id = request.matchdict['device_id']
    if check_permission('admin', request):
        email = None
    else:
        email = get_user_email(request)

    if animal_id != None:
        animal = Animal().queryObject().filter(Animal.id == animal_id).scalar()
        if (email != None):
            if (animal.user.email != email):
                return
        animal.active = False
        animal.update()