예제 #1
0
    def po_save(self, user_id, name, txt, state, zsite_id):
        po = self.po
        if po is None:
            return

        cid = po.cid
        rid = po.rid
        po.zsite_id = zsite_id

        if cid == CID_WORD:
            if cnenlen(txt) > 140:
                answer_word2note(po)
                po.txt_set(txt)
            else:
                po.name_ = txt
        elif cid == CID_EVENT_FEEDBACK:
            event_joiner_state_set_by_good(user_id, rid, state)
            if txt:
                po.txt_set(txt)
        else:
            if not po.rid and name:
                po.name_ = name
            if txt:
                po.txt_set(txt)

        if cid in (CID_NOTE, CID_QUESTION, CID_ANSWER):
            if not (cid == CID_QUESTION and po.state == STATE_ACTIVE):
                po_state_set(po, state)

        po.save()
        return po
예제 #2
0
    def post(self, id):
        user_id = self.current_user_id
        if not user_id:
            return request.redirect('/auth/login')

        question = self.po(id)
        if question is None:
            return

        txt = self.get_argument('txt', '')
        if not question.can_view(user_id) or not txt:
            return self.get(id)

        secret = self.get_argument('secret', None)
        arguments = self.request.arguments
        if secret:
            state = STATE_SECRET
        else:
            state = STATE_ACTIVE

        if cnenlen(txt) > 140:
            name = ''
        else:
            name, txt = txt, ''
        po = po_answer_new(user_id, id, name, txt, state)

        if po:
            if po.cid == CID_ANSWER and po.state == STATE_ACTIVE:
                answer_id = po.id
                link = '/po/tag/%s' % answer_id
            else:
                link = '%s#reply%s' % (question.link, po.id)
        else:
            link = '%s#reply_txt' % question.link
        self.redirect(link)
예제 #3
0
    def po_save(self, user_id, name, txt, state, zsite_id):
        po = self.po
        if po is None:
            return

        cid = po.cid
        rid = po.rid
        po.zsite_id = zsite_id

        if cid == CID_WORD:
            if cnenlen(txt) > 140:
                answer_word2note(po)
                po.txt_set(txt)
            else:
                po.name_ = txt
        elif cid == CID_EVENT_FEEDBACK:
            event_joiner_state_set_by_good(user_id, rid, state)
            if txt:
                po.txt_set(txt)
        else:
            if not po.rid and name:
                po.name_ = name
            if txt:
                po.txt_set(txt)



        if cid in (CID_NOTE, CID_QUESTION, CID_ANSWER):
            if not (cid == CID_QUESTION and po.state == STATE_ACTIVE):
                po_state_set(po, state)


        po.save()
        return po
예제 #4
0
def po_json(user_id, po_id_list, line_width):

    po_id_list = map(int,po_id_list)

    po_list = Po.mc_get_list(po_id_list)

    txt_bind(po_list)

    Zsite.mc_bind(po_list, 'user', 'user_id')
    result = []


    fav_dict = fav_cid_dict(
        user_id,
        po_id_list
    )

    for po in po_list:

        name = po.name
        user = po.user


        name_len = cnenlen(name)
        txt = po.txt

        if txt and name_len < line_width:
            tip = cnenoverflow(txt, line_width-name_len)[0]
        else:
            tip = ''

        id = po.id
        if not user:
            user_id = 0
            user_name = None
        else:
            user_id = user.id
            user_name = None
        result.append((
            id,
            name,
            tip,
#            user_id,
#            user_name,
            fav_dict[id]
        ))
# 0   1       2     3           4               5
# id , name, tip,  author_id , author_name , is_star 
    return result
예제 #5
0
def po_json(user_id, po_id_list, line_width):

    po_id_list = map(int, po_id_list)

    po_list = Po.mc_get_list(po_id_list)

    txt_bind(po_list)

    Zsite.mc_bind(po_list, 'user', 'user_id')
    result = []

    fav_dict = fav_cid_dict(user_id, po_id_list)

    for po in po_list:

        name = po.name
        user = po.user

        name_len = cnenlen(name)
        txt = po.txt

        if txt and name_len < line_width:
            tip = cnenoverflow(txt, line_width - name_len)[0]
        else:
            tip = ''

        id = po.id
        if not user:
            user_id = 0
            user_name = None
        else:
            user_id = user.id
            user_name = None
        result.append((
            id,
            name,
            tip,
            #            user_id,
            #            user_name,
            fav_dict[id]))


# 0   1       2     3           4               5
# id , name, tip,  author_id , author_name , is_star
    return result