示例#1
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()
示例#2
0
def get_profile(cursor, params):
    status = Object()
    obj = Object()
    status.status = Status.Error.value

    id_profile = params.get(Profile.ID.value, None)

    if id_profile is None:
        cursor.execute(
            "select id_profile from Token_Table where token='{}'".format(
                params[User.Token.value]))
        row = cursor.fetchone()
        if row is None:
            return status.toJSON()
        else:
            id_profile = row[0]

    cursor.execute(
        "select a.id, a.name, a.about, b.photo from Profile as a left \
          join Photo as b on a.id_photo = b.id where a.id={}".format(
            id_profile))
    row = cursor.fetchone()

    if row is not None:
        status.status = Status.Ok.value
        obj.id = row[0]
        obj.name = row[1]
        obj.about = row[2]
        obj.photo = row[3]

        cursor.execute("select id from Witcher where id_profile={}".format(
            obj.id))
        row = cursor.fetchone()

        if row is not None:
            obj.type = Profile.Witcher.value
            cursor.execute(
                "select c.id, c.id_witcher, c.id_client, c.header, c.status, c.last_update,  \
                            c.last_update_status from Profile as a inner join Witcher as b on a.id=b.id_profile \
                            inner join Contract as c on c.id_witcher=b.id where b.id={}"
                .format(row[0]))
            row = cursor.fetchall()
            obj.history = Object()
            obj.history.count = len(row)
            obj.history.contract = {}
            for line in row:
                hist = Object()
                hist.id_contract = line[0]
                hist.id_witcher = line[1]
                hist.id_client = line[2]
                hist.header = line[3]
                hist.status = line[4]
                hist.last_update = line[5]
                hist.last_update_status = line[6]

                obj.history.contract[len(obj.history.contract)] = hist

        else:
            obj.type = Profile.Client.value
            cursor.execute("select id from Client where id_profile={}".format(
                obj.id))
            row = cursor.fetchone()

            cursor.execute(
                "select c.id, c.id_witcher, c.id_client, c.header, c.status, c.last_update, c.last_update_status \
                from Profile as a inner join Client as b on a.id=b.id_profile \
                inner join Contract as c on c.id_witcher=b.id where b.id={}".
                format(row[0]))
            row = cursor.fetchall()
            obj.history = Object()
            obj.history.count = len(row)
            obj.history.contract = {}
            for line in row:
                hist = Object()
                hist.id_contract = line[0]
                hist.id_witcher = line[1]
                hist.id_client = line[2]
                hist.header = line[3]
                hist.status = line[4]
                hist.last_update = line[5]
                hist.last_update_status = line[6]

                obj.history.contract[len(obj.history.contract)] = hist

    status.object = obj
    return status.toJSON()