Exemple #1
0
def oauth_client_new(user_id, name, txt, site, cid=0):
    secret = uuid4().bytes
    id = gid()
    o = OauthClient(id=id, user_id=user_id, secret=secret, name=name, site=site, cid=cid)
    o.save()
    txt_new(id, txt)
    mc_oauth_client_id_by_user_id.delete(user_id)
    return o
Exemple #2
0
def oauth_client_edit(oauth_client_id, name, txt, site):
    o = OauthClient.mc_get(oauth_client_id)
    if name:
        o.name = name
    o.site = site
    o.save()
    txt_new(oauth_client_id, txt)
    mc_oauth_client_id_by_user_id.delete(o.user_id)
    return o
Exemple #3
0
def oauth_client_edit(oauth_client_id, name, txt, site):
    o = OauthClient.mc_get(oauth_client_id)
    if name:
        o.name = name
    o.site = site
    o.save()
    txt_new(oauth_client_id, txt)
    mc_oauth_client_id_by_user_id.delete(o.user_id)
    return o
Exemple #4
0
def _po_answer_new(user_id, name, txt, state, rid):
    if not name and not txt:
        return
    if not is_same_post(user_id, name, txt):
        m = po_new(CID_ANSWER, user_id, name, state, rid)
        if m:
            txt_new(m.id, txt)
            if state > STATE_SECRET:
                m.feed_new()
            return m
Exemple #5
0
def po_product_new(user_id, name, _info_json, zsite_id=0, state=STATE_ACTIVE):
    if not name and not _info_json:
        return
    info_json = json.dumps(dict(iter(_info_json)))
    if not is_same_post(user_id, name, info_json, zsite_id):
        m = po_new(CID_PRODUCT, user_id, name, state, 0, None, zsite_id)
        if m:
            txt_new(m.id, info_json)
            mc_product_id_list_by_com_id.delete(zsite_id)
            return m
Exemple #6
0
def po_product_new(user_id, name, _info_json, zsite_id=0, state=STATE_ACTIVE):
    if not name and not _info_json :
        return
    info_json = json.dumps(dict(iter(_info_json)))
    if not is_same_post(user_id, name, info_json, zsite_id):
        m = po_new(CID_PRODUCT, user_id, name, state, 0, None, zsite_id)
        if m:
            txt_new(m.id, info_json)
            mc_product_id_list_by_com_id.delete(zsite_id)
            return m
def _po_answer_new(user_id, name, txt, state, rid):
    if not name and not txt:
        return
    if not is_same_post(user_id, name, txt):
        m = po_new(CID_ANSWER, user_id, name, state, rid)
        if m:
            txt_new(m.id, txt)
            if state > STATE_SECRET:
                m.feed_new()
            return m
Exemple #8
0
def po_question_new(user_id, name, txt, state, zsite_id):
    if not name and not txt:
        return
    name = name or time_title()
    if not is_same_post(user_id, name, txt, zsite_id):
        m = po_new(CID_QUESTION, user_id, name, state, zsite_id=zsite_id)
        if m:
            txt_new(m.id, txt)
            if state > STATE_SECRET:
                m.feed_new()
            return m
def po_question_new(user_id, name, txt, state, zsite_id):
    if not name and not txt:
        return
    name = name or time_title()
    if not is_same_post(user_id, name, txt, zsite_id):
        m = po_new(CID_QUESTION, user_id, name, state, zsite_id=zsite_id)
        if m:
            txt_new(m.id, txt)
            if state > STATE_SECRET:
                m.feed_new()
            return m
Exemple #10
0
def oauth_client_new(user_id, name, txt, site, cid=0):
    secret = uuid4().bytes
    id = gid()
    o = OauthClient(id=id,
                    user_id=user_id,
                    secret=secret,
                    name=name,
                    site=site,
                    cid=cid)
    o.save()
    txt_new(id, txt)
    mc_oauth_client_id_by_user_id.delete(user_id)
    return o
Exemple #11
0
def zsite_book_new(
    name,
    douban_id,
    pic_id,
    author,
    translator,
    pages,
    publisher,
    isbn,
    rating,
    rating_num,
    author_intro,
    txt,
):
    if douban_id:
        book = ZsiteBook.get(douban_id=douban_id)
        if book:
            return book.id
    if isbn:
        book_id = zsite_book_id_by_isbn(isbn)
        if book_id:
            return book_id
    zsite = zsite_new(name, CID_BOOK)
    id = zsite.id
    if isbn:
        mc_zsite_book_id_by_isbn.set(isbn, id)

    txt_new(id, txt)
    book = ZsiteBook.get_or_create(id=id)
    book.douban_id = douban_id
    book.douban_pic_id = pic_id
    book.author = author
    book.translator = translator
    book.pages = pages
    book.publisher = publisher
    book.isbn = isbn
    book.rating = rating
    book.rating_num = rating_num
    book.author_intro = author_intro
    #print author_intro,"author_intro"
    book.save()
    return id
Exemple #12
0
    def reply_new(self, user, txt, state=STATE_ACTIVE, create_time=None):
        from zsite import user_can_reply
        user_id = user.id
        cid = self.cid
        if cid not in (CID_SITE, CID_COM):
            if not user_can_reply(user):
                return
        if is_spammer(user_id):
            return

        txt = txt.rstrip()
        rid = self.id


        if not txt or is_same_post(user_id, cid, rid, txt, state):
            return

        id = gid()
        if not create_time:
            create_time = int(time())
        txt_new(id, txt)
        cursor = self.reply_cursor
        cursor.execute(
            'insert into reply (id,cid,create_time,state,rid,user_id) values (%s,%s,%s,%%s,%%s,%%s)' % (
                id,
                cid,
                create_time,
            ),
            (state, rid, user_id)
        )
        cursor.connection.commit()
        mc_flush_reply_id_list(cid, rid)

#            key = '%s_%s' % (rid, user_id)
#            if mc_reply_in_1h.get(key) is None:
#                mq_buzz_po_reply_new(user_id, rid)
#                mc_reply_in_1h.set(key, True, 3600)

        return id
Exemple #13
0
    def reply_new(self, user, txt, state=STATE_ACTIVE, create_time=None):
        from zsite import user_can_reply
        user_id = user.id
        cid = self.cid
        if cid not in (CID_SITE, CID_COM):
            if not user_can_reply(user):
                return
        if is_spammer(user_id):
            return

        txt = txt.rstrip()
        rid = self.id

        if not txt or is_same_post(user_id, cid, rid, txt, state):
            return

        id = gid()
        if not create_time:
            create_time = int(time())
        txt_new(id, txt)
        cursor = self.reply_cursor
        cursor.execute(
            'insert into reply (id,cid,create_time,state,rid,user_id) values (%s,%s,%s,%%s,%%s,%%s)'
            % (
                id,
                cid,
                create_time,
            ), (state, rid, user_id))
        cursor.connection.commit()
        mc_flush_reply_id_list(cid, rid)

        #            key = '%s_%s' % (rid, user_id)
        #            if mc_reply_in_1h.get(key) is None:
        #                mq_buzz_po_reply_new(user_id, rid)
        #                mc_reply_in_1h.set(key, True, 3600)

        return id
Exemple #14
0
def zsite_book_new(
    name,
    douban_id,
    pic_id,
    author, translator, pages,
    publisher, isbn,
    rating, rating_num,
    author_intro, txt,
):
    if douban_id:
        book = ZsiteBook.get(douban_id=douban_id)
        if book:
            return book.id
    if isbn:
        book_id = zsite_book_id_by_isbn(isbn)
        if book_id:
            return book_id
    zsite = zsite_new(name, CID_BOOK)
    id = zsite.id
    if isbn:
        mc_zsite_book_id_by_isbn.set(isbn, id)

    txt_new(id, txt)
    book = ZsiteBook.get_or_create(id=id)
    book.douban_id = douban_id
    book.douban_pic_id = pic_id
    book.author = author
    book.translator = translator
    book.pages = pages
    book.publisher = publisher
    book.isbn = isbn
    book.rating = rating
    book.rating_num = rating_num
    book.author_intro = author_intro
    #print author_intro,"author_intro"
    book.save()
    return id
Exemple #15
0
 def txt_set(self, txt):
     id = self.id
     txt = url_short_txt(txt, self.user_id)
     txt_new(id, txt or '')
     self.mc_flush()
Exemple #16
0
 def txt_set(self, txt):
     return txt_new(self.id, txt)
Exemple #17
0
 def txt_set(self, txt):
     return txt_new(self.id, txt)