Example #1
0
def _reply_list_dump(reply_list, can_admin, current_user_id):
    result = []
    career_bind(reply_list, "user_id")
    ico_url_bind_with_default(tuple(i.user for i in reply_list))
    pre_user_id = None

    for reply in reply_list:
        user = reply.user
        career = reply.career
        career = " , ".join(filter(bool,career))
        if not career:
            career = 0

        user_id = user.id


        reply_tuple = (
            reply.htm, 
            reply.id, 
            can_admin or reply.can_admin(current_user_id)
        )

        if user_id == pre_user_id:
            result[-1][-1].append(reply_tuple)
        else:
            result.append(
                (url_or_id(user_id), user.name , career, user.ico, [reply_tuple])
            )

        pre_user_id = user_id
    
    return result
Example #2
0
def _reply_list_dump(reply_list, can_admin, current_user_id):
    result = []
    career_bind(reply_list, "user_id")
    ico_url_bind_with_default(tuple(i.user for i in reply_list))
    pre_user_id = None

    for reply in reply_list:
        user = reply.user
        career = reply.career
        career = " , ".join(filter(bool, career))
        if not career:
            career = 0

        user_id = user.id

        reply_tuple = (reply.htm, reply.id, can_admin
                       or reply.can_admin(current_user_id))

        if user_id == pre_user_id:
            result[-1][-1].append(reply_tuple)
        else:
            result.append((url_or_id(user_id), user.name, career, user.ico,
                           [reply_tuple]))

        pre_user_id = user_id

    return result
Example #3
0
def site_po_iter(id_list, limit=MAXINT, begin_id=MAXINT):
    id_list = list(merge_iter(id_list, limit, begin_id))
    po_list = Po.mc_get_list(id_list)

    zsite_set = set()

    for i in po_list:
        zsite_set.add(i.zsite_id)
        zsite_set.add(i.user_id)

    zsite_dict = Zsite.mc_get_dict(zsite_set)

    result = []
    pre_zsite_id = None
    m = []

    zsite_set = set()

    if po_list:
        last_id = po_list[-1].id
        for i in po_list:
            if pre_zsite_id != i.zsite_id:
                if pre_zsite_id:
                    result.append([pre_zsite_id, m])
                    zsite_set.add(zsite_dict[pre_zsite_id])
                    m = []
                pre_zsite_id = i.zsite_id

            cid = i.cid
            t = []
            t.append(i.id)
            t.append(cid)

            if cid == CID_WORD:
                t.append(i.htm)
            else:
                t.append(i.name)

            if i.zsite_id != i.user_id:
                user = zsite_dict[i.user_id]
                t.append(user.link)
                t.append(user.name)
            m.append(t)

        result.append([i.zsite_id, m])
        zsite_set.add(zsite_dict[i.zsite_id])
    else:
        last_id = 0

    ico_url_bind_with_default(zsite_set)

    for i in result:
        id = i[0]
        zsite = zsite_dict[id]
        i[0] = [id, zsite.name, zsite.link, zsite.ico]

    return result, last_id
Example #4
0
def _get(self, func):
    key = self.get_argument('q', None)
    user_id = self.current_user_id
    result = []
    if user_id:
        name_dict, url_dict = func(user_id)
        id_list = zsite_by_key(key, name_dict, url_dict, 7)
        zsite_list = Zsite.mc_get_list(id_list)
        ico_url_bind_with_default(zsite_list)
        career_bind(zsite_list)

        for i in zsite_list:
            li = (i.name, ','.join(i.career), url_or_id(i.id), i.ico)
            result.append(li)
    #print result
    self.finish(jsonp(self, dumps(result)))