Exemple #1
0
def get_list_comment(cursor, params):
    sel = "Contract"
    if params.get(Comments.Type.value, None) == Comments.Profile.value:
        sel = "Profile"
    cursor.execute("select text, create_date from Comment where \
                    id_list_comment=(select id_list_comments from {} where id={})"
                   .format(sel, params[Profile.ID.value]))
    row = cursor.fetchall()

    status, obj = Object(), Object()
    status.status = Status.Ok.value
    status.message = EventComments.Success.value
    obj.id_comments = {}
    for i in row:
        comm = Object()
        comm.text = i[0]
        comm.date = i[1]

        #cursor.execute("select a.id, a.name, b.photo from Profile as a left join Photo as b on a.id_photo = b.id \
        #                where a.id_list_comments=(select id_list_comment from Comment where id={})".format(i[2]))
        #prof = cursor.fetchone()
        #comm.id_prof = prof[0]
        #comm.name = prof[1]
        #comm.photo = prof[2]
        obj.id_comments[len(obj.id_comments)] = comm

    status.object = obj
    return status.toJSON()
Exemple #2
0
def get_advert(cursor, params):
    cursor.execute("select * from Contract where id={}".format(
        params[Advert.ID.value]))
    status = Object()
    obj = Object()

    row = cursor.fetchone()
    obj.id = row[0]
    obj.text = row[6]
    obj.bounty = row[7]
    obj.status = row[8]
    obj.last_update_status = row[9]
    obj.last_update = row[10]
    obj.header = row[11]
    id_witcher = row[1]
    id_client = row[2]
    id_list_comments = row[3]
    id_task_located = row[4]
    id_list_photos = row[5]

    if id_witcher is not None:
        cursor.execute(
            "select id, name from Profile where id=(select id_profile from Witcher where id={})"
            .format(id_witcher))
        row = cursor.fetchone()
        witcher = Object()
        witcher.id = row[0]
        witcher.name = row[1]
        status.witcher = witcher

    cursor.execute(
        "select id, name, id_photo from Profile where id=(select id_profile from Client where id={})"
        .format(id_client))
    row = cursor.fetchone()
    client = Object()
    client.id = row[0]
    client.name = row[1]
    if row[2] is not None:
        cursor.execute("select photo from Photo where id={}".format(row[2]))
        client.photo = cursor.fetchone()[0]
    status.client = client

    cursor.execute(
        "select a.name, b.name from Town as a inner join Kingdom as b on a.id_kingdom=b.id where a.id={}"
        .format(id_task_located))
    row = cursor.fetchone()
    obj.town = row[0]
    obj.kingdom = row[1]

    cursor.execute(
        "select b.photo from Contract as a inner join Photo as b on a.id_list_photos = b.id_list_photos where \
        a.id_list_photos={}".format(id_list_photos))
    row = cursor.fetchall()
    obj.photoContract = Object()
    obj.photoContract.photo = {}
    obj.photoContract.count = len(row)
    for i in range(len(row)):
        ph = Object()
        ph.photo = row[i][0]
        obj.photoContract.photo[len(obj.photoContract.photo)] = ph

    status.object = obj
    status.status = Status.Ok.value
    status.message = EventAdvert.Success.value
    return status.toJSON()