Ejemplo n.º 1
0
def _po_prev_next(cid, zsite_id, zsite_tag_id, po_id):
    t = ZsiteTagPo.get(zsite_id=zsite_id, po_id=po_id, zsite_tag_id=zsite_tag_id)
    if not t:
        result = (0, 0)
    else:
        id = t.id
        result = [
            _po_goto(
                'select po_id from zsite_tag_po where cid=%s and zsite_id=%s and zsite_tag_id=%s and id>%s order by id limit 1',
                cid,
                zsite_id,
                zsite_tag_id,
                id,
            ) or 0
            ,
            _po_goto(
                'select po_id from zsite_tag_po where cid=%s and zsite_id=%s and zsite_tag_id=%s and id<%s order by id desc limit 1',
                cid,
                zsite_id,
                zsite_tag_id,
                id,
            ) or 0
        ]

    if result[0] != result[1]:
        if not result[0]:
            c = ZsiteTagPo.raw_sql(
                'select po_id from zsite_tag_po where cid=%s and zsite_id=%s and zsite_tag_id=%s order by id limit 1',
                cid,
                zsite_id,
                zsite_tag_id,
            )
            result[0] = c.fetchone()[0]
        elif not result[1]:
            c = ZsiteTagPo.raw_sql(
                'select po_id from zsite_tag_po where cid=%s and zsite_id=%s and zsite_tag_id=%s order by id desc limit 1',
                cid,
                zsite_id,
                zsite_tag_id,
            )
            result[1] = c.fetchone()[0]

    return result
Ejemplo n.º 2
0
def _po_goto(
    sql,
    cid,
    zsite_id,
    tag_id,
    id,
):
    c = ZsiteTagPo.raw_sql(
        sql,
        cid,
        zsite_id,
        tag_id,
        id,
    )
    r = c.fetchone()
    if r:
        r = r[0]
    return r