Ejemplo n.º 1
0
def recover_devices_recycles(ids):
    devices = Device.objects(Q(id__in=ids) & Q(is_template=False))
    devices.update(is_deleted=False)

    equipments = [equipment.id for equipment in devices.values_list('_parent_equipment')]
    Equipment.objects(id__in=equipments).update(is_deleted=False)

    return jsonify(ok=True, msg='success')
Ejemplo n.º 2
0
def delete_all():
    Sample.objects.all().delete()
    Collect.objects().all().delete()
    LoanHistory.objects().all().delete()
    Equipment.objects().all().delete()
    Sensor.objects().all().delete()
    Patient.objects().all().delete()
    return jsonify({'message': 'deleted with success.'})
Ejemplo n.º 3
0
def recover_interfaces_recycles(ids):
    interfaces = Interface.objects(Q(id__in=ids) & Q(is_template=False))
    interfaces.update(is_deleted=False)  # 恢复接口自身

    devices = [
        device.id for device in interfaces.values_list('_parent_device')
    ]
    equipments = [
        equipment.id
        for equipment in interfaces.values_list('_parent_equipment')
    ]

    Device.objects(id__in=devices).update(is_deleted=False)
    Equipment.objects(id__in=equipments).update(is_deleted=False)
    return jsonify(ok=True, msg='success')
Ejemplo n.º 4
0
def get_equipments():
    form = SearchForm(request.args)
    query = Equipment.objects(is_deleted=False, is_template=False)

    # 简单搜索
    if form.searchKey.data:
        search_key = form.searchKey.data
        query = query.filter(Q(name__contains=search_key) | Q(note__contains=search_key))
        return build_order_by(query, form.orderBy.data), 200

    # 高级搜索
    if form.name.data:
        query = query.filter(name__contains=form.name.data)
    if form.type.data:
        query = query.filter(type=form.type.data)
    if form.location.data:
        query = query.filter(location=form.location.data)
    if form.sn.data:
        query = query.filter(sn=form.sn.data)
    if form.manufacturer.data:
        query = query.filter(manufacturer=form.manufacturer.data)
    if form.note.data:
        query = query.filter(note__contains=form.note.data)
    if form.createUserId.data:
        query = query.filter(_create_user=form.createUserId.data)
    if form.createdAtStart.data:
        query = query.filter(created_at__gte=form.createdAtStart.data)
    if form.createdAtEnd.data:
        query = query.filter(created_at__lte=form.createdAtEnd.data)

    current_user.update(inc__search_num=1)
    return build_order_by(query, form.orderBy.data)
Ejemplo n.º 5
0
def get_users_meta():
    data = Equipment.objects(is_deleted=False, is_template=False).fields(id=1, name=1).all()
    meta = [{
        'id': str(item.id),
        'name': item.name,
    } for item in data]
    return jsonify(ok=True, data=meta)
Ejemplo n.º 6
0
def get_child(oid):
    equipment = Equipment.objects(id=oid).count()
    if not equipment:
        return jsonify(ok=True, msg='not found'), 404
    child_device = Device.objects(_parent_equipment=oid).count()
    child_interface = Interface.objects(_parent_equipment=oid).count()
    child_cable = Cable.objects(Q(_start_equipment=oid) | Q(_end_equipment=oid)).count()
    return jsonify(ok=True, msg={'device': child_device, 'interface': child_interface,
                                 'cable': child_cable})
Ejemplo n.º 7
0
def index(vessel):
    equipments = Equipment.objects(vessel=vessel)
    print(equipments)
    response = []
    for equipment in equipments:
        response.append(equipment.to_json())
    if not equipments:
        return jsonify({'error': 'data not found'})
    else:
        return jsonify(response)
Ejemplo n.º 8
0
def deleteVessel(code):
    equipment = Equipment.objects(code=code).first()
    if not equipment:
        return jsonify({'error': 'data not found'}), 404
    else:
        try:
            equipment.delete()
            return jsonify(), 204
        except Exception as e:
            print(e)
    return jsonify(), 204
Ejemplo n.º 9
0
def get_equipments_child():
    form = ObjectIdListForm(request.args)
    ids = form.ids.data
    equipment = Equipment.objects(id__in=ids).count()
    if not equipment:
        return jsonify(ok=True, msg='not found'), 404
    child_device = Device.objects(_parent_equipment__in=ids).count()
    child_interface = Interface.objects(_parent_equipment__in=ids).count()
    child_cable = Cable.objects(Q(_start_equipment__in=ids) | Q(_end_equipment__in=ids)).count()
    return jsonify(ok=True, msg={'device': child_device, 'interface': child_interface,
                                 'cable': child_cable})
Ejemplo n.º 10
0
def deactivateEquipment():
    listOfEquipments = json.loads(request.data)

    if not listOfEquipments: return jsonify({'error': 'data not found'}), 404

    for equipment in listOfEquipments:
        equipments_doc = Equipment.objects(code=equipment).first()
        if not equipments_doc:
            return jsonify({'error': 'data not found'}), 404
        else:
            equipments_doc.update(status=False)
        return jsonify(equipments_doc.to_json())
Ejemplo n.º 11
0
def recover_cables_recycles(ids):
    cables = Cable.objects(Q(id__in=ids) & Q(is_template=False))
    cables.update(is_deleted=False)  # 恢复线缆自身

    interfaces = [
        interface.id for interface in cables.values_list(
            '_start_interface', '_end_interface')[0]
    ]
    devices = [
        device.id
        for device in cables.values_list('_start_device', '_end_interface')[0]
    ]
    equipments = [
        equipment.id for equipment in cables.values_list(
            '_start_equipment', '_end_interface')[0]
    ]

    Interface.objects(id__in=interfaces).update(is_deleted=False)
    Device.objects(id__in=devices).update(is_deleted=False)
    Equipment.objects(id__in=equipments).update(is_deleted=False)

    return jsonify(ok=True, msg='success')
Ejemplo n.º 12
0
 def load(self, device):
     device.name = self.name.data
     device.type = self.type.data
     device.location = self.location.data
     device.system = self.system.data
     device.sn = self.sn.data
     device.manufacturer = self.manufacturer.data
     device.note = self.note.data
     try:
         parent_equipment = Equipment.objects().get(id=self.parentEquipmentId.data)
     except Equipment.DoesNotExist:
         raise FormLoadException('装置不存在,id: ' + str(self.parentEquipmentId.data))
     else:
         device.parent_equipment = parent_equipment.id
Ejemplo n.º 13
0
def recover_equipments_recycles(ids):
    Equipment.objects(id__in=ids).update(is_deleted=False)
    return jsonify(ok=True, msg='success')