Esempio n. 1
0
def cl_event_type_rel_add(request):

    record = get_record(request, _MODEL)
    rel_name, rid = request.matchdict.get('rel'), request.matchdict.get('rid')
    rel = record.__mapper__.get_property(rel_name)
    rel_list = getattr(record, rel_name, None)
    if rel is None or rel_list is None or not hasattr(rel_list, 'append'):
        raise HTTPBadRequest(
            json_body={
                "error": "Relationship {} does not exist".format(rel_name)
            },
        )

    query = get_session(request).query(rel.mapper)
    added_record = query.get(rid)
    if added_record is None:
        raise HTTPNotFound(
            json_body={"error": "Event type ID {id} not found".format(id=rid)},
        )
    if added_record not in rel_list:
        rel_list.append(added_record)
    else:
        raise HTTPBadRequest(
            json_body={"error": "Object is already in the relationship"},
        )
    return added_record.as_dict()
Esempio n. 2
0
def cl_event_type_rel_delete(request):

    record = get_record(request, _MODEL)
    rel_name, rid = request.matchdict.get('rel'), request.matchdict.get('rid')
    rel = record.__mapper__.get_property(rel_name)
    rel_list = getattr(record, rel_name, None)
    if rel is None or rel_list is None or not hasattr(rel_list, 'append'):
        raise HTTPBadRequest(
            json_body={
                "error": "Relationship {} does not exist".format(rel_name)
            },
        )

    query = get_session(request).query(rel.mapper)
    removed_record = query.get(rid)
    if removed_record is None:
        raise HTTPNotFound(
            json_body={"error": "Event type ID {id} not found".format(id=rid)},
        )
    if removed_record in rel_list:
        rel_list.remove(removed_record)
    else:
        raise HTTPBadRequest(
            json_body={"error": "Object is not in the relationship"},
        )
    return Response(status_int=204, json_body={})
Esempio n. 3
0
def cl_item_type_rel_add(request):

    record = get_record(request, _MODEL)
    rel_name, rid = request.matchdict.get('rel'), request.matchdict.get('rid')
    rel = record.__mapper__.get_property(rel_name)
    rel_list = getattr(record, rel_name, None)
    if rel is None or rel_list is None or not hasattr(rel_list, 'append'):
        raise HTTPBadRequest(
            json_body={
                "error": "Relationship {} does not exist".format(rel_name)
            },
        )

    query = get_session(request).query(rel.mapper)
    added_record = query.get(rid)
    if added_record is None:
        raise HTTPNotFound(
            json_body={"error": "Item type ID {id} not found".format(id=rid)},
        )
    if added_record not in rel_list:
        rel_list.append(added_record)
    else:
        raise HTTPBadRequest(
            json_body={"error": "Object is already in the relationship"},
        )
    return added_record.as_dict()
Esempio n. 4
0
def cl_item_column_create(request):

    record = ItemColumn()

    _update_record(request, record)

    session = get_session(request)

    session.add(record)
    session.flush()
    session.refresh(record)

    return record.as_dict()
Esempio n. 5
0
def cl_item_type_create(request):

    record = ItemType()

    _update_record(request, record)

    session = get_session(request)

    session.add(record)
    session.flush()
    session.refresh(record)

    return record.as_dict()
Esempio n. 6
0
def cl_event_type_create(request):

    record = EventType()

    _update_record(request, record)

    session = get_session(request)

    session.add(record)
    session.flush()
    session.refresh(record)

    return record.as_dict()
Esempio n. 7
0
def cl_event_type_rel_list(request):

    record = get_record(request, _MODEL)
    rel_name = request.matchdict.get('rel')
    rel = record.__mapper__.get_property(rel_name)
    rel_list = getattr(record, rel_name, None)
    if rel is None or rel_list is None or not hasattr(rel_list, 'filter'):
        raise HTTPBadRequest(
            json_body={
                "error": "Relationship {} does not exist".format(rel_name)
            },
        )

    return get_list(
        rel.mapper, request.GET, rel_list, sqla_session=get_session(request)
    )
Esempio n. 8
0
def cl_item_list(request):

    # TODO Remove the custom record wrapper when clients represent
    # relationships better (for now, we just include the data they are going
    # to need in the result list).

    def record_wrapper(record):
        """Include type names."""
        ret = record.as_dict()
        ret['type_name'] = record.type.display_name
        return ret

    return get_list(
        Item, request.GET, sqla_session=get_session(request),
        record_wrapper=record_wrapper,
    )
Esempio n. 9
0
def cl_item_join_list(request):

    # TODO Remove the custom record wrapper when clients represent
    # relationships better (for now, we just include the data they are going
    # to need in the result list).

    def record_wrapper(record):
        """Include type names."""
        ret = record.as_dict()
        ret['type_name'] = record.type.display_name
        return ret

    return get_list(
        ItemJoin, request.GET, sqla_session=get_session(request),
        record_wrapper=record_wrapper,
    )
Esempio n. 10
0
def cl_item_type_rel_list(request):

    record = get_record(request, _MODEL)
    rel_name = request.matchdict.get('rel')
    rel = record.__mapper__.get_property(rel_name)
    rel_list = getattr(record, rel_name, None)
    if rel is None or rel_list is None or not hasattr(rel_list, 'filter'):
        raise HTTPBadRequest(
            json_body={
                "error": "Relationship {} does not exist".format(rel_name)
            },
        )

    return get_list(
        rel.mapper, request.GET, rel_list, sqla_session=get_session(request)
    )
Esempio n. 11
0
def cl_item_type_rel_delete(request):

    record = get_record(request, _MODEL)
    rel_name, rid = request.matchdict.get('rel'), request.matchdict.get('rid')
    rel = record.__mapper__.get_property(rel_name)
    rel_list = getattr(record, rel_name, None)
    if rel is None or rel_list is None or not hasattr(rel_list, 'append'):
        raise HTTPBadRequest(json_body={
            "error":
            "Relationship {} does not exist".format(rel_name)
        }, )

    query = get_session(request).query(rel.mapper)
    removed_record = query.get(rid)
    if removed_record is None:
        raise HTTPNotFound(
            json_body={"error":
                       "Item type ID {id} not found".format(id=rid)}, )
    if removed_record in rel_list:
        rel_list.remove(removed_record)
    else:
        raise HTTPBadRequest(
            json_body={"error": "Object is not in the relationship"}, )
    return Response(status_int=204, json_body={})
Esempio n. 12
0
def cl_event_type_delete(request):
    record = get_record(request, _MODEL)
    get_session(request).delete(record)

    return Response(status_int=204, json_body={})
Esempio n. 13
0
def cl_item_type_delete(request):
    record = get_record(request, _MODEL)
    get_session(request).delete(record)

    return Response(status_int=204, json_body={})
Esempio n. 14
0
def cl_item_type_list(request):
    return get_list(ItemType, request.GET, sqla_session=get_session(request))
Esempio n. 15
0
def cl_item_type_list(request):
    return get_list(ItemType, request.GET, sqla_session=get_session(request))
Esempio n. 16
0
 def sqla_session(self, request):
     return get_session(request)
Esempio n. 17
0
 def sqla_session(self, request):
     return get_session(request)
Esempio n. 18
0
def cl_event_type_list(request):
    return get_list(EventType, request.GET, sqla_session=get_session(request))